Skip to content

Commit

Permalink
ENH: rename mirrors-taplo repo to taplo-pre-commit (#383)
Browse files Browse the repository at this point in the history
* FIX: list `taplo-format` as hook
* MAINT: autoupdate pre-commit config
  • Loading branch information
redeboer authored Sep 5, 2024
1 parent 0821a86 commit ca21862
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 26 deletions.
16 changes: 7 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ ci:
skip:
- check-dev-files
- mypy
- prettier
- pyright
- self-check
- taplo

repos:
- repo: meta
Expand All @@ -16,7 +14,7 @@ repos:
- id: check-useless-excludes

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.5
rev: v0.6.3
hooks:
- id: ruff
args: [--fix]
Expand Down Expand Up @@ -70,10 +68,10 @@ repos:
hooks:
- id: prettier

- repo: https://github.com/ComPWA/mirrors-taplo
rev: v0.8.1
- repo: https://github.com/ComPWA/taplo-pre-commit
rev: v0.9.3
hooks:
- id: taplo
- id: taplo-format

- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
Expand All @@ -83,12 +81,12 @@ repos:
exclude: (?x)^(labels/.*\.toml)$

- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.13.0
rev: v8.13.3
hooks:
- id: cspell

- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 2.7.3
rev: 3.0.3
hooks:
- id: editorconfig-checker
name: editorconfig
Expand All @@ -109,6 +107,6 @@ repos:
- python

- repo: https://github.com/ComPWA/mirrors-pyright
rev: v1.1.374
rev: v1.1.379
hooks:
- id: pyright
7 changes: 6 additions & 1 deletion src/compwa_policy/.template/.cspell.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"version": "0.2",
"enableFiletypes": ["git-commit", "github-actions-workflow", "julia", "jupyter"],
"enableFiletypes": [
"git-commit",
"github-actions-workflow",
"julia",
"jupyter"
],
"flagWords": [
"analyse",
"colour",
Expand Down
19 changes: 7 additions & 12 deletions src/compwa_policy/check_dev_files/precommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __repo_sort_key(repo: Repo) -> tuple[int, str]:
"isort",
"prettier",
"taplo",
"taplo-format",
"toml-sort",
}
if hook_id in formatter_hooks:
Expand Down Expand Up @@ -129,12 +130,17 @@ def get_local_hooks(config: PrecommitConfig) -> list[str]:


def get_non_functional_hooks(config: PrecommitConfig) -> list[str]:
skipped_hooks = {
"check-jsonschema",
"pyright",
"taplo",
}
return [
hook["id"]
for repo in config["repos"]
for hook in repo["hooks"]
if repo["repo"]
if hook["id"] in __get_skipped_hooks(config)
if hook["id"] in skipped_hooks
]


Expand Down Expand Up @@ -166,17 +172,6 @@ def _update_conda_environment(precommit: Precommit) -> None:
raise PrecommitError(msg)


def __get_skipped_hooks(config: PrecommitConfig) -> set[str]:
skipped_hooks = {
"check-jsonschema",
"pyright",
"taplo",
}
if __has_prettier_v4alpha(config):
skipped_hooks.add("prettier")
return skipped_hooks


def __has_prettier_v4alpha(config: PrecommitConfig) -> bool:
repo = find_repo(config, search_pattern=r"^.*/mirrors-prettier$")
if repo is None:
Expand Down
26 changes: 24 additions & 2 deletions src/compwa_policy/check_dev_files/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def main(precommit: ModifiablePrecommit) -> None:
with Executor() as do:
do(_rename_taplo_config)
do(_update_taplo_config)
do(_rename_precommit_url, precommit)
do(_update_precommit_repo, precommit)
do(_update_tomlsort_config)
do(_update_tomlsort_hook, precommit)
Expand Down Expand Up @@ -121,11 +122,32 @@ def _update_taplo_config() -> None:
raise PrecommitError(msg)


def _rename_precommit_url(precommit: ModifiablePrecommit) -> None:
mirrors_repo_with_idx = precommit.find_repo_with_index(r"^.*/mirrors-taplo$")
rev = ""
if mirrors_repo_with_idx is not None:
idx, repo = mirrors_repo_with_idx
rev = repo["rev"]
precommit.document["repos"].pop(idx)
precommit.changelog.append("Renamed mirrors-taplo repo to taplo-pre-commit")
expected_hook = Repo(
repo="https://github.com/ComPWA/taplo-pre-commit",
rev=rev,
hooks=[Hook(id="taplo-format")],
)
precommit.update_single_hook_repo(expected_hook)


def _update_precommit_repo(precommit: ModifiablePrecommit) -> None:
mirrors_repo_with_idx = precommit.find_repo_with_index(r"^.*/mirrors-taplo$")
if mirrors_repo_with_idx is not None:
idx, _ = mirrors_repo_with_idx
precommit.document["repos"].pop(idx)
precommit.changelog.append("Renamed mirrors-taplo repo to taplo-pre-commit")
expected_hook = Repo(
repo="https://github.com/ComPWA/mirrors-taplo",
repo="https://github.com/ComPWA/taplo-pre-commit",
rev="",
hooks=[Hook(id="taplo")],
hooks=[Hook(id="taplo-format")],
)
precommit.update_single_hook_repo(expected_hook)

Expand Down
2 changes: 1 addition & 1 deletion src/compwa_policy/set_nb_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _insert_autolink_concat(filename: str) -> None:
return
new_cell = nbformat.v4.new_markdown_cell(expected_cell_content)
del new_cell["id"] # following nbformat_minor = 4
notebook["cells"].insert(cell_id, new_cell) # noqa: B909
notebook["cells"].insert(cell_id, new_cell)
nbformat.validate(notebook)
nbformat.write(notebook, filename)
return
Expand Down
2 changes: 1 addition & 1 deletion src/compwa_policy/utilities/precommit/struct.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa: D100
# noqa: A005, D100
from __future__ import annotations

import sys
Expand Down
1 change: 1 addition & 0 deletions src/compwa_policy/utilities/pyproject/_struct.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# noqa: A005
"""This module is hidden Sphinx can't handle `typing.TypedDict` with hyphens.
See https://github.com/sphinx-doc/sphinx/issues/11039.
Expand Down

0 comments on commit ca21862

Please sign in to comment.