Skip to content

Commit

Permalink
Switch from tox to nox
Browse files Browse the repository at this point in the history
This greatly simplifies (and makes more idiomatic) both our local tests and CI.
  • Loading branch information
hynek committed Sep 23, 2022
1 parent e301d67 commit 0d634eb
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 140 deletions.
3 changes: 3 additions & 0 deletions setup.cfg → .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[flake8]
# Allow for longer test strings. Code is formatted to 88 columns by Black.
max-line-length = 99
extend-ignore =
# Conflict between flake8 & black about whitespace in slices.
E203
59 changes: 23 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,25 @@ jobs:
runs-on: ubuntu-latest
python:
- name: CPython 3.9
tox: py39
action: 3.9
task:
- name: Build
tox: build
nox: build

steps:
- uses: actions/checkout@v3

- name: Set up ${{ matrix.python.name }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.action }}

- name: Install dependencies
run: python -m pip install --upgrade pip tox
run: python -m pip install --upgrade pip nox

- uses: twisted/python-info-action@v1

- name: Tox
run: tox -c tox.ini -e ${{ matrix.task.tox }}
- run: nox -e ${{ matrix.task.nox }}

- name: Publish
uses: actions/upload-artifact@v3
Expand All @@ -60,29 +58,22 @@ jobs:
matrix:
python:
- name: CPython 3.7
tox: py37
action: 3.7
- name: CPython 3.8
tox: py38
action: 3.8
- name: CPython 3.9
tox: py39
action: 3.9
- name: CPython 3.10
tox: py310
action: '3.10'
- name: CPython 3.11
tox: py311
action: '3.11.0-beta - 3.11'
- name: PyPy 3.7
tox: pypy37
action: pypy-3.7
action: pypy3.7
- name: PyPy 3.8
tox: pypy38
action: pypy-3.8
action: pypy3.8
task:
- name: Test
tox: tests
nox: tests

steps:
- uses: actions/checkout@v3
Expand All @@ -94,21 +85,20 @@ jobs:
path: dist/

- name: Set up ${{ matrix.python.name }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.action }}

- name: Install dependencies
run: python -m pip install --upgrade pip tox codecov coverage[toml]
run: python -m pip install --upgrade pip nox codecov coverage[toml]

- uses: twisted/python-info-action@v1

- name: Tox
run: tox -c tox.ini --installpkg dist/*.whl -e ${{ matrix.python.tox }}-tests
- run: nox --python ${{ matrix.python.action }} -e ${{ matrix.task.nox }} -- --use-wheel dist/*.whl

- name: Codecov
run: |
codecov -n "GitHub Actions - ${{ matrix.task.name}} - ${{ matrix.os.name }} ${{ matrix.python.name }}"
codecov -n "GitHub Actions - Tests - ${{ matrix.os.name }} ${{ matrix.python.name }}"
test-windows:
Expand All @@ -121,11 +111,10 @@ jobs:
matrix:
python:
- name: CPython 3.9
tox: py39
action: '3.9'
task:
- name: Test
tox: tests
nox: tests

steps:
- uses: actions/checkout@v3
Expand All @@ -137,17 +126,16 @@ jobs:
path: dist/

- name: Set up ${{ matrix.python.name }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.action }}

- name: Install dependencies
run: python -m pip install --upgrade pip tox codecov coverage[toml]
run: python -m pip install --upgrade pip nox codecov coverage[toml]

- uses: twisted/python-info-action@v1

- name: Tox
run: tox -c tox.ini --installpkg dist/*.whl -e ${{ matrix.python.tox }}-tests
- run: nox --python ${{ matrix.python.action }} -e ${{ matrix.task.nox }} -- --use-wheel dist/*.whl

- name: Codecov
run: |
Expand All @@ -165,17 +153,16 @@ jobs:
# Using second most recent minor release for whatever little
# increase in stability over using the latest minor.
- name: CPython 3.9
tox: py39
python-version: '3.9'
task:
- name: Check Newsfragment
tox: check-newsfragment
nox: check_newsfragment
run-if: ${{ github.head_ref != 'pre-commit-ci-update-config' }}
- name: Check package manifest
tox: check-manifest
nox: check_manifest
run-if: true
- name: Check mypy
tox: typecheck
nox: typecheck
run-if: true

steps:
Expand All @@ -190,18 +177,18 @@ jobs:
path: dist/

- name: Set up ${{ matrix.python.name }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.python-version }}

- name: Install dependencies
run: python -m pip install --upgrade pip tox
run: python -m pip install --upgrade pip nox

- uses: twisted/python-info-action@v1

- name: Tox
- run: nox -e ${{ matrix.task.nox }}
if: ${{ matrix.task.run-if }}
run: tox -c tox.ini -e ${{ matrix.task.tox }}


pypi-publish:
# https://github.saobby.my.eu.orgmunity/t/is-it-possible-to-require-all-github-actions-tasks-to-pass-without-enumerating-them/117957/4?u=graingert
Expand All @@ -222,7 +209,7 @@ jobs:
path: dist/

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: 3.9

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ apidocs/
*.pyproj
.DS_Store
.eggs
.tox/
.nox/
.coverage.*
.vscode
.idea
Expand Down
22 changes: 11 additions & 11 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ We recommend the following workflow:
Running the test suite
----------------------

We use the `twisted.trial`_ module and `tox`_ to run tests against all supported
We use the `twisted.trial`_ module and `nox`_ to run tests against all supported
Python versions and operating systems.

The following list contains some ways how to run the test suite:
Expand All @@ -109,42 +109,42 @@ The following list contains some ways how to run the test suite:
This will invoke a PDB session. If you press ``c`` it will continue running
the test suite until it runs into an error.

* To run all tests against all supported versions, install tox and use::
* To run all tests against all supported versions, install nox and use::

$ tox
$ nox

You may want to add the ``--skip-missing-interpreters`` option to avoid errors
You may want to add the ``--no-error-on-missing-interpreters`` option to avoid errors
when a specific Python interpreter version couldn't be found.

* To get a complete list of the available targets, run::

$ tox -av
$ nox -l

* To run only a specific test only, use the ``towncrier.test.FILE.CLASS.METHOD`` syntax,
for example::

$ tox -- towncrier.test.test_project.InvocationTests.test_version
$ nox -e tests -- towncrier.test.test_project.InvocationTests.test_version

* To run some quality checks before you create the pull request,
we recommend using this call::

$ tox -e pre-commit,check-manifest,check-newsfragment
$ nox -e pre_commit check_manifest check_newsfragment

* Or enable `pre-commit` as a git hook::

$ pip install pre-commit
$ pre-commit install


**Please note**: If the test suite works in tox, but doesn't by calling
**Please note**: If the test suite works in nox, but doesn't by calling
``trial``, it could be that you've got GPG-signing active for git commits which
fails with our dummy test commits.

.. ### Links
.. _flake8: https://flake8.rtfd.io
.. _flake8: https://flake8.pycqa.org/
.. _GitHub Discussions: https://github.com/twisted/towncrier/discussions
.. _issues: https://github.com/twisted/towncrier/issues
.. _pull request: https://github.com/twisted/towncrier/pulls
.. _tox: https://tox.rtfd.org/
.. _twisted.trial: https://twistedmatrix.com/trac/wiki/TwistedTrial
.. _nox: https://nox.thea.codes/
.. _twisted.trial: https://github.com/twisted/trac-wiki-archive/blob/trunk/TwistedTrial.mediawiki
5 changes: 2 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ include .coveragerc
include LICENSE
include CODE_OF_CONDUCT.md
include pyproject.toml
include tox.ini
include tox_build.sh
include tox_check-release.sh
include noxfile.py
include *.yaml
include .git-blame-ignore-revs
include .flake8
recursive-include src *.rst

exclude bin
Expand Down
97 changes: 97 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from __future__ import annotations

import os

import nox


nox.options.sessions = ["pre_commit", "docs", "typecheck", "tests"]
nox.options.reuse_existing_virtualenvs = True
nox.options.error_on_external_run = True


@nox.session
def pre_commit(session: nox.Session) -> None:
session.install("pre-commit")

session.run("pre-commit", "run", "--all-files", "--show-diff-on-failure")


@nox.session(python=["pypy3.7", "pypy3.8", "3.7", "3.8", "3.9", "3.10", "3.11"])
def tests(session: nox.Session) -> None:
session.install("Twisted", "coverage[toml]")
posargs = list(session.posargs)

try:
# Allow `--use-wheel path/to/wheel.whl` to be passed.
i = session.posargs.index("--use-wheel")
session.install(session.posargs[i + 1])
del posargs[i : i + 2]
except ValueError:
session.install(".")

if not posargs:
posargs = ["towncrier"]

session.run("coverage", "run", "--module", "twisted.trial", *posargs)

if os.environ.get("CI") != "true":
session.notify("coverage_report")
else:
session.run("coverage", "combine")


@nox.session
def coverage_report(session: nox.Session) -> None:
session.install("coverage[toml]")

session.run("coverage", "combine")
session.run("coverage", "report")


@nox.session
def check_newsfragment(session: nox.Session) -> None:
session.install(".")
session.run("python", "-m", "towncrier.check", "--compare-with", "origin/trunk")


@nox.session
def check_manifest(session: nox.Session) -> None:
session.install("check-manifest")
session.run("check-manifest")


@nox.session
def typecheck(session: nox.Session) -> None:
session.install(".", "mypy", "types-setuptools")
session.run("mypy", "src")


@nox.session
def docs(session: nox.Session) -> None:
session.install(".[dev]")

session.run(
# fmt: off
"python", "-m", "sphinx",
"-T", "-E",
"-W", "--keep-going",
"-b", "html",
"-d", "docs/_build/doctrees",
"-D", "language=en",
"docs",
"docs/_build/html",
# fmt: on
)


@nox.session
def build(session: nox.Session) -> None:
session.install("build", "check-manifest>=0.44", "twine")

session.run("check-manifest", "--verbose")
# If no argument is passed, build builds an sdist and then a wheel from
# that sdist.
session.run("python", "-m", "build")

session.run("twine", "check", "dist/*")
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exclude = '''
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.tox
| \.nox
| \.venv
| \.env
| env
Expand Down Expand Up @@ -71,6 +71,11 @@ module = 'click_default_group'
# 2022-09-04: This library has no type annotations.
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = 'incremental'
# No released version with type hints.
ignore_missing_imports = true


[build-system]
requires = [
Expand All @@ -86,7 +91,7 @@ branch = true
source = ["towncrier"]

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

[tool.coverage.report]
show_missing = true
Expand Down
Loading

0 comments on commit 0d634eb

Please sign in to comment.