diff --git a/jedi/evaluate/sys_path.py b/jedi/evaluate/sys_path.py index 748a5457..f2b75385 100644 --- a/jedi/evaluate/sys_path.py +++ b/jedi/evaluate/sys_path.py @@ -68,23 +68,6 @@ def _get_venv_sitepackages(venv): return p -def _execute_code(module_path, code): - c = "import os; from os.path import *; result=%s" - variables = {'__file__': module_path} - try: - exec_function(c % code, variables) - except Exception: - debug.warning('sys.path manipulation detected, but failed to evaluate.') - else: - try: - res = variables['result'] - if isinstance(res, str): - return _abs_path(module_path, res) - except KeyError: - pass - return None - - def _abs_path(module_path, path): if os.path.isabs(path): return path @@ -97,6 +80,7 @@ def _abs_path(module_path, path): base_dir = os.path.dirname(module_path) return os.path.abspath(os.path.join(base_dir, path)) + def _paths_from_assignment(module_context, expr_stmt): """ Extracts the assigned strings from an assignment that looks as follows:: @@ -119,8 +103,8 @@ def _paths_from_assignment(module_context, expr_stmt): assert trailer.children[0] == '.' and trailer.children[1].value == 'path' # TODO Essentially we're not checking details on sys.path # manipulation. Both assigment of the sys.path and changing/adding - # parts of the sys.path are the same: They get added to the current - # sys.path. + # parts of the sys.path are the same: They get added to the end of + # the current sys.path. """ execution = c[2] assert execution.children[0] == '[' @@ -141,6 +125,23 @@ def _paths_from_assignment(module_context, expr_stmt): yield abs_path +def _execute_code(module_path, code): + c = "import os; from os.path import *; result=%s" + variables = {'__file__': module_path} + try: + exec_function(c % code, variables) + except Exception: + debug.warning('sys.path manipulation detected, but failed to evaluate.') + else: + try: + res = variables['result'] + if isinstance(res, str): + return _abs_path(module_path, res) + except KeyError: + pass + return None + + def _paths_from_list_modifications(module_path, trailer1, trailer2): """ extract the path from either "sys.path.append" or "sys.path.insert" """ # Guarantee that both are trailers, the first one a name and the second one