diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2015-09-06 21:44:45 +0300 |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2015-09-06 21:44:45 +0300 |
commit | f352202977fc53197bd38198b1ac26ed4008a9ba (patch) | |
tree | 34246df426e6f7d82794886be98c613903a5655e /Lib/importlib/__init__.py | |
parent | d68070857ae58758849446f5ae162ff3bffb7d6e (diff) | |
parent | 2936930f6c8fc1d8992b680181c30f417d74b7c2 (diff) | |
download | cpython-f352202977fc53197bd38198b1ac26ed4008a9ba.tar.gz |
#23144: merge with 3.4.
Diffstat (limited to 'Lib/importlib/__init__.py')
-rw-r--r-- | Lib/importlib/__init__.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index 1bc99474f2..b6a9f82e05 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -30,9 +30,26 @@ else: pass sys.modules['importlib._bootstrap'] = _bootstrap +try: + import _frozen_importlib_external as _bootstrap_external +except ImportError: + from . import _bootstrap_external + _bootstrap_external._setup(_bootstrap) + _bootstrap._bootstrap_external = _bootstrap_external +else: + _bootstrap_external.__name__ = 'importlib._bootstrap_external' + _bootstrap_external.__package__ = 'importlib' + try: + _bootstrap_external.__file__ = __file__.replace('__init__.py', '_bootstrap_external.py') + except NameError: + # __file__ is not guaranteed to be defined, e.g. if this code gets + # frozen by a tool like cx_Freeze. + pass + sys.modules['importlib._bootstrap_external'] = _bootstrap_external + # To simplify imports in test code -_w_long = _bootstrap._w_long -_r_long = _bootstrap._r_long +_w_long = _bootstrap_external._w_long +_r_long = _bootstrap_external._r_long # Fully bootstrapped at this point, import whatever you like, circular # dependencies and startup overhead minimisation permitting :) @@ -73,7 +90,7 @@ def find_loader(name, path=None): except KeyError: pass except AttributeError: - raise ValueError('{}.__loader__ is not set'.format(name)) + raise ValueError('{}.__loader__ is not set'.format(name)) from None spec = _bootstrap._find_spec(name, path) # We won't worry about malformed specs (missing attributes). @@ -138,15 +155,15 @@ def reload(module): parent = sys.modules[parent_name] except KeyError: msg = "parent {!r} not in sys.modules" - raise ImportError(msg.format(parent_name), name=parent_name) + raise ImportError(msg.format(parent_name), + name=parent_name) from None else: pkgpath = parent.__path__ else: pkgpath = None target = module spec = module.__spec__ = _bootstrap._find_spec(name, pkgpath, target) - methods = _bootstrap._SpecMethods(spec) - methods.exec(module) + _bootstrap._exec(spec, module) # The module may have replaced itself in sys.modules! return sys.modules[name] finally: |