Skip to content

Commit 2538a00

Browse files
authored
Setup pre-commit (#276)
* Setup pre-commit * Add build to requirements
1 parent 09189ad commit 2538a00

File tree

15 files changed

+238
-181
lines changed

15 files changed

+238
-181
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020

2121
<!-- Describe the environment you have that lead to your issue.
2222
This includes the frozenlist version, OS, proxy server and other
23-
relevant software that is related to your case.
23+
relevant software that is related to your case.
2424
-->

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
- [ ] Documentation reflects the changes
2020
- [ ] If you provide code modifications, please add yourself to `CONTRIBUTORS.txt`
2121
* The format is &lt;Name&gt; &lt;Surname&gt;.
22-
* Please keep the list in alphabetical order, the file is sorted by name.
22+
* Please keep the list in alphabetical order, the file is sorted by name.
2323
- [ ] Add a new news fragment into the `CHANGES` folder
2424
* name it `<issue_id>.<type>` for example (588.bugfix)
2525
* if you don't have an `issue_id` change it to the pr id after creating the pr

.github/workflows/ci.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,9 @@ jobs:
4040
pip install .
4141
env:
4242
FROZENLIST_NO_EXTENSIONS: 1
43-
- name: Run flake8
43+
- name: Run linters
4444
run: |
45-
make flake8
46-
- name: Run isort-check
47-
run: |
48-
make isort-check
49-
- name: Run mypy checker
50-
run: |
51-
make mypy
45+
make lint
5246
- name: Install spell checker
5347
run: |
5448
sudo apt install libenchant-dev
@@ -60,7 +54,7 @@ jobs:
6054
- name: Prepare twine checker
6155
run: |
6256
pip install -U twine wheel
63-
python setup.py sdist bdist_wheel
57+
python -m build
6458
env:
6559
FROZENLIST_NO_EXTENSIONS: 1
6660
- name: Run twine checker
@@ -170,7 +164,7 @@ jobs:
170164
make cythonize
171165
- name: Make sdist
172166
run:
173-
python setup.py sdist
167+
python -m build --sdist
174168
- name: Upload artifacts
175169
uses: actions/upload-artifact@v2
176170
with:

.pre-commit-config.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: check-changes
5+
name: Check CHANGES
6+
language: system
7+
entry: ./tools/check_changes.py
8+
pass_filenames: false
9+
- repo: https://github.com/pre-commit/pre-commit-hooks
10+
rev: 'v4.1.0'
11+
hooks:
12+
- id: check-merge-conflict
13+
- repo: https://github.com/asottile/yesqa
14+
rev: v1.3.0
15+
hooks:
16+
- id: yesqa
17+
- repo: https://github.com/PyCQA/isort
18+
rev: '5.10.1'
19+
hooks:
20+
- id: isort
21+
- repo: https://github.com/psf/black
22+
rev: '21.12b0'
23+
hooks:
24+
- id: black
25+
language_version: python3 # Should be a command that runs python3.6+
26+
- repo: https://github.com/pre-commit/pre-commit-hooks
27+
rev: 'v4.1.0'
28+
hooks:
29+
- id: end-of-file-fixer
30+
exclude: >-
31+
^docs/[^/]*\.svg$
32+
- id: requirements-txt-fixer
33+
exclude: >-
34+
^requirements/constraints[.]txt$
35+
- id: trailing-whitespace
36+
- id: file-contents-sorter
37+
args: ['--ignore-case']
38+
files: |
39+
CONTRIBUTORS.txt|
40+
docs/spelling_wordlist.txt|
41+
.gitignore|
42+
.gitattributes
43+
- id: check-case-conflict
44+
- id: check-json
45+
- id: check-xml
46+
- id: check-executables-have-shebangs
47+
- id: check-toml
48+
- id: check-yaml
49+
- id: debug-statements
50+
- id: check-added-large-files
51+
- id: check-symlinks
52+
- id: fix-byte-order-marker
53+
- id: fix-encoding-pragma
54+
args: ['--remove']
55+
- id: detect-aws-credentials
56+
args: ['--allow-missing-credentials']
57+
- id: detect-private-key
58+
exclude: ^examples/
59+
- repo: https://github.com/asottile/pyupgrade
60+
rev: 'v2.31.0'
61+
hooks:
62+
- id: pyupgrade
63+
args: ['--py36-plus']
64+
- repo: https://github.com/PyCQA/flake8
65+
rev: '4.0.1'
66+
hooks:
67+
- id: flake8
68+
exclude: "^docs/"
69+
- repo: git://github.com/Lucas-C/pre-commit-hooks-markup
70+
rev: v1.0.1
71+
hooks:
72+
- id: rst-linter
73+
files: >-
74+
^[^/]+[.]rst$
75+
exclude: >-
76+
^CHANGES\.rst$
77+
- repo: https://github.com/rhysd/actionlint
78+
rev: v1.6.8
79+
hooks:
80+
- id: actionlint-docker
81+
args:
82+
- -ignore
83+
- 'SC2155:'
84+
- -ignore
85+
- 'SC2157:'
86+
- -ignore
87+
- 'SC2086:'
88+
- -ignore
89+
- 'SC1004:'
90+
- repo: https://github.com/sirosen/check-jsonschema
91+
rev: 0.10.0
92+
hooks:
93+
- id: check-github-actions
94+
ci:
95+
skip:
96+
- actionlint-docker
97+
- check-github-actions
98+
- check-changes

Makefile

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,16 @@ cythonize: .install-cython $(PYXS:.pyx=.c)
1616

1717
.install-deps: cythonize $(shell find requirements -type f)
1818
pip install -r requirements/ci.txt
19+
pre-commit install
1920
@touch .install-deps
2021

21-
lint: flake isort-check flake8
22-
23-
isort:
24-
isort $(SRC)
25-
26-
flake: .flake
27-
28-
.flake: .install-deps $(shell find frozenlist -type f) \
29-
$(shell find tests -type f)
30-
flake8 frozenlist tests
31-
python setup.py sdist bdist_wheel
32-
twine check dist/*
33-
@if ! isort -c frozenlist tests; then \
34-
echo "Import sort errors, run 'make isort' to fix them!"; \
35-
isort --diff frozenlist tests; \
36-
false; \
37-
fi
38-
@if ! LC_ALL=C sort -c CONTRIBUTORS.txt; then \
39-
echo "CONTRIBUTORS.txt sort error"; \
40-
fi
41-
@touch .flake
42-
43-
flake8:
44-
flake8 $(SRC)
45-
46-
mypy: .flake
47-
mypy frozenlist
48-
49-
isort-check:
50-
@if ! isort --check-only $(SRC); then \
51-
echo "Import sort errors, run 'make isort' to fix them!!!"; \
52-
isort --diff $(SRC); \
53-
false; \
54-
fi
55-
56-
check_changes:
57-
./tools/check_changes.py
22+
lint: .install-deps
23+
ifdef CI
24+
python -m pre_commit run --all-files --show-diff-on-failure
25+
else
26+
python -m pre_commit run --all-files
27+
endif
28+
python -m mypy frozenlist --show-error-codes
5829

5930
.develop: .install-deps $(shell find frozenlist -type f) .flake check_changes mypy
6031
pip install -e .

0 commit comments

Comments
 (0)