forked from VimPlug/jedi
A small refactoring
This commit is contained in:
+1
-1
@@ -43,5 +43,5 @@ from jedi.api import Script, Interpreter, set_debug_function, \
|
|||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.api.environment import find_virtualenvs, find_python_environments, \
|
from jedi.api.environment import find_virtualenvs, find_python_environments, \
|
||||||
get_default_environment, InvalidPythonEnvironment, create_environment, \
|
get_default_environment, InvalidPythonEnvironment, create_environment, \
|
||||||
find_executable, get_python_environment
|
get_python_environment
|
||||||
from jedi.api.exceptions import InternalError
|
from jedi.api.exceptions import InternalError
|
||||||
|
|||||||
@@ -241,25 +241,25 @@ def _get_python_prefix(executable):
|
|||||||
|
|
||||||
# TODO: this function should probably return a list of environments since
|
# TODO: this function should probably return a list of environments since
|
||||||
# multiple Python installations can be found on a system for the same version.
|
# multiple Python installations can be found on a system for the same version.
|
||||||
def get_python_environment(python):
|
def get_python_environment(name):
|
||||||
"""
|
"""
|
||||||
Return the first Python environment found for a given path or for a string
|
Return the first Python environment found for a given path or for a string
|
||||||
of the form 'pythonX.Y' where X and Y are the major and minor versions of
|
of the form 'pythonX.Y' where X and Y are the major and minor versions of
|
||||||
Python.
|
Python.
|
||||||
"""
|
"""
|
||||||
exe = find_executable(python)
|
exe = find_executable(name)
|
||||||
if exe:
|
if exe:
|
||||||
if exe == sys.executable:
|
if exe == sys.executable:
|
||||||
return SameEnvironment()
|
return SameEnvironment()
|
||||||
return _Environment(_get_python_prefix(exe), exe)
|
return _Environment(_get_python_prefix(exe), exe)
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
match = re.search('python(\d+\.\d+)$', python)
|
match = re.search('python(\d+\.\d+)$', name)
|
||||||
if match:
|
if match:
|
||||||
version = match.group(1)
|
version = match.group(1)
|
||||||
for prefix, exe in _get_executables_from_windows_registry(version):
|
for prefix, exe in _get_executables_from_windows_registry(version):
|
||||||
return _Environment(prefix, exe)
|
return _Environment(prefix, exe)
|
||||||
raise InvalidPythonEnvironment("Cannot find executable %s." % python)
|
raise InvalidPythonEnvironment("Cannot find executable %s." % name)
|
||||||
|
|
||||||
|
|
||||||
def create_environment(path, safe=True):
|
def create_environment(path, safe=True):
|
||||||
|
|||||||
Reference in New Issue
Block a user