forked from VimPlug/jedi
Fixed sys path scanning again.
This commit is contained in:
@@ -71,7 +71,7 @@ class BaseDefinition(object):
|
|||||||
if self.in_builtin_module():
|
if self.in_builtin_module():
|
||||||
self.module_path = None
|
self.module_path = None
|
||||||
else:
|
else:
|
||||||
self.module_path = self._module.path
|
self.module_path = self._module.py__file__()
|
||||||
"""Shows the file path of a module. e.g. ``/usr/lib/python2.7/os.py``"""
|
"""Shows the file path of a module. e.g. ``/usr/lib/python2.7/os.py``"""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -449,7 +449,6 @@ class ModuleContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
|||||||
def __init__(self, evaluator, module_node):
|
def __init__(self, evaluator, module_node):
|
||||||
super(ModuleContext, self).__init__(evaluator, parent_context=None)
|
super(ModuleContext, self).__init__(evaluator, parent_context=None)
|
||||||
self.module_node = module_node
|
self.module_node = module_node
|
||||||
self.path = None
|
|
||||||
|
|
||||||
def get_node(self):
|
def get_node(self):
|
||||||
return self.module_node
|
return self.module_node
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from jedi.parser import ParserWithRecovery
|
|||||||
from jedi.evaluate.cache import memoize_default
|
from jedi.evaluate.cache import memoize_default
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import common
|
from jedi import common
|
||||||
|
from jedi.evaluate.compiled import CompiledObject
|
||||||
from jedi.parser.utils import load_parser, save_parser
|
from jedi.parser.utils import load_parser, save_parser
|
||||||
|
|
||||||
|
|
||||||
@@ -146,7 +147,7 @@ def _paths_from_list_modifications(module_path, trailer1, trailer2):
|
|||||||
return _execute_code(module_path, arg.get_code())
|
return _execute_code(module_path, arg.get_code())
|
||||||
|
|
||||||
|
|
||||||
def _check_module(evaluator, module):
|
def _check_module(evaluator, module_context):
|
||||||
"""
|
"""
|
||||||
Detect sys.path modifications within module.
|
Detect sys.path modifications within module.
|
||||||
"""
|
"""
|
||||||
@@ -162,8 +163,11 @@ def _check_module(evaluator, module):
|
|||||||
yield name, power
|
yield name, power
|
||||||
|
|
||||||
sys_path = list(evaluator.sys_path) # copy
|
sys_path = list(evaluator.sys_path) # copy
|
||||||
|
if isinstance(module_context, CompiledObject):
|
||||||
|
return sys_path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
possible_names = module.used_names['path']
|
possible_names = module_context.get_node().used_names['path']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# module.used_names is MergedNamesDict whose getitem never throws
|
# module.used_names is MergedNamesDict whose getitem never throws
|
||||||
# keyerror, this is superfluous.
|
# keyerror, this is superfluous.
|
||||||
@@ -172,15 +176,20 @@ def _check_module(evaluator, module):
|
|||||||
for name, power in get_sys_path_powers(possible_names):
|
for name, power in get_sys_path_powers(possible_names):
|
||||||
stmt = name.get_definition()
|
stmt = name.get_definition()
|
||||||
if len(power.children) >= 4:
|
if len(power.children) >= 4:
|
||||||
sys_path.extend(_paths_from_list_modifications(module.path, *power.children[2:4]))
|
sys_path.extend(
|
||||||
|
_paths_from_list_modifications(
|
||||||
|
module_context.py__file__(), *power.children[2:4]
|
||||||
|
)
|
||||||
|
)
|
||||||
elif name.get_definition().type == 'expr_stmt':
|
elif name.get_definition().type == 'expr_stmt':
|
||||||
sys_path.extend(_paths_from_assignment(evaluator, stmt))
|
sys_path.extend(_paths_from_assignment(evaluator, stmt))
|
||||||
return sys_path
|
return sys_path
|
||||||
|
|
||||||
|
|
||||||
@memoize_default(evaluator_is_first_arg=True, default=[])
|
@memoize_default(evaluator_is_first_arg=True, default=[])
|
||||||
def sys_path_with_modifications(evaluator, module):
|
def sys_path_with_modifications(evaluator, module_context):
|
||||||
if module.path is None:
|
path = module_context.py__file__()
|
||||||
|
if path is None:
|
||||||
# Support for modules without a path is bad, therefore return the
|
# Support for modules without a path is bad, therefore return the
|
||||||
# normal path.
|
# normal path.
|
||||||
return list(evaluator.sys_path)
|
return list(evaluator.sys_path)
|
||||||
@@ -188,13 +197,13 @@ def sys_path_with_modifications(evaluator, module):
|
|||||||
curdir = os.path.abspath(os.curdir)
|
curdir = os.path.abspath(os.curdir)
|
||||||
#TODO why do we need a chdir?
|
#TODO why do we need a chdir?
|
||||||
with common.ignored(OSError):
|
with common.ignored(OSError):
|
||||||
os.chdir(os.path.dirname(module.path))
|
os.chdir(os.path.dirname(path))
|
||||||
|
|
||||||
buildout_script_paths = set()
|
buildout_script_paths = set()
|
||||||
|
|
||||||
result = _check_module(evaluator, module)
|
result = _check_module(evaluator, module_context)
|
||||||
result += _detect_django_path(module.path)
|
result += _detect_django_path(path)
|
||||||
for buildout_script in _get_buildout_scripts(module.path):
|
for buildout_script in _get_buildout_scripts(path):
|
||||||
for path in _get_paths_from_buildout_script(evaluator, buildout_script):
|
for path in _get_paths_from_buildout_script(evaluator, buildout_script):
|
||||||
buildout_script_paths.add(path)
|
buildout_script_paths.add(path)
|
||||||
# cleanup, back to old directory
|
# cleanup, back to old directory
|
||||||
|
|||||||
Reference in New Issue
Block a user