mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-09 21:42:20 +08:00
Include __init__.py files in search for the project directory, fixes #773
This commit is contained in:
@@ -100,7 +100,9 @@ class Script(object):
|
||||
sys_path = list(map(force_unicode, sys_path))
|
||||
|
||||
# Load the Python grammar of the current interpreter.
|
||||
project = get_default_project(self.path or os.getcwd())
|
||||
project = get_default_project(
|
||||
os.path.dirname(self.path)if path else os.getcwd()
|
||||
)
|
||||
# TODO deprecate and remove sys_path from the Script API.
|
||||
if sys_path is not None:
|
||||
project._sys_path = sys_path
|
||||
|
||||
@@ -11,7 +11,7 @@ from jedi.evaluate.cache import evaluator_as_method_param_cache
|
||||
from jedi.common.utils import traverse_parents
|
||||
|
||||
_CONFIG_FOLDER = '.jedi'
|
||||
_CONTAINS_POTENTIAL_PROJECT = 'setup.py', '.git', '.hg', 'MANIFEST.in'
|
||||
_CONTAINS_POTENTIAL_PROJECT = 'setup.py', '.git', '.hg', 'requirements.txt', 'MANIFEST.in'
|
||||
|
||||
_SERIALIZER_VERSION = 1
|
||||
|
||||
@@ -171,12 +171,21 @@ def get_default_project(path=None):
|
||||
|
||||
check = os.path.realpath(path)
|
||||
probable_path = None
|
||||
first_no_init_file = None
|
||||
for dir in traverse_parents(check, include_current=True):
|
||||
try:
|
||||
return Project.load(dir)
|
||||
except (FileNotFoundError, NotADirectoryError):
|
||||
pass
|
||||
|
||||
if first_no_init_file is None:
|
||||
if os.path.exists(os.path.join(dir, '__init__.py')):
|
||||
# In the case that a __init__.py exists, it's in 99% just a
|
||||
# Python package and the project sits at least one level above.
|
||||
continue
|
||||
else:
|
||||
first_no_init_file = dir
|
||||
|
||||
if _is_django_path(dir):
|
||||
return Project(dir, _django=True)
|
||||
|
||||
@@ -187,5 +196,8 @@ def get_default_project(path=None):
|
||||
# TODO search for setup.py etc
|
||||
return Project(probable_path)
|
||||
|
||||
if first_no_init_file is not None:
|
||||
return Project(first_no_init_file)
|
||||
|
||||
curdir = path if os.path.isdir(path) else os.path.dirname(path)
|
||||
return Project(curdir)
|
||||
|
||||
Reference in New Issue
Block a user