From fdc9eb0355f3f58ca700147dc15e4c6894595bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Wed, 7 Aug 2024 10:15:57 -0700 Subject: [PATCH] Restore limited . environment name support (#3319) --- docs/changelog.rst | 8 ++++---- docs/changelog/2849.bugfix.rst | 1 + src/tox/tox_env/python/api.py | 13 +++++++++---- tests/tox_env/python/test_python_api.py | 3 +++ 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 docs/changelog/2849.bugfix.rst diff --git a/docs/changelog.rst b/docs/changelog.rst index 5cfedf69b..ce8275571 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -9,7 +9,7 @@ v4.17.0 (2024-08-05) Features - 4.17.0 ~~~~~~~~~~~~~~~~~ -- Add "graalpy" prefix as a supported base python (:issue:`3312`) +- Add ``graalpy`` prefix as a supported base python (:issue:`3312`) - Add :ref:`on_platform` core configuration holding the tox platform and do not install package when exec an environment - by :user:`gaborbernat`. (:issue:`3315`) @@ -69,7 +69,7 @@ Bugfixes - 4.14.2 Improved Documentation - 4.14.2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Removed unused line from the 'fresh_subprocess' documentation. (:issue:`3241`) +- Removed unused line from the ``fresh_subprocess`` documentation. (:issue:`3241`) v4.14.1 (2024-03-06) -------------------- @@ -216,9 +216,9 @@ v4.7.0 (2023-08-08) Features - 4.7.0 ~~~~~~~~~~~~~~~~ -- Make --hashseed default to PYTHONHASHSEED, if defined - by :user:`paravoid`. +- Make ``--hashseed`` default to ``PYTHONHASHSEED``, if defined - by :user:`paravoid`. The main motivation for this is to able to set the hash seed when building the - documentation with "tox -e docs", and thus avoid embedding a random value in + documentation with ``tox -e docs``, and thus avoid embedding a random value in the tox documentation for --help. This caused documentation builds to fail to build reproducibly. (:issue:`2942`) diff --git a/docs/changelog/2849.bugfix.rst b/docs/changelog/2849.bugfix.rst new file mode 100644 index 000000000..7e5b2101f --- /dev/null +++ b/docs/changelog/2849.bugfix.rst @@ -0,0 +1 @@ +Support for running ``-e .`` has been lost, fixing it - by :user:`gaborbernat`. diff --git a/src/tox/tox_env/python/api.py b/src/tox/tox_env/python/api.py index ed8ba8ece..1f9141790 100644 --- a/src/tox/tox_env/python/api.py +++ b/src/tox/tox_env/python/api.py @@ -56,6 +56,7 @@ def version_dot(self) -> str: """, re.VERBOSE, ) +PY_FACTORS_RE_EXPLICIT_VERSION = re.compile(r"^(?P[2-9]\.[0-9]+)$") class Python(ToxEnv, ABC): @@ -142,10 +143,14 @@ def default_base_python(self, conf: Config, env_name: str | None) -> list[str]: @classmethod def extract_base_python(cls, env_name: str) -> str | None: candidates: list[str] = [] - for factor in env_name.split("-"): - match = PY_FACTORS_RE.match(factor) - if match: - candidates.append(factor) + match = PY_FACTORS_RE_EXPLICIT_VERSION.match(env_name) + if match: + candidates.append(env_name) + else: + for factor in env_name.split("-"): + match = PY_FACTORS_RE.match(factor) + if match: + candidates.append(factor) if candidates: if len(candidates) > 1: msg = f"conflicting factors {', '.join(candidates)} in {env_name}" diff --git a/tests/tox_env/python/test_python_api.py b/tests/tox_env/python/test_python_api.py index da3628f4c..8690cc838 100644 --- a/tests/tox_env/python/test_python_api.py +++ b/tests/tox_env/python/test_python_api.py @@ -100,6 +100,9 @@ def test_diff_msg_no_diff() -> None: ("5", None), ("2000", None), ("4000", None), + ("3.10", "3.10"), + ("3.9", "3.9"), + ("2.7", "2.7"), ], ids=lambda a: "|".join(a) if isinstance(a, list) else str(a), )