1
0
forked from VimPlug/jedi

Move a function around

This commit is contained in:
Dave Halter
2017-10-05 18:49:12 +02:00
parent 28dea46bed
commit aa8a6d2482

View File

@@ -68,23 +68,6 @@ def _get_venv_sitepackages(venv):
return p 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): def _abs_path(module_path, path):
if os.path.isabs(path): if os.path.isabs(path):
return path return path
@@ -97,6 +80,7 @@ def _abs_path(module_path, path):
base_dir = os.path.dirname(module_path) base_dir = os.path.dirname(module_path)
return os.path.abspath(os.path.join(base_dir, path)) return os.path.abspath(os.path.join(base_dir, path))
def _paths_from_assignment(module_context, expr_stmt): def _paths_from_assignment(module_context, expr_stmt):
""" """
Extracts the assigned strings from an assignment that looks as follows:: 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' assert trailer.children[0] == '.' and trailer.children[1].value == 'path'
# TODO Essentially we're not checking details on sys.path # TODO Essentially we're not checking details on sys.path
# manipulation. Both assigment of the sys.path and changing/adding # manipulation. Both assigment of the sys.path and changing/adding
# parts of the sys.path are the same: They get added to the current # parts of the sys.path are the same: They get added to the end of
# sys.path. # the current sys.path.
""" """
execution = c[2] execution = c[2]
assert execution.children[0] == '[' assert execution.children[0] == '['
@@ -141,6 +125,23 @@ def _paths_from_assignment(module_context, expr_stmt):
yield abs_path 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): def _paths_from_list_modifications(module_path, trailer1, trailer2):
""" extract the path from either "sys.path.append" or "sys.path.insert" """ """ 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 # Guarantee that both are trailers, the first one a name and the second one