forked from VimPlug/jedi
Fix calculate_dotted_path_from_sys_path. It was broken beyond stupid.
This commit is contained in:
@@ -145,7 +145,6 @@ class ModuleContext(ModuleMixin, TreeContext):
|
||||
self._path = path
|
||||
self._string_names = string_names
|
||||
self.code_lines = code_lines
|
||||
#print(self._path)
|
||||
|
||||
def _get_init_directory(self):
|
||||
"""
|
||||
|
||||
@@ -517,7 +517,7 @@ def get_modules_containing_name(evaluator, modules, name):
|
||||
code = python_bytes_to_unicode(f.read(), errors='replace')
|
||||
if name in code:
|
||||
e_sys_path = evaluator.get_sys_path()
|
||||
import_names = sys_path.dotted_path_in_sys_path(e_sys_path, path)
|
||||
import_names = sys_path.calculate_dotted_path_from_sys_path(e_sys_path, path)
|
||||
module = _load_module(
|
||||
evaluator, path, code,
|
||||
sys_path=e_sys_path,
|
||||
|
||||
@@ -197,31 +197,38 @@ def _get_buildout_script_paths(search_path):
|
||||
continue
|
||||
|
||||
|
||||
def dotted_path_in_sys_path(sys_path, module_path):
|
||||
def calculate_dotted_path_from_sys_path(sys_path, module_path):
|
||||
"""
|
||||
Returns the dotted path inside a sys.path as a list of names.
|
||||
|
||||
This function is supposed to be a backup plan in case there's no idea where
|
||||
a file is lying.
|
||||
"""
|
||||
# First remove the suffix.
|
||||
for suffix in all_suffixes():
|
||||
if module_path.endswith(suffix):
|
||||
module_path = module_path[:-len(suffix)]
|
||||
break
|
||||
break
|
||||
else:
|
||||
# There should always be a suffix in a valid Python file on the path.
|
||||
return None
|
||||
|
||||
if module_path.startswith(os.path.sep):
|
||||
# The paths in sys.path most of the times don't end with a slash.
|
||||
module_path = module_path[1:]
|
||||
if module_path.endswith('__init__'):
|
||||
module_path = module_path[:-len('__init__') - 1]
|
||||
|
||||
if module_path.endswith(os.path.sep):
|
||||
# The paths in sys.path may end with a slash.
|
||||
module_path = module_path[:-1]
|
||||
|
||||
for p in sys_path:
|
||||
if module_path.startswith(p):
|
||||
rest = module_path[len(p):]
|
||||
if rest.startswith(os.path.sep) or rest.startswith('/'):
|
||||
rest = rest[1:]
|
||||
if rest:
|
||||
split = rest.split(os.path.sep)
|
||||
for string in split:
|
||||
if not string or '.' in string:
|
||||
return None
|
||||
return split
|
||||
|
||||
return tuple(split)
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user