Skip to content

Commit

Permalink
Simplify CI Mypy config (#146)
Browse files Browse the repository at this point in the history
* Simplify Mypy config

* env

* No mypy on pypy

* different rules for steps

* whitespace
  • Loading branch information
hynek committed Jun 14, 2023
1 parent 4db390a commit 2886c46
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 74 deletions.
79 changes: 37 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ permissions:

jobs:
tests:
name: Tests on ${{ matrix.python-version }}
name: Tests & Mypy on ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -35,16 +35,17 @@ jobs:
- "3.12"
- "pypy-3.7"
- "pypy-3.8"
- "pypy-3.9"

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- run: python -Im pip install --upgrade wheel tox
cache: pip

- name: Determine Python version for tox
- name: Prepare tox & run tests
run: |
V=${{ matrix.python-version }}
if [[ "$V" = pypy-* ]]; then
Expand All @@ -53,9 +54,11 @@ jobs:
V=py$(echo $V | tr -d .)
fi
echo TOX_PYTHON=$V >>$GITHUB_ENV
python -Im pip install tox
- run: python -Im tox run -f ${{ env.TOX_PYTHON }}
python -Im tox run -f $V
- run: python -Im tox run -e mypy-api
if: ${{ !startsWith(matrix.python-version, 'pypy-') }}

- name: Upload coverage data
uses: actions/upload-artifact@v3
Expand All @@ -72,15 +75,23 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
cache: pip
- uses: actions/download-artifact@v3
with:
name: coverage-data
- run: python -Im pip install --upgrade coverage[toml]

- name: Combine coverage & fail if it's <100%.
run: |
python -Im pip install coverage[toml]
python -Im coverage combine
python -Im coverage html --skip-covered --skip-empty
# Report and write to summary.
python -Im coverage report | sed 's/^/ /' >> $GITHUB_STEP_SUMMARY
# Report again and fail if under 100%.
python -Im coverage report --fail-under=100
- name: Upload HTML report if check failed.
Expand All @@ -101,48 +112,29 @@ jobs:
with:
fetch-depth: 0
- uses: actions/setup-python@v4
- name: Install dependencies
with:
cache: pip

- name: Install dependencies & run tox
run: |
sudo apt-get install libargon2-0 libargon2-0-dev
python -VV
python -Im site
python -Im pip install --upgrade wheel tox
- run: python -Im tox run -e system-argon2
python -Im tox run -e system-argon2
mypy-all:
name: Mypy for API & own code
mypy:
name: Type-check code base
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4

- run: python -Im pip install --upgrade wheel tox
- run: python -Im tox run -f mypy

mypy-api:
name: Mypy for API on ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- run: python -Im pip install --upgrade wheel tox
- run: python -Im tox run -e mypy-api
- name: Prepare & run tox
run: |
python -Im pip install tox
python -Im tox run -e mypy-pkg
docs:
name: Build docs & run doctests
Expand All @@ -153,9 +145,11 @@ jobs:
with:
# Keep in-sync with .readthedocs.yaml and tox.ini/docs.
python-version: "3.11"
- run: python -Im pip install --upgrade wheel tox

- run: tox run -e docs
- name: Prepare & run tox
run: |
python -Im pip install tox
python -Im tox run -e docs
install-dev:
name: Verify dev env
Expand All @@ -167,18 +161,19 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- run: python -Im pip install -e .[dev]

- run: python -Im argon2 -n 1 -t 1 -m 8 -p 1
- name: Install in dev mode and run CLI
run: |
python -Im pip install -e .[dev]
python -Im argon2 -n 1 -t 1 -m 8 -p 1
# Ensure everything required is passing for branch protection.
required-checks-pass:
if: always()

needs:
- coverage
- mypy-all
- mypy-api
- mypy
- docs
- install-dev
- system-package
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.270
rev: v0.0.272
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
File renamed without changes.
64 changes: 33 additions & 31 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
min_version = 4
env_list =
pre-commit,
mypy-{all,api},
mypy-{pkg,api},
py3{7,8,9,10,11,12}
py311-bindings-main,
pypy3,
Expand All @@ -11,38 +11,10 @@ env_list =
coverage-report


[testenv:docs]
description = Build docs and run doctests.
# Keep base_python in-sync with .readthedocs.yaml and ci.yml/docs.
base_python = python3.11
extras = docs
commands =
python -Im doctest README.md
sphinx-build -W -b html -d {envtmpdir}/doctrees docs docs/_build/html
sphinx-build -W -b doctest -d {envtmpdir}/doctrees docs docs/_build/html


[testenv:pre-commit]
description = Run all pre-commit hooks.
skip_install = true
deps = pre-commit
commands = pre-commit run --all-files


[testenv:mypy-all]
description = Check own code and API.
deps = mypy
commands = mypy src typing_examples.py


[testenv:mypy-api]
description = Check only API types.
deps = mypy
commands = mypy typing_examples.py


[testenv]
description = Run tests and do NOT measure coverage.
package = wheel
wheel_build_env = .pkg
extras = tests
commands =
pytest {posargs}
Expand Down Expand Up @@ -87,3 +59,33 @@ commands =
pip install -I hypothesis pytest git+https://github.com/hynek/argon2-cffi-bindings
pytest {posargs}
python -Im argon2 -n 1 -t 1 -m 8 -p 1


[testenv:docs]
description = Build docs and run doctests.
# Keep base_python in-sync with .readthedocs.yaml and ci.yml/docs.
base_python = python3.11
extras = docs
commands =
python -Im doctest README.md
sphinx-build -W -b html -d {envtmpdir}/doctrees docs docs/_build/html
sphinx-build -W -b doctest -d {envtmpdir}/doctrees docs docs/_build/html


[testenv:pre-commit]
description = Run all pre-commit hooks.
skip_install = true
deps = pre-commit
commands = pre-commit run --all-files


[testenv:mypy-pkg]
description = Check own code.
deps = mypy
commands = mypy src


[testenv:mypy-api]
description = Check only API types.
deps = mypy
commands = mypy tests/typing

0 comments on commit 2886c46

Please sign in to comment.