Skip to content

Commit

Permalink
ENH: automatically add remove-empty-tag hook (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer authored Aug 6, 2024
1 parent 032f4cd commit 1496e2a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compwa_policy/check_dev_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def main(argv: Sequence[str] | None = None) -> int:
do(remove_deprecated_tools, precommit_config, args.keep_issue_templates)
do(vscode.main, has_notebooks)
do(gitpod.main, args.no_gitpod, dev_python_version)
do(precommit.main, precommit_config)
do(precommit.main, precommit_config, has_notebooks)
do(tox.main, has_notebooks)
return 1 if do.error_messages else 0

Expand Down
21 changes: 20 additions & 1 deletion src/compwa_policy/check_dev_files/precommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.yaml import create_prettier_round_trip_yaml

Expand All @@ -25,12 +26,13 @@
)


def main(precommit: ModifiablePrecommit) -> None:
def main(precommit: ModifiablePrecommit, has_notebooks: bool) -> None:
with Executor() as do:
do(_sort_hooks, precommit)
do(_update_conda_environment, precommit)
do(_update_precommit_ci_commit_msg, precommit)
do(_update_precommit_ci_skip, precommit)
do(_update_policy_hook, precommit, has_notebooks)
do(_update_repo_urls, precommit)


Expand Down Expand Up @@ -68,6 +70,23 @@ def __repo_sort_key(repo: Repo) -> tuple[int, str]:
return 4, hook_id


def _update_policy_hook(precommit: ModifiablePrecommit, has_notebooks: bool) -> None:
if not has_notebooks:
return
repo = precommit.find_repo(r".*/(ComPWA\-)?policy")
if repo is None:
msg = "Could not find ComPWA/policy pre-commit repo"
raise KeyError(msg)
hook_ids = {h["id"] for h in repo["hooks"]}
remove_empty_tags_ids = "remove-empty-tags"
if remove_empty_tags_ids in hook_ids:
return
precommit.update_hook(
repo_url=repo["repo"],
expected_hook=Hook(id=remove_empty_tags_ids),
)


def _update_precommit_ci_commit_msg(precommit: ModifiablePrecommit) -> None:
precommit_ci = precommit.document.get("ci")
if precommit_ci is None:
Expand Down

0 comments on commit 1496e2a

Please sign in to comment.