check-dev-files#

This hook is responsible for standardizing and synchronizing the developer environment of repositories by the ComPWA organization. Coding conventions are enforced through automated checks instead of through a contribution guide. These conventions have to be regularly updated across all repositories as developer tools introduce new features and deprecate old ones.

The check-dev-files hook can also be used as a cookie cutter for new repositories by adding the following to your .pre-commit-config.yaml file:

repos:
  - repo: https://github.com/ComPWA/policy
    rev: ""
    hooks:
      - id: check-dev-files
        args:
          - --repo-name="short name for your repository"

and running

pre-commit autoupdate --repo=https://github.com/ComPWA/policy
pre-commit run check-dev-files -a

For more implementation details of this hook, check the compwa_policy.cli module.

Command-line interface#

The checks are also exposed through a short Typer-based policy command. Running policy without a subcommand runs every check at once, which is exactly what the check-dev-files pre-commit hook does. The subcommands group the checks by domain, so you can run just a subset.

You do not need to install anything: with uv, uvx fetches and runs the command on the fly. For example, to see which subcommands are available:

uvx --from git+https://github.com/ComPWA/policy policy --help

Tip

uvx caches the Git checkout, so add --refresh directly after uvx to pull the latest commit from the default branch.

If you run the command often, you can install it as a persistent tool with uv tool install (or pipx install) and call policy directly, updating it with uv tool upgrade --reinstall compwa-policy. When the pwa command is installed alongside this package, the same command is also available as pwa policy ... through a pwa.commands entry point.

Hook arguments#

The check-dev-files hook (and the policy command without a subcommand) only accepts the options that are shared across the whole repository, such as --repo-name. These can be added to the args key in your .pre-commit-config.yaml file. Options scoped to a single area (e.g. --no-pypi) are exposed on the matching subcommand instead and are configured through its [tool.compwa.policy.<group>] table (see below). The full command tree and its options are:

