Skip to content

Commit 6adce31

Browse files
authored
Add mypy as pre-commit hook (#467)
* [refactor] Run mypy as part of the pre-commit hooks. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de> * [ci] Use pre-commit directly, instead of starting it via a tox environment. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de> * [refactor] Removed obsolete "lint" tox environment. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de> * [ci] Run lint step with Python 3.11. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de> * [ci] Extracted environment variable for the latest Python version. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de> * [ci] Avoid checking out unnecessary Git history during deployment step. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de> * [ci] Avoid checking out unnecessary Git history during test step. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de> * [ci] Removed obsolete USING_COVERAGE env variable. We record coverage for all interpreters and merge them afterwards. There is no longer a need to specify the environment we want to use for measuring coverage. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de> Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
1 parent ed0666c commit 6adce31

File tree

4 files changed

+15
-31
lines changed

4 files changed

+15
-31
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
branches: [master]
1010
workflow_dispatch:
1111

12+
env:
13+
PYTHON_LATEST: 3.11
14+
1215
jobs:
1316
lint:
1417
name: Run linters
@@ -22,16 +25,18 @@ jobs:
2225
fetch-depth: 0
2326
- uses: actions/setup-python@v4
2427
with:
25-
python-version: '3.10'
28+
python-version: ${{ env.PYTHON_LATEST }}
2629
- name: Install GitHub matcher for ActionLint checker
2730
run: |
2831
echo "::add-matcher::.github/actionlint-matcher.json"
32+
- name: Install pre-commit
33+
run: python -m pip install pre-commit
34+
- name: Run pre-commit checks
35+
run: pre-commit run --all-files --show-diff-on-failure
2936
- name: Install check-wheel-content, and twine
3037
run: python -m pip install build check-wheel-contents tox twine
3138
- name: Build package
3239
run: python -m build
33-
- name: Run tox for linter
34-
run: python -m tox -e lint
3540
- name: List result
3641
run: ls -l dist
3742
- name: Check wheel contents
@@ -52,17 +57,13 @@ jobs:
5257
test:
5358
name: Python ${{ matrix.python-version }}
5459
runs-on: ubuntu-latest
55-
env:
56-
USING_COVERAGE: 3.7,3.8,3.9,3.10,3.11
5760

5861
strategy:
5962
matrix:
6063
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
6164

6265
steps:
6366
- uses: actions/checkout@v3
64-
with:
65-
fetch-depth: 0
6667
- uses: actions/setup-python@v4
6768
with:
6869
python-version: ${{ matrix.python-version }}
@@ -81,7 +82,6 @@ jobs:
8182
with:
8283
name: coverage-per-interpreter
8384
path: .coverage.*
84-
if: ${{ contains(env.USING_COVERAGE, matrix.python-version) }}
8585

8686
check:
8787
name: Check
@@ -96,7 +96,7 @@ jobs:
9696
- uses: actions/checkout@v3
9797
- uses: actions/setup-python@v4
9898
with:
99-
python-version: 3.11
99+
python-version: ${{ env.PYTHON_LATEST }}
100100
- name: Install Coverage.py
101101
run: |
102102
set -xe
@@ -128,8 +128,6 @@ jobs:
128128
sudo apt-get install -y pandoc
129129
- name: Checkout
130130
uses: actions/checkout@v3
131-
with:
132-
fetch-depth: 0
133131
- name: Download distributions
134132
uses: actions/download-artifact@v3
135133
with:

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ repos:
3636
- id: check-xml
3737
- id: check-yaml
3838
- id: debug-statements
39+
- repo: https://github.com/pre-commit/mirrors-mypy
40+
rev: v0.991
41+
hooks:
42+
- id: mypy
43+
exclude: ^(docs|tests)/.*
3944
- repo: https://github.com/pycqa/flake8
4045
rev: 5.0.4
4146
hooks:

Makefile

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ clean-test: ## remove test and coverage artifacts
2020
rm -f .coverage
2121
rm -fr htmlcov/
2222

23-
lint:
24-
# CI env-var is set by GitHub actions
25-
ifdef CI
26-
python -m pre_commit run --all-files --show-diff-on-failure
27-
else
28-
python -m pre_commit run --all-files
29-
endif
30-
python -m mypy pytest_asyncio
31-
3223
test:
3324
coverage run --parallel-mode --omit */_version.py -m pytest tests
3425

tox.ini

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
minversion = 3.14.0
3-
envlist = py37, py38, py39, py310, py311, lint, pytest-min
3+
envlist = py37, py38, py39, py310, py311, pytest-min
44
isolated_build = true
55
passenv =
66
CI
@@ -23,16 +23,6 @@ commands = make test
2323
allowlist_externals =
2424
make
2525

26-
[testenv:lint]
27-
basepython = python3.10
28-
extras = testing
29-
deps =
30-
pre-commit == 2.16.0
31-
commands =
32-
make lint
33-
allowlist_externals =
34-
make
35-
3626
[gh-actions]
3727
python =
3828
3.7: py37, pytest-min

0 commit comments

Comments
 (0)