mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Document get_sys_path and change the signature of get_system_environment a bit
This commit is contained in:
@@ -102,6 +102,12 @@ class Environment(_BaseEnvironment):
|
|||||||
|
|
||||||
@memoize_method
|
@memoize_method
|
||||||
def get_sys_path(self):
|
def get_sys_path(self):
|
||||||
|
"""
|
||||||
|
The sys path for this environment. Does not include potential
|
||||||
|
modifications like ``sys.path.append``.
|
||||||
|
|
||||||
|
:returns: list of str
|
||||||
|
"""
|
||||||
# It's pretty much impossible to generate the sys path without actually
|
# It's pretty much impossible to generate the sys path without actually
|
||||||
# executing Python. The sys path (when starting with -S) itself depends
|
# executing Python. The sys path (when starting with -S) itself depends
|
||||||
# on how the Python version was compiled (ENV variables).
|
# on how the Python version was compiled (ENV variables).
|
||||||
@@ -235,7 +241,7 @@ def find_system_environments():
|
|||||||
"""
|
"""
|
||||||
for version_string in _SUPPORTED_PYTHONS:
|
for version_string in _SUPPORTED_PYTHONS:
|
||||||
try:
|
try:
|
||||||
yield get_system_environment('python' + version_string)
|
yield get_system_environment(version_string)
|
||||||
except InvalidPythonEnvironment:
|
except InvalidPythonEnvironment:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -259,28 +265,24 @@ 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_system_environment(name):
|
def get_system_environment(version):
|
||||||
"""
|
"""
|
||||||
Return the first Python environment found for a given path or for a string
|
Return the first Python environment found for a string of the form 'X.Y'
|
||||||
of the form 'pythonX.Y' where X and Y are the major and minor versions of
|
where X and Y are the major and minor versions of Python.
|
||||||
Python.
|
|
||||||
|
|
||||||
:raises: :exc:`.InvalidPythonEnvironment`
|
:raises: :exc:`.InvalidPythonEnvironment`
|
||||||
:returns: :class:`Environment`
|
:returns: :class:`Environment`
|
||||||
"""
|
"""
|
||||||
exe = find_executable(name)
|
exe = find_executable('python' + version)
|
||||||
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+)$', name)
|
|
||||||
if match:
|
|
||||||
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." % name)
|
raise InvalidPythonEnvironment("Cannot find executable python%s." % version)
|
||||||
|
|
||||||
|
|
||||||
def create_environment(path, safe=True):
|
def create_environment(path, safe=True):
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ def time_cache(seconds):
|
|||||||
|
|
||||||
def memoize_method(method):
|
def memoize_method(method):
|
||||||
"""A normal memoize function."""
|
"""A normal memoize function."""
|
||||||
|
@wraps(method)
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
cache_dict = self.__dict__.setdefault('_memoize_method_dct', {})
|
cache_dict = self.__dict__.setdefault('_memoize_method_dct', {})
|
||||||
dct = cache_dict.setdefault(method, {})
|
dct = cache_dict.setdefault(method, {})
|
||||||
|
|||||||
Reference in New Issue
Block a user