From 169e6afd1753e2bc2bf1b07acacfe0a665d4267e Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:05:56 +0100 Subject: [PATCH] MAINT: remove `.python-version` if `requires-python` pins (#457) --- src/compwa_policy/check_dev_files/uv.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/compwa_policy/check_dev_files/uv.py b/src/compwa_policy/check_dev_files/uv.py index 5387d5fe..ab61f4a1 100644 --- a/src/compwa_policy/check_dev_files/uv.py +++ b/src/compwa_policy/check_dev_files/uv.py @@ -121,7 +121,17 @@ def _update_editor_config() -> None: def _update_python_version_file(dev_python_version: PythonVersion) -> None: + pyproject = Pyproject.load() python_version_file = Path(".python-version") + if pyproject.has_table("project"): + requires_python = pyproject.get_table("project").get("requires-python", "") + if "==" in requires_python or "~=" in requires_python: + if python_version_file.exists(): + python_version_file.unlink() + msg = f"Removed {python_version_file} file because requires-python already pins the Python version" + raise PrecommitError(msg) + return + existing_python_version = "" if python_version_file.exists(): with open(python_version_file) as stream: