From 2361233247a742919416c2dc16332eedba09e480 Mon Sep 17 00:00:00 2001 From: chrysle Date: Thu, 14 Mar 2024 20:28:01 +0100 Subject: [PATCH] Switch to `nox` for automated testing --- .github/workflows/test.yml | 6 +++-- .gitignore | 5 ++-- noxfile.py | 52 ++++++++++++++++++++++++++++++++++++++ tox.ini | 45 --------------------------------- 4 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 noxfile.py delete mode 100644 tox.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 67a77647..76651635 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,8 @@ jobs: with: python-version: ${{ matrix.python }} - name: Install test dependencies - run: python -m pip install -U tox + run: python -m pip install --upgrade nox - name: Test - run: python -m tox -e py + run: python -m nox -s tests-${{ matrix.python }} + - name: Lint + run: python -m nox -s lint diff --git a/.gitignore b/.gitignore index e81f0842..ddc2bd11 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,8 @@ dist/ __pycache__/ *.so *~ +venv/ -# due to using tox and pytest -.tox +# due to using nox and pytest +.nox .cache diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 00000000..8d0c9495 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,52 @@ +# this file is *not* meant to cover or endorse the use of nox or pytest or +# testing in general, +# +# It's meant to show the use of: +# +# - check-manifest +# confirm items checked into vcs are in your sdist +# - readme_renderer (when using a reStructuredText README) +# confirms your long_description will render correctly on PyPI. +# +# and also to help confirm pull requests to this project. + +import nox +import os + +nox.options.sessions = ["lint"] + +# Define the minimal nox version required to run +nox.options.needs_version = ">= 2024.3.2" + + +@nox.session +def lint(session): + session.install("flake8") + session.run( + "flake8", "--exclude", ".nox,*.egg,build,data", + "--select", "E,W,F", "." + ) + + +@nox.session +def build_and_check_dists(session): + session.install("build", "check-manifest >= 0.42", "twine") + # If your project uses README.rst, uncomment the following: + # session.install("readme_renderer") + + session.run("check-manifest", "--ignore", "noxfile.py,tests/**") + session.run("python", "-m", "build") + session.run("python", "-m", "twine", "check", "dist/*") + + +@nox.session(python=["3.8", "3.9", "3.10", "3.11", "3.12"]) +def tests(session): + session.install("pytest") + build_and_check_dists(session) + + generated_files = os.listdir("dist/") + generated_sdist = os.path.join("dist/", generated_files[1]) + + session.install(generated_sdist) + + session.run("py.test", "tests/", *session.posargs) diff --git a/tox.ini b/tox.ini deleted file mode 100644 index c96f4e62..00000000 --- a/tox.ini +++ /dev/null @@ -1,45 +0,0 @@ -# this file is *not* meant to cover or endorse the use of tox or pytest or -# testing in general, -# -# It's meant to show the use of: -# -# - check-manifest -# confirm items checked into vcs are in your sdist -# - readme_renderer (when using a ReStructuredText README) -# confirms your long_description will render correctly on PyPI. -# -# and also to help confirm pull requests to this project. - -[tox] -envlist = py{38,39,310,311,312} - -# Define the minimal tox version required to run; -# if the host tox is less than this the tool with create an environment and -# provision it with a tox that satisfies it under provision_tox_env. -# At least this version is needed for PEP 517/518 support. -minversion = 3.3.0 - -# Activate isolated build environment. tox will use a virtual environment -# to build a source distribution from the source tree. For build tools and -# arguments use the pyproject.toml file as specified in PEP-517 and PEP-518. -isolated_build = true - -[testenv] -deps = - check-manifest >= 0.42 - # If your project uses README.rst, uncomment the following: - # readme_renderer - flake8 - pytest - build - twine -commands = - check-manifest --ignore 'tox.ini,tests/**' - python -m build - python -m twine check dist/* - flake8 . - py.test tests {posargs} - -[flake8] -exclude = .tox,*.egg,build,data -select = E,W,F