From 8e1e87c5d9e6e8832d684cf9313de61155823592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Sat, 23 Mar 2024 14:56:35 +0100 Subject: [PATCH] env: add support for untagged CPython builds where platform.python_version() ends with a "+" works around https://github.com/python/cpython/issues/99968 --- src/poetry/utils/env/script_strings.py | 2 +- src/poetry/utils/env/system_env.py | 3 ++- tests/utils/env/test_system_env.py | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/utils/env/test_system_env.py diff --git a/src/poetry/utils/env/script_strings.py b/src/poetry/utils/env/script_strings.py index 246649867f3..3e663e3e0c6 100644 --- a/src/poetry/utils/env/script_strings.py +++ b/src/poetry/utils/env/script_strings.py @@ -82,7 +82,7 @@ def _version_nodot(version): "platform_release": platform.release(), "platform_system": platform.system(), "platform_version": platform.version(), - "python_full_version": platform.python_version(), + "python_full_version": platform.python_version().rstrip("+"), "platform_python_implementation": platform.python_implementation(), "python_version": ".".join(platform.python_version_tuple()[:2]), "sys_platform": sys.platform, diff --git a/src/poetry/utils/env/system_env.py b/src/poetry/utils/env/system_env.py index 8ddef7b5608..81396206ff3 100644 --- a/src/poetry/utils/env/system_env.py +++ b/src/poetry/utils/env/system_env.py @@ -71,7 +71,8 @@ def get_marker_env(self) -> dict[str, Any]: "platform_release": platform.release(), "platform_system": platform.system(), "platform_version": platform.version(), - "python_full_version": platform.python_version(), + # Workaround for https://github.com/python/cpython/issues/99968 + "python_full_version": platform.python_version().rstrip("+"), "platform_python_implementation": platform.python_implementation(), "python_version": ".".join(platform.python_version().split(".")[:2]), "sys_platform": sys.platform, diff --git a/tests/utils/env/test_system_env.py b/tests/utils/env/test_system_env.py new file mode 100644 index 00000000000..4e71a2c595c --- /dev/null +++ b/tests/utils/env/test_system_env.py @@ -0,0 +1,19 @@ +from __future__ import annotations + +import sys + +from pathlib import Path +from typing import TYPE_CHECKING + +from poetry.utils.env import SystemEnv + + +if TYPE_CHECKING: + from pytest_mock import MockerFixture + + +def test_get_marker_env_untagged_cpython(mocker: MockerFixture) -> None: + mocker.patch("platform.python_version", return_value="3.11.9+") + env = SystemEnv(Path(sys.prefix)) + marker_env = env.get_marker_env() + assert marker_env["python_full_version"] == "3.11.9"