Make it possible to get the right version parser for a certain environment

This commit is contained in:
Dave Halter
2017-12-16 00:30:47 +01:00
parent d0732e58cc
commit 1c62db04ba
2 changed files with 10 additions and 1 deletions

View File

@@ -11,6 +11,8 @@ from jedi.evaluate.project import Project
from jedi.cache import memoize_method
from jedi.evaluate.compiled.subprocess import get_subprocess
import parso
_VersionInfo = namedtuple('VersionInfo', 'major minor micro')
_SUPPORTED_PYTHONS = ['2.7', '3.3', '3.4', '3.5', '3.6']
@@ -35,6 +37,11 @@ class Environment(object):
def get_subprocess(self):
return get_subprocess(self._executable)
@memoize_method
def get_parser(self):
version_string = '%s.%s' % (self.version_info.major, self.version_info.minor)
return parso.load_grammar(version=version_string)
@memoize_method
def get_sys_path(self):
# It's pretty much impossible to generate the sys path without actually
@@ -115,4 +122,4 @@ def _get_version(executable):
if match is None:
raise InvalidPythonEnvironment()
return _VersionInfo(*match.groups())
return _VersionInfo(*[int(m) for m in match.groups()])

View File

@@ -15,6 +15,8 @@ def test_find_python_environments():
for env in envs:
assert env.version_info
assert env.get_sys_path()
parser_version = env.get_parser().version_info
assert parser_version[:2] == env.version_info[:2]
@pytest.mark.parametrize(