Skip to content

Commit

Permalink
DX: highlight .constraints/py*.txt as pip requirements (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer authored Aug 6, 2024
1 parent f36c6b2 commit d722bf7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/compwa_policy/check_dev_files/precommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
from ruamel.yaml.scalarstring import DoubleQuotedScalarString

from compwa_policy.errors import PrecommitError
from compwa_policy.utilities import CONFIG_PATH
from compwa_policy.utilities.executor import Executor
from compwa_policy.utilities.precommit.getters import find_repo
from compwa_policy.utilities.precommit.struct import Hook
from compwa_policy.utilities.pyproject import Pyproject, get_constraints_file
from compwa_policy.utilities.python import has_constraint_files
from compwa_policy.utilities.yaml import create_prettier_round_trip_yaml

if TYPE_CHECKING:
Expand Down Expand Up @@ -91,7 +90,7 @@ def _update_precommit_ci_commit_msg(precommit: ModifiablePrecommit) -> None:
precommit_ci = precommit.document.get("ci")
if precommit_ci is None:
return
if __has_constraint_files():
if has_constraint_files():
expected_msg = "MAINT: update pip constraints and pre-commit"
else:
expected_msg = "MAINT: autoupdate pre-commit hooks"
Expand All @@ -103,15 +102,6 @@ def _update_precommit_ci_commit_msg(precommit: ModifiablePrecommit) -> None:
precommit.append_to_changelog(msg)


def __has_constraint_files() -> bool:
if not CONFIG_PATH.pip_constraints.exists():
return False
python_versions = Pyproject.load().get_supported_python_versions()
constraint_files = [get_constraints_file(v) for v in python_versions]
constraint_paths = [Path(path) for path in constraint_files if path is not None]
return any(path.exists() for path in constraint_paths)


def _update_precommit_ci_skip(precommit: ModifiablePrecommit) -> None:
precommit_ci = precommit.document.get("ci")
if precommit_ci is None:
Expand Down
6 changes: 6 additions & 0 deletions src/compwa_policy/check_dev_files/vscode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from compwa_policy.utilities import CONFIG_PATH, vscode
from compwa_policy.utilities.executor import Executor
from compwa_policy.utilities.python import has_constraint_files


def main(has_notebooks: bool) -> None:
Expand Down Expand Up @@ -73,6 +74,11 @@ def _update_settings(has_notebooks: bool) -> None:
if has_notebooks:
do(_update_notebook_settings)
do(_update_pytest_settings)
if has_constraint_files():
do(
vscode.update_settings,
{"files.associations": {"**/.constraints/py*.txt": "pip-requirements"}},
)
if CONFIG_PATH.envrc.exists():
do(vscode.update_settings, {"python.terminal.activateEnvironment": False})

Expand Down
13 changes: 13 additions & 0 deletions src/compwa_policy/utilities/python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from pathlib import Path # noqa: D100

from compwa_policy.utilities import CONFIG_PATH
from compwa_policy.utilities.pyproject import Pyproject, get_constraints_file


def has_constraint_files() -> bool:
if not CONFIG_PATH.pip_constraints.exists():
return False
python_versions = Pyproject.load().get_supported_python_versions()
constraint_files = [get_constraints_file(v) for v in python_versions]
constraint_paths = [Path(path) for path in constraint_files if path is not None]
return any(path.exists() for path in constraint_paths)

0 comments on commit d722bf7

Please sign in to comment.