forked from VimPlug/jedi
Add a py__path__ method to the ModuleWrapper, that behaves very similar to a package's __path__ attribute.
This commit is contained in:
@@ -448,14 +448,18 @@ class _Importer(object):
|
|||||||
# This is a recursive way of importing that works great with
|
# This is a recursive way of importing that works great with
|
||||||
# the module cache.
|
# the module cache.
|
||||||
base = self._do_import(import_path[:-1], sys_path)
|
base = self._do_import(import_path[:-1], sys_path)
|
||||||
path = base.py__file__()
|
try:
|
||||||
|
paths = base.py__path__()
|
||||||
debug.dbg('search_module %s in pkg %s', module_name, path)
|
except AttributeError:
|
||||||
module_file, module_path, is_pkg = \
|
# The module is not a package.
|
||||||
find_module(import_parts[-1], [path])
|
raise NotImplementedError
|
||||||
raise NotImplementedError
|
else:
|
||||||
|
debug.dbg('search_module %s in paths %s', module_name, paths)
|
||||||
|
for path in paths:
|
||||||
|
module_file, module_path, is_pkg = \
|
||||||
|
find_module(import_parts[-1], [path])
|
||||||
else:
|
else:
|
||||||
debug.dbg('search_module %s in %s', module_name, self.file_path)
|
debug.dbg('search_module %s in %s', import_parts[-1], self.file_path)
|
||||||
# Override the sys.path. It works only good that way.
|
# Override the sys.path. It works only good that way.
|
||||||
# Injecting the path directly into `find_module` did not work.
|
# Injecting the path directly into `find_module` did not work.
|
||||||
sys.path, temp = sys_path, sys.path
|
sys.path, temp = sys_path, sys.path
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ __
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import pkgutil
|
import pkgutil
|
||||||
|
import imp
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from jedi._compatibility import use_metaclass, unicode, Python3Method
|
from jedi._compatibility import use_metaclass, unicode, Python3Method
|
||||||
@@ -762,6 +763,28 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
|
|||||||
def py__name__(self):
|
def py__name__(self):
|
||||||
return self._evaluator.module_name_cache[self]
|
return self._evaluator.module_name_cache[self]
|
||||||
|
|
||||||
|
def py__file__(self):
|
||||||
|
return self._module.path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def py__path__(self):
|
||||||
|
"""
|
||||||
|
In case of a package, this returns Python's __path__ attribute, which
|
||||||
|
is a list of paths (strings).
|
||||||
|
Raises an AttributeError if the module is not a package.
|
||||||
|
"""
|
||||||
|
def return_value():
|
||||||
|
return [path]
|
||||||
|
|
||||||
|
for suffix, _, _ in imp.get_suffixes():
|
||||||
|
ending = '__init__' + suffix
|
||||||
|
if self.py__file__().endswith(ending):
|
||||||
|
# Remove the ending, including the separator.
|
||||||
|
path = self.py__file__()[:-len(ending) - 1]
|
||||||
|
return return_value
|
||||||
|
else:
|
||||||
|
raise AttributeError('Only packages have __path__ attributes.')
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
def _sub_modules_dict(self):
|
def _sub_modules_dict(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user