Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronize via a local pre-commit hook #19

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml

This file was deleted.

90 changes: 90 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# This file contains all the hooks that precommend would ever recommend to users.
# They are kept in this file in order to allow pre-commit CI to update them on a
# regular basis. If you want to add a new hook, add it here and then add a corresponding
# inclusion rule in rules.py. Note that YAML parsing with comment preservation is
# a fickle issue: Only end-of-line comments are safe to use with our toolchain.

repos:
- repo: local
hooks:
- id: synchronize-files
name: Synchronize files within the repository
entry: python sync.py
language: system
always_run: true
pass_filenames: false

- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black # Run Black - the uncompromising Python code formatter
- id: black-jupyter # Run Black - the uncompromising Python code formatter (Jupyter version)

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: end-of-file-fixer # Ensure existence of newline characters at file ends
- id: check-yaml # Make sure that contained YAML files are well-formed
- id: trailing-whitespace # Trim trailing whitespace of all sorts
- id: check-added-large-files # Apply a file size limit of 500kB
- id: check-toml # Simple parser validation of e.g. pyproject.toml
- id: requirements-txt-fixer # Sort lines in requirements files
- id: check-json # Check validity of JSON files
- id: pretty-format-json # Format JSON files consistently
exclude_types:
- jupyter
args:
- --autofix
- id: mixed-line-ending # Ensure consistent line endings

- repo: https://github.com/rhysd/actionlint
rev: v1.6.27
hooks:
- id: actionlint # GitHub Actions Workflow linter

- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
hooks:
- id: nbstripout # Make sure that Jupyter notebooks under version control have their outputs stripped before committing
files: ".ipynb"

- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format # Apply formatting to CMake files
additional_dependencies:
- pyyaml
- id: cmake-lint # Apply linting to CMake files

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.1
hooks:
- id: clang-format # Format C++ code with Clang-Format - automatically applying the changes
args:
- --style=Mozilla

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
hooks:
- id: setup-cfg-fmt # Automatically format/sanitize setup.cfg

- repo: https://github.com/citation-file-format/cffconvert
rev: main
hooks:
- id: validate-cff # Validate CFF format

- repo: https://github.com/lovesegfault/beautysh
rev: v6.2.1
hooks:
- id: beautysh # Beautify Bash scripts

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.16
hooks:
- id: validate-pyproject # Validate the contents of pyproject.toml

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.0
hooks:
- id: check-readthedocs # Validate the given .readthedocs.yml file
- id: check-dependabot # Validate the given dependabot.yml file
9 changes: 9 additions & 0 deletions precommend/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
# a fickle issue: Only end-of-line comments are safe to use with our toolchain.

repos:
- repo: local
hooks:
- id: synchronize-files
name: Synchronize files within the repository
entry: python sync.py
language: system
always_run: true
pass_filenames: false

- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
Expand Down
13 changes: 13 additions & 0 deletions sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import hashlib
import os
import shutil


# Check whether we need to copy the config file
if (
not os.path.exists("precommend/.pre-commit-config.yaml")
or hashlib.md5(open("precommend/.pre-commit-config.yaml", "rb").read()).hexdigest()
!= hashlib.md5(open(".pre-commit-config.yaml", "rb").read()).hexdigest()
):
shutil.copy(".pre-commit-config.yaml", "precommend/.pre-commit-config.yaml")
raise SystemExit(1)