diff --git a/src/compwa_policy/check_dev_files/precommit.py b/src/compwa_policy/check_dev_files/precommit.py index 2f097751..25dddb8d 100644 --- a/src/compwa_policy/check_dev_files/precommit.py +++ b/src/compwa_policy/check_dev_files/precommit.py @@ -19,6 +19,7 @@ load_precommit_config, load_roundtrip_precommit_config, ) +from compwa_policy.utilities.project_info import get_supported_python_versions from compwa_policy.utilities.yaml import create_prettier_round_trip_yaml @@ -77,7 +78,7 @@ def _update_precommit_ci_commit_msg() -> None: precommit_ci = config.get("ci") if precommit_ci is None: return - if CONFIG_PATH.pip_constraints.exists(): + if __has_constraint_files(): expected_msg = "MAINT: update pip constraints and pre-commit" else: expected_msg = "MAINT: autoupdate pre-commit hooks" @@ -90,6 +91,13 @@ def _update_precommit_ci_commit_msg() -> None: raise PrecommitError(msg) +def __has_constraint_files() -> bool: + python_versions = get_supported_python_versions() + return any( + (CONFIG_PATH.pip_constraints / f"py{v}.txt").exists() for v in python_versions + ) + + def _update_precommit_ci_skip() -> None: config, yaml = load_roundtrip_precommit_config() precommit_ci = config.get("ci") diff --git a/src/compwa_policy/utilities/project_info.py b/src/compwa_policy/utilities/project_info.py index ee07589c..f27ed460 100644 --- a/src/compwa_policy/utilities/project_info.py +++ b/src/compwa_policy/utilities/project_info.py @@ -4,7 +4,6 @@ import os import sys -from pathlib import Path from textwrap import dedent from typing import TYPE_CHECKING @@ -18,6 +17,7 @@ if TYPE_CHECKING: from configparser import ConfigParser + from pathlib import Path from tomlkit import TOMLDocument @@ -172,7 +172,7 @@ def open_setup_cfg() -> ConfigParser: def get_constraints_file(python_version: PythonVersion) -> Path | None: - path = Path(f".constraints/py{python_version}.txt") + path = CONFIG_PATH.pip_constraints / f"py{python_version}.txt" if path.exists(): return path return None