diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2021-04-25 18:05:55 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2021-04-25 18:05:55 -0400 |
commit | b720937d0af9e8382c8b9e00b2c0d5715b7cfbe5 (patch) | |
tree | c29ce9e7423c4f89e79634991941e5bdf9d07a15 /setuptools/extern | |
parent | 8b494633df0f6770946092498aed76fd30be99b1 (diff) | |
parent | b5fa6ad11e1344648b470ff0d847a7d940b4c99d (diff) | |
download | python-setuptools-git-feature/distutils-docs.tar.gz |
Merge branch 'main' into feature/distutils-docsfeature/distutils-docs
Diffstat (limited to 'setuptools/extern')
-rw-r--r-- | setuptools/extern/__init__.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/setuptools/extern/__init__.py b/setuptools/extern/__init__.py index b7f30dc2..7df32fde 100644 --- a/setuptools/extern/__init__.py +++ b/setuptools/extern/__init__.py @@ -1,3 +1,4 @@ +import importlib.util import sys @@ -20,17 +21,10 @@ class VendorImporter: yield self.vendor_pkg + '.' yield '' - def find_module(self, fullname, path=None): - """ - Return self when fullname starts with root_name and the - target module is one vendored through this importer. - """ + def _module_matches_namespace(self, fullname): + """Figure out if the target module is vendored.""" root, base, target = fullname.partition(self.root_name + '.') - if root: - return - if not any(map(target.startswith, self.vendored_names)): - return - return self + return not root and any(map(target.startswith, self.vendored_names)) def load_module(self, fullname): """ @@ -54,6 +48,19 @@ class VendorImporter: "distribution.".format(**locals()) ) + def create_module(self, spec): + return self.load_module(spec.name) + + def exec_module(self, module): + pass + + def find_spec(self, fullname, path=None, target=None): + """Return a module spec for vendored names.""" + return ( + importlib.util.spec_from_loader(fullname, self) + if self._module_matches_namespace(fullname) else None + ) + def install(self): """ Install this importer into sys.meta_path if not already present. |