Commit 6987aaa8 by Sébastien Eustace Committed by GitHub

Fix the python patch version retrieval when passing an executable (#1736)

Fixes #1735
parent a7792f6a
...@@ -494,18 +494,19 @@ class EnvManager(object): ...@@ -494,18 +494,19 @@ class EnvManager(object):
python_patch = ".".join([str(v) for v in sys.version_info[:3]]) python_patch = ".".join([str(v) for v in sys.version_info[:3]])
python_minor = ".".join([str(v) for v in sys.version_info[:2]]) python_minor = ".".join([str(v) for v in sys.version_info[:2]])
if executable: if executable:
python_minor = decode( python_patch = decode(
subprocess.check_output( subprocess.check_output(
" ".join( " ".join(
[ [
executable, executable,
"-c", "-c",
"\"import sys; print('.'.join([str(s) for s in sys.version_info[:2]]))\"", "\"import sys; print('.'.join([str(s) for s in sys.version_info[:3]]))\"",
] ]
), ),
shell=True, shell=True,
).strip() ).strip()
) )
python_minor = ".".join(python_patch.split(".")[:2])
supported_python = self._poetry.package.python_constraint supported_python = self._poetry.package.python_constraint
if not supported_python.allows(Version.parse(python_patch)): if not supported_python.allows(Version.parse(python_patch)):
...@@ -517,7 +518,7 @@ class EnvManager(object): ...@@ -517,7 +518,7 @@ class EnvManager(object):
# Otherwise, we try to find a compatible Python version. # Otherwise, we try to find a compatible Python version.
if executable: if executable:
raise NoCompatiblePythonVersionFound( raise NoCompatiblePythonVersionFound(
self._poetry.package.python_versions, python_minor self._poetry.package.python_versions, python_patch
) )
io.write_line( io.write_line(
......
...@@ -700,6 +700,45 @@ def test_create_venv_uses_patch_version_to_detect_compatibility( ...@@ -700,6 +700,45 @@ def test_create_venv_uses_patch_version_to_detect_compatibility(
) )
def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable(
manager, poetry, config, mocker
):
if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"]
version = Version.parse(".".join(str(c) for c in sys.version_info[:3]))
poetry.package.python_versions = "~{}".format(
".".join(str(c) for c in (version.major, version.minor - 1, 0))
)
venv_name = manager.generate_env_name("simple-project", str(poetry.file.parent))
check_output = mocker.patch(
"poetry.utils._compat.subprocess.check_output",
side_effect=check_output_wrapper(
Version.parse("{}.{}.0".format(version.major, version.minor - 1))
),
)
m = mocker.patch(
"poetry.utils.env.EnvManager.build_venv", side_effect=lambda *args, **kwargs: ""
)
manager.create_venv(
NullIO(), executable="python{}.{}".format(version.major, version.minor - 1)
)
assert check_output.called
m.assert_called_with(
str(
Path(
"/foo/virtualenvs/{}-py{}.{}".format(
venv_name, version.major, version.minor - 1
)
)
),
executable="python{}.{}".format(version.major, version.minor - 1),
)
def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir( def test_activate_with_in_project_setting_does_not_fail_if_no_venvs_dir(
manager, poetry, config, tmp_dir, mocker manager, poetry, config, tmp_dir, mocker
): ):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment