diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2016-08-24 09:44:03 +0300 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2016-08-24 09:57:39 +0300 |
commit | 6b9a7ed82cef0b89edb00b19e991fe6ec5d057d5 (patch) | |
tree | e8bcd6765980f5c9fc628d44714888da14416a9d /astroid/modutils.py | |
parent | 8ec025fa36c9c627bcdd6da7fab56271731d47eb (diff) | |
download | astroid-git-6b9a7ed82cef0b89edb00b19e991fe6ec5d057d5.tar.gz |
Add support for discovering .pth file created by certain namespace packages.
Diffstat (limited to 'astroid/modutils.py')
-rw-r--r-- | astroid/modutils.py | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/astroid/modutils.py b/astroid/modutils.py index 77081b5b..3334e1e3 100644 --- a/astroid/modutils.py +++ b/astroid/modutils.py @@ -742,6 +742,22 @@ class ImpFinder(Finder): return path +class DynamicImpFinder(ImpFinder): + + def find_module(self, modname, module_parts, processed, submodule_path): + if _is_namespace(modname) and modname in sys.modules: + submodule_path = sys.modules[modname].__path__ + return ModuleSpec(name=modname, location='', + origin='namespace', + type=ModuleType.PY_NAMESPACE, + submodule_search_locations=submodule_path) + + + def contribute_to_path(self, spec, processed): + return spec.submodule_search_locations + + + class ZipFinder(Finder): def __init__(self, path): @@ -776,12 +792,17 @@ class PEP420SpecFinder(Finder): return spec.submodule_search_locations return None +_SPEC_FINDERS = ( + ImpFinder, + ZipFinder, +) +if _HAS_MACHINERY and sys.version_info[:2] > (3, 3): + _SPEC_FINDERS += (PEP420SpecFinder, ) +_SPEC_FINDERS += (DynamicImpFinder, ) -def _find_spec_with_path(search_path, modname, module_parts, processed, submodule_path): - finders = [finder(search_path) for finder in (ImpFinder, ZipFinder)] - if _HAS_MACHINERY and sys.version_info[:2] > (3, 3): - finders.append(PEP420SpecFinder(search_path)) +def _find_spec_with_path(search_path, modname, module_parts, processed, submodule_path): + finders = [finder(search_path) for finder in _SPEC_FINDERS] for finder in finders: spec = finder.find_module(modname, module_parts, processed, submodule_path) if spec is None: |