policy Usage: policy [OPTIONS] COMMAND [ARGS]... Standardize and synchronize the developer setup of a ComPWA repository. ╭─ Options ────────────────────────────────────────────────────────────────────╮ --python--no-pythonSpecify whether     this repository     contains Python     code (default:      automatic           detection).         --dev-python-versi…[3.6|3.7|3.8|3.9|Specify the Python  3.10|3.11|3.12|3.version for your    13|3.14]developer           environment.        [default: (3.13)]   --package-manager[none|uv|conda|piSpecify which       xi+uv|pixi|venv]package manager to  use for the         project.            [default: (uv)]     --repo-nameTEXT             Name of the         repository. This    can usually be      found in the URL of the repository on   GitHub or GitLab.   --repo-organizationTEXT             Name of the         organization under  which the           repository lives.   [default: (ComPWA)] --repo-titleTEXT             Title or full name  of the repository.  If not provided,    this falls back to  the repo-name.      --no-ruffDo not enforce Ruff as a linter.        --pytest-single-th…Run pytest without  the `-n` argument.  --doc-apt-packagesTEXT             Comma- or           space-separated     list of APT         packages that are   required to build   documentation.      --install-completi…Install completion  for the current     shell.              --show-completionShow completion for the current shell,  to copy it or       customize the       installation.       --helpShow this message   and exit.           ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ───────────────────────────────────────────────────────────────────╮ python Standardize Python tooling: pyproject, Ruff, Black, mypy, pyright,  ty, pytest, pyupgrade.                                              github Standardize GitHub config: workflows, labels, Dependabot, Release   Drafter, lock upgrades.                                             env    Standardize the developer environment: uv, Conda, Pixi, direnv.     nb     Standardize Jupyter notebook config: Jupyter, nbstripout, Binder.   format Standardize formatters and linters: Prettier, TOML, cSpell,         EditorConfig, pre-commit.                                           repo   Standardize miscellaneous repo files: citation, commitlint, VS      Code, GitPod, Poe, Read the Docs.                                   migrateMigrate hook args into a pyproject.toml policy table and relocate   nb hooks.                                                           ╰──────────────────────────────────────────────────────────────────────────────╯
python Usage: policy python [OPTIONS] Standardize Python tooling: pyproject, Ruff, Black, mypy, pyright, ty, pytest, pyupgrade. ╭─ Options ────────────────────────────────────────────────────────────────────╮ --python--no-pythonSpecify whether   this repository   contains Python   code (default:    automatic         detection).       --dev-python-ver…[3.6|3.7|3.8|3.9Specify the       |3.10|3.11|3.12|Python version    3.13|3.14]for your          developer         environment.      [default: (3.13)] --excluded-pytho…TEXT            Comma- or         space-separated   list of Python    versions you do   NOT want to       support.          --type-checker[mypy|pyright|tySpecify which     ]type checker to   use for the       project.          --no-ruffDo not enforce    Ruff as a linter. --imports-on-topSort notebook     imports on the    top.              --branch-coverage--no-branch-cov…Enable branch     coverage in the   Coverage.py       pytest            configuration.    --keep-local-pre…Do not remove     local pre-commit  hooks.            --pytest-single-…Run pytest        without the `-n argument.         --allow-vscode-c…Recommend the     ryanluker.vscode… extension and     keep its          settings, instead of marking it as  an unwanted VS    Code extension.   --helpShow this message and exit.         ╰──────────────────────────────────────────────────────────────────────────────╯
github Usage: policy github [OPTIONS] Standardize GitHub config: workflows, labels, Dependabot, Release Drafter,  lock upgrades. ╭─ Options ────────────────────────────────────────────────────────────────────╮ --python--no-pythonSpecify whether     this repository     contains Python     code (default:      automatic           detection).         --dev-python-versi…[3.6|3.7|3.8|3.9|Specify the Python  3.10|3.11|3.12|3.version for your    13|3.14]developer           environment.        [default: (3.13)]   --allow-labelsDo not perform the  check on            labels.toml.        --no-github-actionsDo not add standard GitHub Actions      workflows that are  used across ComPWA  repositories. This  can be useful if    you already have    your own CI         workflows that do   the same as the     workflows enforced  by the              check-dev-files     hook.               --allow-deprecated…Allow deprecated CI workflows, such as  ci-docs.yml.        --github-pagesHost documentation  on GitHub Pages.    --keep-pr-lintingDo not overwrite    the PR linting      workflow.           --macos-python-ver…TEXT             Run the test job in MacOS on a specific Python version. Use 'disable' to not    run the tests on    MacOS.              [default: (3.10)]   --no-cdDo not add any      GitHub workflows    for continuous      deployment.         --no-milestonesThis repository     does not use        milestones and      therefore no close  workflow.           --no-pypiDo not publish      package to PyPI.    --no-version-branc…Do not push to      matching            major/minor version branches upon       tagging.            --ci-skipped-testsTEXT             Avoid running CI    test on the         following Python    versions.           --doc-apt-packagesTEXT             Comma- or           space-separated     list of APT         packages that are   required to build   documentation.      --environment-vari…TEXT             Comma- or           space-separated     list of environment variables, e.g.     PYTHONHASHSEED=0,S… --pytest-single-th…Run pytest without  the `-n` argument.  --keep-workflowTEXT             Names of the GitHub Actions workflows   that should not be  updated or removed, including the .yml  extension.          --upgrade-frequency[monthly|quarterlAdd a workflow to   y|semiannually]upgrade lock files, like uv.lock,       .pre-commit-config… and pip             .constraints/       files. The argument is the frequency of the cron job.       [default:           (quarterly)]        --repo-nameTEXT             Name of the         repository. This    can usually be      found in the URL of the repository on   GitHub or GitLab.   --repo-organizationTEXT             Name of the         organization under  which the           repository lives.   [default: (ComPWA)] --repo-titleTEXT             Title or full name  of the repository.  If not provided,    this falls back to  the repo-name.      --helpShow this message   and exit.           ╰──────────────────────────────────────────────────────────────────────────────╯
env Usage: policy env [OPTIONS] Standardize the developer environment: uv, Conda, Pixi, direnv. ╭─ Options ────────────────────────────────────────────────────────────────────╮ --python--no-pythonSpecify whether    this repository    contains Python    code (default:     automatic          detection).        --dev-python-versi…[3.6|3.7|3.8|3.9|3Specify the Python .10|3.11|3.12|3.13version for your   |3.14]developer          environment.       [default: (3.13)]  --package-manager[none|uv|conda|pixSpecify which      i+uv|pixi|venv]package manager to use for the        project.           [default: (uv)]    --environment-vari…TEXT              Comma- or          space-separated    list of            environment        variables, e.g.    PYTHONHASHSEED=0,… --keep-contributin…Do not update or   remove the         CONTRIBUTING.md    file.              --repo-nameTEXT              Name of the        repository. This   can usually be     found in the URL   of the repository  on GitHub or       GitLab.            --repo-organizationTEXT              Name of the        organization under which the          repository lives.  [default:          (ComPWA)]          --helpShow this message  and exit.          ╰──────────────────────────────────────────────────────────────────────────────╯
nb Usage: policy nb [OPTIONS] Standardize Jupyter notebook config: Jupyter, nbstripout, Binder. ╭─ Options ────────────────────────────────────────────────────────────────────╮ --package-manager[none|uv|conda|pixi+uvSpecify which package  |pixi|venv]manager to use for the project.               [default: (uv)]        --dev-python-version[3.6|3.7|3.8|3.9|3.10|Specify the Python     3.11|3.12|3.13|3.14]version for your       developer environment. [default: (3.13)]      --no-binderDo not update the      Binder configuration.  --no-ruffDo not enforce Ruff as a linter.              --allowed-cell-metada…TEXT                  Comma-separated list   of allowed metadata in Jupyter notebook       cells, e.g.            editable,slideshow.    --doc-apt-packagesTEXT                  Comma- or              space-separated list   of APT packages that   are required to build  documentation.         --helpShow this message and  exit.                  ╰──────────────────────────────────────────────────────────────────────────────╯
format Usage: policy format [OPTIONS] Standardize formatters and linters: Prettier, TOML, cSpell, EditorConfig,  pre-commit. ╭─ Options ────────────────────────────────────────────────────────────────────╮ --no-cspell-updateDo not enforce same cSpell configuration as      other ComPWA repositories. This can be useful if you have a more advanced configuration, like     using different dictionaries for different file  types.                                           --helpShow this message and exit. ╰──────────────────────────────────────────────────────────────────────────────╯
repo Usage: policy repo [OPTIONS] Standardize miscellaneous repo files: citation, commitlint, VS Code, GitPod,  Poe, Read the Docs. ╭─ Options ────────────────────────────────────────────────────────────────────╮ --python--no-pythonSpecify whether     this repository     contains Python     code (default:      automatic           detection).         --package-manager[none|uv|conda|piSpecify which       xi+uv|pixi|venv]package manager to  use for the         project.            [default: (uv)]     --dev-python-versi…[3.6|3.7|3.8|3.9|Specify the Python  3.10|3.11|3.12|3.version for your    13|3.14]developer           environment.        [default: (3.13)]   --gitpodCreate a GitPod     config file.        --keep-issue-templ…Do not remove the   .github/ISSUE_TEMP… directory.          --helpShow this message   and exit.           ╰──────────────────────────────────────────────────────────────────────────────╯
migrate Usage: policy migrate [OPTIONS] [CONFIG_FILE] Migrate hook args into a pyproject.toml policy table and relocate nb hooks. ╭─ Arguments ──────────────────────────────────────────────────────────────────╮ config_file[CONFIG_FILE]Path to the .pre-commit-config.yaml file   to migrate.                                [default: .pre-commit-config.yaml]         ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Options ────────────────────────────────────────────────────────────────────╮ --dry-runOnly report the migration; do not modify any files. --helpShow this message and exit. ╰──────────────────────────────────────────────────────────────────────────────╯

Configuration in pyproject.toml#

Instead of repeating the same flags under args: in every .pre-commit-config.yaml, a repository can declare its options once in a [tool.compwa.policy] table in its pyproject.toml. Each option is resolved with the following precedence (first match wins):

  1. the option explicitly passed on the command line (e.g. under args:);

  2. the [tool.compwa.policy] table in pyproject.toml;

  3. the built-in default.

The table is organized hierarchically, mirroring the subcommand tree: options shared by several checks live in the top-level table, while options that belong to a single subcommand live in a sub-table named after it. The env subcommand maps to a setup table, and environment variables are a plain nested table under [tool.compwa.policy.setup.env]:

[tool.compwa.policy]
# options shared by several checks
dev-python-version = "3.13"
package-manager = "pixi"

[tool.compwa.policy.python]
imports-on-top = true
type-checker = ["mypy", "pyright"]

[tool.compwa.policy.nb]
no-binder = true
allowed-cell-metadata = ["scrolled"]

# options of the `env` subcommand (uv, conda, pixi, direnv)
[tool.compwa.policy.setup]
keep-contributing-md = true

# environment variables, as a plain TOML table
[tool.compwa.policy.setup.env]
PYTHONHASHSEED = "0"

[tool.compwa.policy.repo]
gitpod = true

Both the native TOML form (arrays, tables, booleans) and the legacy command-line string form ("mypy,pyright", "A=1,B=2") are accepted, so an existing args: list can be moved into pyproject.toml verbatim.

Migrating after breaking changes#

Some policy updates introduce breaking changes to a repository’s configuration. The check-dev-files pre-commit hook cannot rewrite your files to apply such a change itself — it can only detect it and fail. The policy migrate command applies these migrations for you, but because it modifies configuration files it has to be run outside of pre-commit, as a one-off command.

Important

If the check-dev-files hook starts failing after an upgrade, run policy migrate to bring your configuration up to date. You do not need to install anything first:

uvx --from git+https://github.com/ComPWA/policy --refresh policy migrate

To preview the changes without writing any files, add --dry-run:

uvx --from git+https://github.com/ComPWA/policy --refresh policy migrate --dry-run

If you already installed the policy command, you can drop the uvx --from git+https://github.com/ComPWA/policy prefix and simply run policy migrate.