Skip to content

Commit

Permalink
Setup pre-commit (#276)
Browse files Browse the repository at this point in the history
* Setup pre-commit

* Add build to requirements
  • Loading branch information
asvetlov authored Jan 18, 2022
1 parent 09189ad commit 2538a00
Show file tree
Hide file tree
Showing 15 changed files with 238 additions and 181 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

<!-- Describe the environment you have that lead to your issue.
This includes the frozenlist version, OS, proxy server and other
relevant software that is related to your case.
relevant software that is related to your case.
-->
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- [ ] Documentation reflects the changes
- [ ] If you provide code modifications, please add yourself to `CONTRIBUTORS.txt`
* The format is &lt;Name&gt; &lt;Surname&gt;.
* Please keep the list in alphabetical order, the file is sorted by name.
* Please keep the list in alphabetical order, the file is sorted by name.
- [ ] Add a new news fragment into the `CHANGES` folder
* name it `<issue_id>.<type>` for example (588.bugfix)
* if you don't have an `issue_id` change it to the pr id after creating the pr
Expand Down
14 changes: 4 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,9 @@ jobs:
pip install .
env:
FROZENLIST_NO_EXTENSIONS: 1
- name: Run flake8
- name: Run linters
run: |
make flake8
- name: Run isort-check
run: |
make isort-check
- name: Run mypy checker
run: |
make mypy
make lint
- name: Install spell checker
run: |
sudo apt install libenchant-dev
Expand All @@ -60,7 +54,7 @@ jobs:
- name: Prepare twine checker
run: |
pip install -U twine wheel
python setup.py sdist bdist_wheel
python -m build
env:
FROZENLIST_NO_EXTENSIONS: 1
- name: Run twine checker
Expand Down Expand Up @@ -170,7 +164,7 @@ jobs:
make cythonize
- name: Make sdist
run:
python setup.py sdist
python -m build --sdist
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
Expand Down
98 changes: 98 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
repos:
- repo: local
hooks:
- id: check-changes
name: Check CHANGES
language: system
entry: ./tools/check_changes.py
pass_filenames: false
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.1.0'
hooks:
- id: check-merge-conflict
- repo: https://github.com/asottile/yesqa
rev: v1.3.0
hooks:
- id: yesqa
- repo: https://github.com/PyCQA/isort
rev: '5.10.1'
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: '21.12b0'
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.1.0'
hooks:
- id: end-of-file-fixer
exclude: >-
^docs/[^/]*\.svg$
- id: requirements-txt-fixer
exclude: >-
^requirements/constraints[.]txt$
- id: trailing-whitespace
- id: file-contents-sorter
args: ['--ignore-case']
files: |
CONTRIBUTORS.txt|
docs/spelling_wordlist.txt|
.gitignore|
.gitattributes
- id: check-case-conflict
- id: check-json
- id: check-xml
- id: check-executables-have-shebangs
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: check-added-large-files
- id: check-symlinks
- id: fix-byte-order-marker
- id: fix-encoding-pragma
args: ['--remove']
- id: detect-aws-credentials
args: ['--allow-missing-credentials']
- id: detect-private-key
exclude: ^examples/
- repo: https://github.com/asottile/pyupgrade
rev: 'v2.31.0'
hooks:
- id: pyupgrade
args: ['--py36-plus']
- repo: https://github.com/PyCQA/flake8
rev: '4.0.1'
hooks:
- id: flake8
exclude: "^docs/"
- repo: git://github.com/Lucas-C/pre-commit-hooks-markup
rev: v1.0.1
hooks:
- id: rst-linter
files: >-
^[^/]+[.]rst$
exclude: >-
^CHANGES\.rst$
- repo: https://github.com/rhysd/actionlint
rev: v1.6.8
hooks:
- id: actionlint-docker
args:
- -ignore
- 'SC2155:'
- -ignore
- 'SC2157:'
- -ignore
- 'SC2086:'
- -ignore
- 'SC1004:'
- repo: https://github.com/sirosen/check-jsonschema
rev: 0.10.0
hooks:
- id: check-github-actions
ci:
skip:
- actionlint-docker
- check-github-actions
- check-changes
45 changes: 8 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,16 @@ cythonize: .install-cython $(PYXS:.pyx=.c)

.install-deps: cythonize $(shell find requirements -type f)
pip install -r requirements/ci.txt
pre-commit install
@touch .install-deps

lint: flake isort-check flake8

isort:
isort $(SRC)

flake: .flake

.flake: .install-deps $(shell find frozenlist -type f) \
$(shell find tests -type f)
flake8 frozenlist tests
python setup.py sdist bdist_wheel
twine check dist/*
@if ! isort -c frozenlist tests; then \
echo "Import sort errors, run 'make isort' to fix them!"; \
isort --diff frozenlist tests; \
false; \
fi
@if ! LC_ALL=C sort -c CONTRIBUTORS.txt; then \
echo "CONTRIBUTORS.txt sort error"; \
fi
@touch .flake

flake8:
flake8 $(SRC)

mypy: .flake
mypy frozenlist

isort-check:
@if ! isort --check-only $(SRC); then \
echo "Import sort errors, run 'make isort' to fix them!!!"; \
isort --diff $(SRC); \
false; \
fi

check_changes:
./tools/check_changes.py
lint: .install-deps
ifdef CI
python -m pre_commit run --all-files --show-diff-on-failure
else
python -m pre_commit run --all-files
endif
python -m mypy frozenlist --show-error-codes

.develop: .install-deps $(shell find frozenlist -type f) .flake check_changes mypy
pip install -e .
Expand Down
Loading

0 comments on commit 2538a00

Please sign in to comment.