Skip to content

pre-commit hooks: hygiene, the CI's black and flake8, notebooks and metadata - #17

Open
btyrcha wants to merge 3 commits into
mainfrom
feature/pre-commit
Open

btyrcha wants to merge 3 commits into
mainfrom
feature/pre-commit

Conversation

@btyrcha

@btyrcha btyrcha commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

An optional pre-commit configuration for local commits. CI is unchanged, and the hooks run only for those who install them:

pip install pre-commit   # in the prop-sapt environment
pre-commit install

The hooks:

  • General hygiene (pre-commit-hooks): files over 1 MB, merge-conflict markers, YAML and TOML syntax, final newlines, trailing whitespace, leftover breakpoints, private keys and shebangs.
  • no-commit-to-branch: no commits on main, which changes only through pull requests. SKIP=no-commit-to-branch git commit ... allows a deliberate exception.
  • black and flake8, the checks CI runs. black is at 26.10.1, the 26 release CI installs. flake8 uses CI's critical selection (E9,F63,F7,F82).
  • nbstripout: keeps the example notebooks free of outputs and widget state.
  • check-jsonschema: checks the GitHub workflows and CITATION.cff against their schemas. release.yml runs only on a tag push, and GitHub's citation and Zenodo read CITATION.cff, so mistakes in either would otherwise show up at release time.

Left out after reviewing a broader suggested setup:

  • ruff: its formatter differs from black, which CI checks.
  • mypy: Psi4 can't be installed into its environment.
  • pytest on push: the suite runs real Psi4 calculations (the CI job takes about 14 minutes) and needs the conda environment. CI already runs it.
  • shellcheck: the repository has no shell scripts.
  • Two custom guard scripts, for new dependencies and for weakened tests. They missed most of this repository's cases, such as changes to prop-sapt.yaml or to tolerance constants.
  • gitleaks (left commented out): GitHub's secret scanning and push protection are on for the repository, and detect-private-key covers private keys.

The first run over the existing files is included: a final newline in LICENSE, and three blank lines in docs/usage.rst that held only spaces. pre-commit run --all-files passes on this branch.

Not in this PR: CONTRIBUTING.md doesn't mention pre-commit yet.

Tested on a clone with pre-commit 4.7.0:

  • The configuration validates.
  • On this branch every hook passes over all files.
  • no-commit-to-branch fails on main and passes on a feature branch.
  • Each hook caught the error planted for it:
    • an undefined name (flake8);
    • unformatted code (black);
    • a misspelled runs-on in release.yml;
    • a misspelled cff-version in CITATION.cff.

🤖 Generated with Claude Code

btyrcha and others added 3 commits December 2, 2026 17:33
…etadata

An optional .pre-commit-config.yaml for local commits; CI is unchanged. black and
flake8 run the checks CI runs: black at the 26 release CI installs, flake8 stopping only
on CI's critical errors. The general hooks catch large files, merge-conflict markers,
broken YAML and TOML, missing final newlines, trailing whitespace, leftover breakpoints
and private keys.

no-commit-to-branch keeps commits off main, which changes only through pull requests.
nbstripout keeps the example notebooks free of outputs and widget state.
check-jsonschema validates the GitHub workflows, as release.yml runs only on a tag push,
and CITATION.cff, which GitHub's citation and Zenodo read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…docs/usage.rst

The fixes of end-of-file-fixer and trailing-whitespace, the only hooks that failed on
the existing files. Three blank lines in the usage guide held only spaces; the rendered
docs are unchanged. pre-commit run --all-files now passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@btyrcha btyrcha assigned Copilot and unassigned Copilot Dec 2, 2026
@btyrcha
btyrcha marked this pull request as draft December 2, 2026 18:24
@btyrcha
btyrcha marked this pull request as ready for review December 2, 2026 18:24
@btyrcha btyrcha closed this Dec 2, 2026
@btyrcha btyrcha reopened this Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants