mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #24192: Fix namespace package imports.
This commit is contained in:
parent
188c18d48f
commit
183a941bc1
8 changed files with 4525 additions and 4591 deletions
|
@ -22,6 +22,8 @@ work. One should use importlib as the public-facing version of this module.
|
|||
|
||||
# Bootstrap-related code ######################################################
|
||||
|
||||
_bootstrap_external = None
|
||||
|
||||
def _wrap(new, old):
|
||||
"""Simple substitute for functools.update_wrapper."""
|
||||
for replace in ['__module__', '__name__', '__qualname__', '__doc__']:
|
||||
|
@ -405,7 +407,8 @@ class ModuleSpec:
|
|||
def cached(self):
|
||||
if self._cached is None:
|
||||
if self.origin is not None and self._set_fileattr:
|
||||
import _frozen_importlib_external as _bootstrap_external # XXX yuck
|
||||
if _bootstrap_external is None:
|
||||
raise NotImplementedError
|
||||
self._cached = _bootstrap_external._get_cached(self.origin)
|
||||
return self._cached
|
||||
|
||||
|
@ -433,7 +436,10 @@ class ModuleSpec:
|
|||
def spec_from_loader(name, loader, *, origin=None, is_package=None):
|
||||
"""Return a module spec based on various loader methods."""
|
||||
if hasattr(loader, 'get_filename'):
|
||||
from ._bootstrap_external import spec_from_file_location # XXX yuck
|
||||
if _bootstrap_external is None:
|
||||
raise NotImplementedError
|
||||
spec_from_file_location = _bootstrap_external.spec_from_file_location
|
||||
|
||||
if is_package is None:
|
||||
return spec_from_file_location(name, loader=loader)
|
||||
search = [] if is_package else None
|
||||
|
@ -516,7 +522,10 @@ def _init_module_attrs(spec, module, *, override=False):
|
|||
if loader is None:
|
||||
# A backward compatibility hack.
|
||||
if spec.submodule_search_locations is not None:
|
||||
from ._bootstrap_external import _NamespaceLoader # XXX yuck
|
||||
if _bootstrap_external is None:
|
||||
raise NotImplementedError
|
||||
_NamespaceLoader = _bootstrap_external._NamespaceLoader
|
||||
|
||||
loader = _NamespaceLoader.__new__(_NamespaceLoader)
|
||||
loader._path = spec.submodule_search_locations
|
||||
try:
|
||||
|
@ -810,7 +819,6 @@ class FrozenImporter:
|
|||
This method is deprecated. Use exec_module() instead.
|
||||
|
||||
"""
|
||||
from ._bootstrap_external import _load_module_shim # XXX yuck
|
||||
return _load_module_shim(cls, fullname)
|
||||
|
||||
@classmethod
|
||||
|
@ -1125,6 +1133,7 @@ def _install(sys_module, _imp_module):
|
|||
sys.meta_path.append(BuiltinImporter)
|
||||
sys.meta_path.append(FrozenImporter)
|
||||
|
||||
global _bootstrap_external
|
||||
import _frozen_importlib_external
|
||||
_bootstrap_external = _frozen_importlib_external
|
||||
_frozen_importlib_external._install(sys.modules[__name__])
|
||||
sys.modules[__name__]._bootstrap_external = _frozen_importlib_external
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue