find_python_environments -> find_system_environments

This commit is contained in:
Dave Halter
2018-04-14 15:46:16 +02:00
parent 45fb770033
commit 336087fcf8
5 changed files with 15 additions and 15 deletions

View File

@@ -6,7 +6,7 @@ from functools import partial
import pytest import pytest
import jedi import jedi
from jedi.api.environment import get_default_environment, get_python_environment from jedi.api.environment import get_default_environment, get_system_environment
from jedi._compatibility import py_version from jedi._compatibility import py_version
collect_ignore = [ collect_ignore = [
@@ -94,7 +94,7 @@ def environment(request):
if int(version) == py_version: if int(version) == py_version:
return get_default_environment() return get_default_environment()
return get_python_environment('python%s.%s' % tuple(version)) return get_system_environment('python%s.%s' % tuple(version))
@pytest.fixture(scope='session') @pytest.fixture(scope='session')

View File

@@ -41,7 +41,7 @@ __version__ = '0.12.0'
from jedi.api import Script, Interpreter, set_debug_function, \ from jedi.api import Script, Interpreter, set_debug_function, \
preload_module, names preload_module, names
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_system_environments, \
get_default_environment, InvalidPythonEnvironment, create_environment, \ get_default_environment, InvalidPythonEnvironment, create_environment, \
get_python_environment get_system_environment
from jedi.api.exceptions import InternalError from jedi.api.exceptions import InternalError

View File

@@ -153,7 +153,7 @@ def get_default_environment():
if virtual_env is not None: if virtual_env is not None:
return virtual_env return virtual_env
for environment in find_python_environments(): for environment in find_system_environments():
return environment return environment
# If no Python Environment is found, use the environment we're already # If no Python Environment is found, use the environment we're already
@@ -207,7 +207,7 @@ def find_virtualenvs(paths=None, **kwargs):
return py27_comp(paths, **kwargs) return py27_comp(paths, **kwargs)
def find_python_environments(): def find_system_environments():
""" """
Ignores virtualenvs and returns the Python versions that were installed on Ignores virtualenvs and returns the Python versions that were installed on
your system. This might return nothing, if you're running Python e.g. from your system. This might return nothing, if you're running Python e.g. from
@@ -217,7 +217,7 @@ def find_python_environments():
""" """
for version_string in _SUPPORTED_PYTHONS: for version_string in _SUPPORTED_PYTHONS:
try: try:
yield get_python_environment('python' + version_string) yield get_system_environment('python' + version_string)
except InvalidPythonEnvironment: except InvalidPythonEnvironment:
pass pass
@@ -241,7 +241,7 @@ 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(name): def get_system_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
@@ -328,7 +328,7 @@ def _is_safe(executable_path):
# Just check the list of known Python versions. If it's not in there, # Just check the list of known Python versions. If it's not in there,
# it's likely an attacker or some Python that was not properly # it's likely an attacker or some Python that was not properly
# installed in the system. # installed in the system.
for environment in find_python_environments(): for environment in find_system_environments():
if environment.executable == real_path: if environment.executable == real_path:
return True return True

View File

@@ -125,7 +125,7 @@ from jedi._compatibility import unicode, is_py3
from jedi.api.classes import Definition from jedi.api.classes import Definition
from jedi.api.completion import get_user_scope from jedi.api.completion import get_user_scope
from jedi import parser_utils from jedi import parser_utils
from jedi.api.environment import get_default_environment, get_python_environment from jedi.api.environment import get_default_environment, get_system_environment
TEST_COMPLETIONS = 0 TEST_COMPLETIONS = 0
@@ -435,7 +435,7 @@ if __name__ == '__main__':
return 1 return 1
if arguments['--env']: if arguments['--env']:
environment = get_python_environment('python' + arguments['--env']) environment = get_system_environment('python' + arguments['--env'])
else: else:
# Will be 3.6. # Will be 3.6.
environment = get_default_environment() environment = get_default_environment()

View File

@@ -6,15 +6,15 @@ import pytest
import jedi import jedi
from jedi._compatibility import py_version from jedi._compatibility import py_version
from jedi.api.environment import get_default_environment, find_virtualenvs, \ from jedi.api.environment import get_default_environment, find_virtualenvs, \
InvalidPythonEnvironment, find_python_environments, get_python_environment InvalidPythonEnvironment, find_system_environments, get_system_environment
def test_sys_path(): def test_sys_path():
assert get_default_environment().get_sys_path() assert get_default_environment().get_sys_path()
def test_find_python_environments(): def test_find_system_environments():
envs = list(find_python_environments()) envs = list(find_system_environments())
assert len(envs) assert len(envs)
for env in envs: for env in envs:
assert env.version_info assert env.version_info
@@ -29,7 +29,7 @@ def test_find_python_environments():
) )
def test_versions(version): def test_versions(version):
try: try:
env = get_python_environment('python' + version) env = get_system_environment('python' + version)
except InvalidPythonEnvironment: except InvalidPythonEnvironment:
if int(version.replace('.', '')) == py_version: if int(version.replace('.', '')) == py_version:
# At least the current version has to work # At least the current version has to work