Easily install and update centralized pre-commit hooks and their configuration files in decentralized repositories
Project description
Centralized pre-commit
configuration
Easily install and update centralized pre-commit hooks and their configuration files in decentralized repositories.
To be able to validate and automatically fix commits we're using git hooks.
We're also heavily relying on pre-commit
, which is a framework for managing and
maintaining multi-language pre-commit hooks. Please refer to the
pre-commit documentation here.
Philosophy
In order to be able to install all the tools and linters in a single command with up to
date centralized configurations, we're copying the configurations files of your tools
(.pre-commit-config.yaml
, isort.cfg
, .flake8
, .clang-format
, ...) from an URL to
your local git directory and we then install pre-commit
.
Why not use only pre-commit
by @asotile? Well,
in his words:
pre-commit will not directly support mutability in configuration (this includes referencing a centralized repository). This causes lots of issues with repeatability and maintenance in general. This was an early design decision after seeing the pain caused at scale when a linter changes behaviour and suddenly every repository's master branch is broken.
So if you disagree and want decentralized repository with centralized lint configuration, you need a tool on top of pre-commit to shoot yourself in the foot anyway. Or more realistically to update your configuration files from a central repository from time to time.
More seriously, the alternative is to use all-repos to mass update a bunch of decentralized repositories with a decentralized configuration.
Installation
pip3 install centralized-pre-commit-conf
Usage
See pre-commit-conf --help
for options.
Installing hooks
For example with this config.yaml
in
one of the appropriate search paths:
configuration_files:
- ".pylintrc"
- ".pre-commit-config.yaml"
repository: https://mycompany.net/lint-conf/
branch: master
update_gitignore: True
path: "pre-commit/static/"
gitignore_info_text:
"# Configuration file added automatically by 'centralized-pre-commit-conf'"
pre-commit-conf
would recover the defined configuration files from
https://mycompany.net/lint-conf/master/pre-commit/static/
and update the .gitignore
:
You can set the option system wide in /home/pierre/.config/pre-commit-conf/config.yaml.
✨ Successfully retrieved .pre-commit-config.yaml ✨
✨ Successfully retrieved .pylintrc ✨
✨ Updated .gitignore successfully with {'.pre-commit-config.yaml', '.pylintrc'}. ✨
🎉 2 configuration files recovered and pre-commit installed correctly. 🎉
Here would the content of the .gitignore
:
# Configuration file added automatically by 'centralized-pre-commit-conf'
.pre-commit-config.yaml
.pylintrc
Then with the same configuration, using pre-commit-conf --branch hardcore-pylint-conf
would try to recover the configuration files from
https://mycompany.net/lint-conf/hardcore-pylint-conf/pre-commit/static/
instead.
You can set the option system wide in /home/pierre/.config/pre-commit-conf/config.yaml.
Found existing .pre-commit-config.yaml ⁉️ Use '-f' or '--replace-existing' to force erase.
Found existing .pylintrc ⁉️ Use '-f' or '--replace-existing' to force erase.
All configuration files already existed.
Next commit supposing the .pre-commit-config.yaml
is done correctly your modified
files we be linted with the centralized configuration.
Development / contribution
pip3 install -e ".[test]"
pre-commit-conf
python3 -m pytest --cov centralized_pre_commit_conf
Pull requests are welcome :)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file centralized-pre-commit-conf-0.6.1.tar.gz
.
File metadata
- Download URL: centralized-pre-commit-conf-0.6.1.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33c09f7969da46afa95fdbec043b624abc11e8d9c5673e71af09cffc04bcceb0 |
|
MD5 | 99883b4fee0022cf79eef64a4826beae |
|
BLAKE2b-256 | 76e5c74fc0a68fbb04bc4c0a4ca66afaee73c3f1711f2610e9f95ba4b7d3c73d |
File details
Details for the file centralized_pre_commit_conf-0.6.1-py3-none-any.whl
.
File metadata
- Download URL: centralized_pre_commit_conf-0.6.1-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92bbab345e2c59117ef31861d38b444d4bbc3ea47b7b307cc42323a21017cf6e |
|
MD5 | 08ca2c0eb3d3bd4d729021a35bb4bf9d |
|
BLAKE2b-256 | 99eb3affa3da83ed0d0e9bf9497b0eccaaa417aaca5ccd5e1887469a3f920bce |