follow imports if they are in the file path, fixes davidhalter/jedi-vim#56

This commit is contained in:
David Halter
2012-12-30 10:29:35 +01:00
parent 886d43fd4c
commit 41362370ed
3 changed files with 20 additions and 1 deletions

View File

@@ -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):
"""

View File

@@ -1 +1,2 @@
a = 1
from import_tree.random import a as c

View File

@@ -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