Skip to content

Commit

Permalink
Add pre-commit autoupdate check
Browse files Browse the repository at this point in the history
- Added a check in tox that warns if the pre-commit
hook versions need updating.
- Added this check as a pre-commit hook.
- Removed `pre-commit autoupdate` from the Makefile
since it's redundant
  • Loading branch information
KAUTH committed Apr 10, 2024
1 parent 609b84a commit 2449d80
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ repos:
files: ''
pass_filenames: false
verbose: true
- id: tox-precommit
name: run pre-commit version check from tox
description: Checks if `pre-commit autoupdate` is up-to-date
entry: tox -e precommit
language: system
pass_filenames: false
verbose: true
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ requirements:

precommit:
pre-commit install
pre-commit autoupdate
pre-commit run --all-files --show-diff-on-failure

coverage:
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ To automatically run checks before you commit your changes you should run:
$ make precommit
This will install the git hook scripts for the first time, it will update to the
latest versions of the hooks and run the pre-commit tool.
This will install the git hook scripts for the first time and run the
``pre-commit`` tool.
Now ``pre-commit`` will run automatically on ``git commit``.


Expand Down
21 changes: 18 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py310,py311,requirements,lint,test,test-docs
envlist = py310,py311,requirements,precommit,lint,test,test-docs

[testenv]
setenv =
Expand Down Expand Up @@ -66,7 +66,22 @@ commands =
bash -c 'diff -w requirements.txt <(pipenv requirements)'
bash -c 'diff -w requirements-dev.txt <(pipenv requirements --dev)'

[testenv:precommit]
description="Check if `pre-commit autoupdate` is up-to-date."
deps = pre-commit
skipsdist=false
allowlist_externals =
bash
commands =
pre-commit --version
bash -c 'cp .pre-commit-config.yaml tmp-tox-precommit.yaml'
bash -c 'pre-commit autoupdate'
bash -c 'if ! diff -w .pre-commit-config.yaml tmp-tox-precommit.yaml; \
then echo "⚠️ [WARNING] pre-commit hooks are outdated"; fi'
bash -c 'cp tmp-tox-precommit.yaml .pre-commit-config.yaml'
bash -c 'rm tmp-tox-precommit.yaml'

[gh-actions]
python =
3.10: py310,pep8,lint,requirements,test,test-docs
3.11: py311,pep8,lint,requirements,test,test-docs
3.10: py310,pep8,lint,requirements,precommit,test,test-docs
3.11: py311,pep8,lint,requirements,precommit,test,test-docs

0 comments on commit 2449d80

Please sign in to comment.