Skip to content

Commit

Permalink
ENH: check contents of .constraints directory (#305)
Browse files Browse the repository at this point in the history
* MAINT: use `CONFIG_PATH` for constraints directory name
  • Loading branch information
redeboer authored Mar 7, 2024
1 parent ba5fcb9 commit 7fd733b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/compwa_policy/check_dev_files/precommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions src/compwa_policy/utilities/project_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import os
import sys
from pathlib import Path
from textwrap import dedent
from typing import TYPE_CHECKING

Expand All @@ -18,6 +17,7 @@

if TYPE_CHECKING:
from configparser import ConfigParser
from pathlib import Path

from tomlkit import TOMLDocument

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7fd733b

Please sign in to comment.