Skip to content

Commit

Permalink
Streamline tox.ini / ci.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Feb 7, 2023
1 parent 1f01557 commit 686f2a7
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 90 deletions.
12 changes: 12 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[flake8]
exclude = src/argon2/_ffi.py
ignore =
# Ambiguous variable names
# Ignored, since there is an enum value "I" for the algorithm type Argon2I
E741
# Not an actual PEP8 violation
W503
# Black vs flake8 conflict
E203

# vim: ft=dosini
3 changes: 2 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Please report any harm to [Hynek Schlawack] in any way you find appropriate.

You can (and should) run our test suite using [*tox*].
However, you’ll probably want a more traditional environment as well.
We highly recommend to develop using the latest Python release because we try to take advantage of modern features whenever possible.
We highly recommend to develop using the version specified in the `.python-version` file in the project root.
That's the version used in CI by default.

First create a [virtual environment](https://virtualenv.pypa.io/) so you don't break your system-wide Python installation.
It’s out of scope for this document to list all the ways to manage virtual environments in Python, but if you don’t already have a pet way, take some time to look at tools like [*direnv*](https://hynek.me/til/python-project-local-venvs/), [*virtualfish*](https://virtualfish.readthedocs.io/), and [*virtualenvwrapper*](https://virtualenvwrapper.readthedocs.io/).
Expand Down
81 changes: 56 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ env:
SETUPTOOLS_SCM_PRETEND_VERSION: "1.0" # avoid warnings about shallow checkout
PIP_DISABLE_PIP_VERSION_CHECK: 1
PIP_NO_PYTHON_VERSION_WARNING: 1
PYTHON_LATEST: "3.10"
# N.B. default Python version for setup-python comes from the .python-version
# file at the root of the project.

permissions:
contents: read

jobs:
tests:
name: tox on ${{ matrix.python-version }}
name: Tests on ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -50,9 +51,25 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: python -m pip install --upgrade wheel tox tox-gh-actions
- run: python -Im pip install --upgrade wheel tox

- run: python -m tox
- name: Determine Python version for tox
run: |
V=${{ matrix.python-version }}
if [[ "$V" = ~* ]]; then
# Extract version from a '~3.XX.0-0' specifier.
V=${V:1:4}
fi
if [[ "$V" = pypy-* ]]; then
V=pypy3
else
V=py$(echo $V | tr -d .)
fi
echo TOX_PYTHON=$V >>$GITHUB_ENV
- run: python -Im tox run -f ${{ env.TOX_PYTHON }}

- name: Upload coverage data
uses: actions/upload-artifact@v3
Expand All @@ -78,21 +95,16 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
# Use latest Python, so it understands all syntax.
python-version: ${{env.PYTHON_LATEST}}

- run: python -m pip install --upgrade coverage[toml]

- 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 -m coverage combine
python -m coverage html --skip-covered --skip-empty
python -m coverage report --fail-under=100
python -Im coverage combine
python -Im coverage html --skip-covered --skip-empty
python -Im coverage report --fail-under=100
- name: Upload HTML report if check failed.
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -122,16 +134,36 @@ jobs:
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: ${{env.PYTHON_LATEST}}
- name: Install dependencies
run: |
sudo apt-get install libargon2-0 libargon2-0-dev
python -VV
python -m site
python -m pip install --upgrade wheel tox
python -Im site
python -Im pip install --upgrade wheel tox
- run: python -m tox -e system-argon2
- run: python -Im tox run -e system-argon2

mypy:
name: Mypy 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"

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

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

docs:
name: Build docs & run doctests
Expand All @@ -151,9 +183,9 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- run: python -Im pip install --upgrade wheel tox

- run: python -m pip install --upgrade wheel tox
- run: tox -e docs
- run: tox run -e docs

package:
name: Build & verify package
Expand All @@ -170,10 +202,10 @@ jobs:
files.pythonhosted.org:443
github.com:443
pypi.org:443
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: hynek/build-and-inspect-python-package@v1

install-dev:
Expand All @@ -195,10 +227,9 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{env.PYTHON_LATEST}}
- run: python -m pip install -e .[dev]
- run: python -m argon2 -n 1 -t 1 -m 8 -p 1
- run: python -Im pip install -e .[dev]

- run: python -Im argon2 -n 1 -t 1 -m 8 -p 1

# Ensure everything required is passing for branch protection.
required-checks-pass:
Expand Down
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ ci:
autoupdate_schedule: monthly

default_language_version:
python: python3.10
# Keep in sync with .python-version.
python: python3.11

repos:
- repo: https://github.com/psf/black
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ branch = true
source = ["argon2"]

[tool.coverage.paths]
source = ["src", ".tox/py*/**/site-packages"]
source = ["src", ".tox/**/site-packages"]

[tool.coverage.report]
show_missing = true
Expand Down
90 changes: 28 additions & 62 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
[flake8]
exclude = src/argon2/_ffi.py
ignore =
# Ambiguous variable names
# Ignored, since there is an enum value "I" for the algorithm type Argon2I
E741
# Not an actual PEP8 violation
W503
# Black vs flake8 conflict
E203


# We don't run pre-commit in CI, because we use pre-commit.ci.
[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39, mypy
3.10: py310, bindings-main
3.11: py311
pypy-3: pypy3


[tox]
envlist = pre-commit,mypy,py37,py38,py39,py310,py311,pypy3,system-argon2,bindings-main,docs,pypi-description,coverage-report
isolated_build = true
min_version = 4
env_list =
pre-commit,
mypy,
py37,
py38,
py39,
py310,
py311{,-bindings-main},
pypy3,
system-argon2,
docs,
coverage-report


[testenv:docs]
description = Build docs and run doctests.
# Keep basepython in-sync with .readthedocs.yml and ci.yml/docs.
basepython = python3.10
# Keep base_python in-sync with .readthedocs.yaml and ci.yml/docs.
base_python = python3.10
extras = docs
commands =
python -m doctest README.md
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

Expand All @@ -54,20 +42,11 @@ commands = mypy src typing_examples.py
description = Run tests and do NOT measure coverage.
extras = tests
commands =
python -m pytest {posargs}
python -m argon2 -n 1 -t 1 -m 8 -p 1


[testenv:py37]
description = Run tests and measure coverage.
deps = coverage[toml]
commands =
coverage run -m pytest {posargs}
coverage run -m argon2 -n 1 -t 1 -m 8 -p 1
coverage run -m argon2 --profile CHEAPEST
pytest {posargs}
python -Im argon2 -n 1 -t 1 -m 8 -p 1


[testenv:py310]
[testenv:py3{7,11}]
description = Run tests and measure coverage.
deps = coverage[toml]
commands =
Expand All @@ -79,42 +58,29 @@ commands =
[testenv:coverage-report]
description = Report coverage over all test runs.
skip_install = true
depends =
py37
py310
basepython = python3.10
depends = py3{7,11}
deps = coverage[toml]
parallel_show_output = true
commands =
coverage combine
coverage report


[testenv:system-argon2]
description = Run tests against bindings that use a system installation of Argon2.
setenv = ARGON2_CFFI_USE_SYSTEM=1
set_env = ARGON2_CFFI_USE_SYSTEM=1
install_command =
pip install {opts} --no-binary=argon2-cffi-bindings {packages}
commands =
python -m pytest {posargs}
python -m argon2 -n 1 -t 1 -m 8 -p 1
pytest {posargs}
python -Im argon2 -n 1 -t 1 -m 8 -p 1


[testenv:bindings-main]
[testenv:py311-bindings-main]
description = Run tests against the current main branch of argon2-cffi-bindings
install_command = pip install {opts} --no-deps {packages}
extras =
commands =
pip install hypothesis pytest git+https://github.com/hynek/argon2-cffi-bindings
python -m pytest {posargs}
python -m argon2 -n 1 -t 1 -m 8 -p 1


[testenv:pypi-description]
description = Ensure README renders on PyPI.
skip_install = true
deps =
twine
pip >= 18.0.0
commands =
pip wheel -w {envtmpdir}/build --no-deps .
twine check {envtmpdir}/build/*
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

0 comments on commit 686f2a7

Please sign in to comment.