Skip to content

Commit 52d83df

Browse files
author
Paolo Melchiorre
authored
Fixed #1199 -- Added pre-commit hooks (#1198)
* Added pre-commit with a few hooks * Add pre-commit instructions in README
1 parent 0df6872 commit 52d83df

File tree

8 files changed

+51
-9
lines changed

8 files changed

+51
-9
lines changed

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
exclude: \/migrations\/
2+
default_language_version:
3+
python: python3
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: "v4.3.0"
7+
hooks:
8+
- id: debug-statements
9+
- id: detect-private-key
10+
- id: file-contents-sorter
11+
files: ^(requirements/\w*.txt)$
12+
args: ["--ignore-case", "--unique"]
13+
- id: fix-encoding-pragma
14+
args: ["--remove"]
15+
- repo: https://github.com/pycqa/isort
16+
rev: "5.10.1"
17+
hooks:
18+
- id: isort
19+
- repo: https://github.com/pycqa/flake8
20+
rev: "5.0.4"
21+
hooks:
22+
- id: flake8

README.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,27 @@ Running Locally with Docker
394394

395395
docker-compose exec web tox
396396
docker-compose exec web python -m manage test
397+
398+
Pre-commit checks
399+
-----------------
400+
401+
`pre-commit <https://pre-commit.com>`_ is a framework for managing pre-commit
402+
hooks. These hooks help to identify simple issues before committing code for
403+
review. By checking for these issues before code review it allows the reviewer
404+
to focus on the change itself, and it can also help to reduce the number CI
405+
runs.
406+
407+
To use the tool, first install ``pre-commit`` and then the git hooks::
408+
409+
.. console::
410+
411+
$ python3 -m pip install pre-commit
412+
$ python3 -m pre_commit install
413+
414+
On the first commit ``pre-commit`` will install the hooks, these are
415+
installed in their own environments and will take a short while to
416+
install on the first run. Subsequent checks will be significantly faster.
417+
If the an error is found an appropriate error message will be displayed.
418+
If the error was with ``isort`` then the tool will go ahead and fix them for
419+
you. Review the changes and re-stage for commit if you are happy with
420+
them.

foundation/templatetags/foundation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from decimal import ROUND_HALF_EVEN
22

3-
from django import template
43
import moneyed
5-
from moneyed.localization import _format, format_money, _sign
6-
4+
from django import template
5+
from moneyed.localization import _format, _sign, format_money
76

87
register = template.Library()
98

foundation/urls/meetings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from .. import views
44

5-
65
urlpatterns = [
76
path('',
87
views.MeetingArchiveIndex.as_view(),

requirements/common.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
Django==3.2.15
1+
Babel==2.10.1
22
django-contact-form==1.9
33
django-hosts==5.1
44
django-money==2.1.1
5-
Babel==2.10.1
65
django-push==1.1
76
django-recaptcha==3.0.0
87
django-registration-redux==2.10
8+
Django==3.2.15
99
docutils==0.17.1
1010
feedparser==6.0.8
1111
Jinja2==3.1.2

requirements/dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-r common.txt
2-
2+
pre-commit~=2.20.0
33
transifex-client==0.14.4
44
watchdog==2.1.6

requirements/prod.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
-r common.txt
2-
32
django-pylibmc==0.6.1
43
django-redis-cache==3.0.1
54
pylibmc==1.6.1

requirements/tests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
-r dev.txt
2-
32
coverage==6.3.2
43
requests-mock==1.9.3

0 commit comments

Comments
 (0)