diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 120000 index e3bc62d..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1 +0,0 @@ -precommend/.pre-commit-config.yaml \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4fba0dc --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/precommend/.pre-commit-config.yaml b/precommend/.pre-commit-config.yaml index 6062c33..4fba0dc 100644 --- a/precommend/.pre-commit-config.yaml +++ b/precommend/.pre-commit-config.yaml @@ -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: diff --git a/sync.py b/sync.py new file mode 100644 index 0000000..4b18cc1 --- /dev/null +++ b/sync.py @@ -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)