mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Make it possible to get the right version parser for a certain environment
This commit is contained in:
@@ -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()])
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user