From 70687f5cb2806824133b8f880f1d69fecdbbd573 Mon Sep 17 00:00:00 2001 From: Jan Harkes Date: Thu, 10 Dec 2020 14:38:46 -0500 Subject: [PATCH] Fix fallback to other interpreters when specifying a patchlevel. When a project specifies a narrow range for the supported python versions, i.e. "python ~= 3.6.1" and the current interpreter falls outside of that range, the fallback code fails to test an available python3.6 interpreter because of a too strict a test. --- src/poetry/utils/env.py | 2 +- tests/utils/test_env.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index afaf001f55d..044816d4bbc 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -847,7 +847,7 @@ def create_venv( supported_python ): continue - elif not supported_python.allows_all( + elif not supported_python.allows_any( parse_constraint(python_to_try + ".*") ): continue diff --git a/tests/utils/test_env.py b/tests/utils/test_env.py index 981db92d54d..66c0bbd1da0 100644 --- a/tests/utils/test_env.py +++ b/tests/utils/test_env.py @@ -1093,3 +1093,35 @@ def test_env_finds_fallback_executables_for_generic_env(tmp_dir, manager): assert Path(venv.python).name == expected_executable assert Path(venv.pip).name == expected_pip_executable + + +def test_create_venv_accepts_fallback_version_w_nonzero_patchlevel( + manager, poetry, config, mocker, config_virtualenvs_path +): + if "VIRTUAL_ENV" in os.environ: + del os.environ["VIRTUAL_ENV"] + + poetry.package.python_versions = "~3.5.1" + venv_name = manager.generate_env_name("simple-project", str(poetry.file.parent)) + + check_output = mocker.patch( + "subprocess.check_output", + side_effect=lambda cmd, *args, **kwargs: str( + "3.5.12" if "python3.5" in cmd else "3.7.1" + ), + ) + m = mocker.patch( + "poetry.utils.env.EnvManager.build_venv", side_effect=lambda *args, **kwargs: "" + ) + + manager.create_venv(NullIO()) + + assert check_output.called + m.assert_called_with( + config_virtualenvs_path / "{}-py3.5".format(venv_name), + executable="python3.5", + flags={"always-copy": False, "system-site-packages": False}, + with_pip=True, + with_setuptools=True, + with_wheel=True, + )