diff --git a/jedi/imports.py b/jedi/imports.py index 9e013b92..de0af587 100644 --- a/jedi/imports.py +++ b/jedi/imports.py @@ -146,8 +146,18 @@ class ImportPath(parsing.Base): return names def sys_path_with_modifications(self): + # If you edit e.g. gunicorn, there will be imports like this: + # `from gunicorn import something`. But gunicorn is not in the + # sys.path. Therefore look if gunicorn is a parent directory, #56. + parts = self.file_path.split(os.path.sep) + in_path = [] + for i, p in enumerate(parts): + if p == self.import_path[0]: + new = os.path.sep.join(parts[:i]) + in_path.append(new) + module = self.import_stmt.get_parent_until() - return modules.sys_path_with_modifications(module) + return in_path + modules.sys_path_with_modifications(module) def follow(self, is_goto=False): """ diff --git a/test/completion/import_tree/mod1.py b/test/completion/import_tree/mod1.py index 1337a530..172103a3 100644 --- a/test/completion/import_tree/mod1.py +++ b/test/completion/import_tree/mod1.py @@ -1 +1,2 @@ a = 1 +from import_tree.random import a as c diff --git a/test/completion/imports.py b/test/completion/imports.py index 9f5d4d24..bc5ebc06 100644 --- a/test/completion/imports.py +++ b/test/completion/imports.py @@ -215,3 +215,11 @@ from not_a_module import # self import # this can cause recursions from imports import * + +# ----------------- +# packages +# ----------------- + +from import_tree.mod1 import c +#? set +c