mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
PY3: Don't use importlib.util.module_from_spec in PY3.4
Signed-off-by: Sergey Kizunov <sergey.kizunov@ni.com>
This commit is contained in:
parent
f9965ccfcb
commit
55a18b5106
@ -34,11 +34,13 @@ from salt.utils import is_proxy
|
|||||||
import salt.ext.six as six
|
import salt.ext.six as six
|
||||||
from salt.ext.six.moves import reload_module
|
from salt.ext.six.moves import reload_module
|
||||||
|
|
||||||
if six.PY3:
|
if sys.version_info[:2] >= (3, 5):
|
||||||
import importlib.machinery # pylint: disable=no-name-in-module,import-error
|
import importlib.machinery # pylint: disable=no-name-in-module,import-error
|
||||||
import importlib.util # pylint: disable=no-name-in-module,import-error
|
import importlib.util # pylint: disable=no-name-in-module,import-error
|
||||||
|
USE_IMPORTLIB = True
|
||||||
else:
|
else:
|
||||||
import imp
|
import imp
|
||||||
|
USE_IMPORTLIB = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
@ -51,7 +53,7 @@ log = logging.getLogger(__name__)
|
|||||||
SALT_BASE_PATH = os.path.abspath(salt.syspaths.INSTALL_DIR)
|
SALT_BASE_PATH = os.path.abspath(salt.syspaths.INSTALL_DIR)
|
||||||
LOADED_BASE_NAME = 'salt.loaded'
|
LOADED_BASE_NAME = 'salt.loaded'
|
||||||
|
|
||||||
if six.PY3:
|
if USE_IMPORTLIB:
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
MODULE_KIND_SOURCE = 1
|
MODULE_KIND_SOURCE = 1
|
||||||
MODULE_KIND_COMPILED = 2
|
MODULE_KIND_COMPILED = 2
|
||||||
@ -1187,7 +1189,7 @@ class LazyLoader(salt.utils.lazy.LazyDict):
|
|||||||
if self.opts.get('enable_zip_modules', True) is True:
|
if self.opts.get('enable_zip_modules', True) is True:
|
||||||
self.suffix_map['.zip'] = tuple()
|
self.suffix_map['.zip'] = tuple()
|
||||||
# allow for module dirs
|
# allow for module dirs
|
||||||
if six.PY3:
|
if USE_IMPORTLIB:
|
||||||
self.suffix_map[''] = ('', '', MODULE_KIND_PKG_DIRECTORY)
|
self.suffix_map[''] = ('', '', MODULE_KIND_PKG_DIRECTORY)
|
||||||
else:
|
else:
|
||||||
self.suffix_map[''] = ('', '', imp.PKG_DIRECTORY)
|
self.suffix_map[''] = ('', '', imp.PKG_DIRECTORY)
|
||||||
@ -1355,7 +1357,7 @@ class LazyLoader(salt.utils.lazy.LazyDict):
|
|||||||
self.tag,
|
self.tag,
|
||||||
name)
|
name)
|
||||||
if suffix == '':
|
if suffix == '':
|
||||||
if six.PY3:
|
if USE_IMPORTLIB:
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
# Package directory, look for __init__
|
# Package directory, look for __init__
|
||||||
loader_details = [
|
loader_details = [
|
||||||
@ -1377,7 +1379,7 @@ class LazyLoader(salt.utils.lazy.LazyDict):
|
|||||||
if not self.initial_load:
|
if not self.initial_load:
|
||||||
self._reload_submodules(mod)
|
self._reload_submodules(mod)
|
||||||
else:
|
else:
|
||||||
if six.PY3:
|
if USE_IMPORTLIB:
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
loader = MODULE_KIND_MAP[desc[2]](mod_namespace, fpath)
|
loader = MODULE_KIND_MAP[desc[2]](mod_namespace, fpath)
|
||||||
spec = importlib.util.spec_from_file_location(
|
spec = importlib.util.spec_from_file_location(
|
||||||
|
@ -18,11 +18,13 @@ import jinja2
|
|||||||
import jinja2.ext
|
import jinja2.ext
|
||||||
import salt.ext.six as six
|
import salt.ext.six as six
|
||||||
|
|
||||||
if six.PY3:
|
if sys.version_info[:2] >= (3, 5):
|
||||||
import importlib.machinery # pylint: disable=no-name-in-module,import-error
|
import importlib.machinery # pylint: disable=no-name-in-module,import-error
|
||||||
import importlib.util # pylint: disable=no-name-in-module,import-error
|
import importlib.util # pylint: disable=no-name-in-module,import-error
|
||||||
|
USE_IMPORTLIB = True
|
||||||
else:
|
else:
|
||||||
import imp
|
import imp
|
||||||
|
USE_IMPORTLIB = False
|
||||||
|
|
||||||
# Import salt libs
|
# Import salt libs
|
||||||
import salt.utils
|
import salt.utils
|
||||||
@ -558,7 +560,7 @@ def py(sfn, string=False, **kwargs): # pylint: disable=C0103
|
|||||||
base_fname = os.path.basename(sfn)
|
base_fname = os.path.basename(sfn)
|
||||||
name = base_fname.split('.')[0]
|
name = base_fname.split('.')[0]
|
||||||
|
|
||||||
if six.PY3:
|
if USE_IMPORTLIB:
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
loader = importlib.machinery.SourceFileLoader(name, sfn)
|
loader = importlib.machinery.SourceFileLoader(name, sfn)
|
||||||
spec = importlib.util.spec_from_file_location(name, sfn, loader=loader)
|
spec = importlib.util.spec_from_file_location(name, sfn, loader=loader)
|
||||||
|
Loading…
Reference in New Issue
Block a user