From ae28e0a847b33bc591500ba6b6f42a14df331e8d Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 9 Aug 2025 12:32:33 -0400 Subject: [PATCH] Switch from tox to nox --- .github/workflows/ci.yml | 89 ++++++++++++++++++++-------------------- .gitignore | 2 +- MANIFEST.in | 2 +- noxfile.py | 88 +++++++++++++++++++++++++++++++++++++++ pyproject.toml | 8 ++-- tox.ini | 70 ------------------------------- 6 files changed, 138 insertions(+), 121 deletions(-) create mode 100644 noxfile.py delete mode 100644 tox.ini diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f71bff678..5a4f5f709 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,55 +11,54 @@ jobs: matrix: PYTHON: # Base builds - - {VERSION: "3.7", TOXENV: "py37"} - - {VERSION: "3.8", TOXENV: "py38"} - - {VERSION: "3.9", TOXENV: "py39"} - - {VERSION: "3.10", TOXENV: "py310"} - - {VERSION: "3.11", TOXENV: "py311"} - - {VERSION: "3.12", TOXENV: "py312"} - - {VERSION: "3.13-dev", TOXENV: "py313"} - - {VERSION: "pypy-3.9", TOXENV: "pypy3"} - - {VERSION: "pypy-3.10", TOXENV: "pypy3"} - - {VERSION: "3.11", TOXENV: "py311-useWheel", OS: "windows-2022" } - # -cryptographyMain - - {VERSION: "3.8", TOXENV: "py38-cryptographyMain"} - - {VERSION: "3.9", TOXENV: "py39-cryptographyMain"} - - {VERSION: "3.10", TOXENV: "py310-cryptographyMain"} - - {VERSION: "3.11", TOXENV: "py311-cryptographyMain"} - - {VERSION: "3.12", TOXENV: "py312-cryptographyMain"} - - {VERSION: "3.13-dev", TOXENV: "py313-cryptographyMain"} - - {VERSION: "pypy-3.9", TOXENV: "pypy3-cryptographyMain"} - - {VERSION: "pypy-3.10", TOXENV: "pypy3-cryptographyMain"} - # -cryptographyMinimum - - {VERSION: "3.7", TOXENV: "py37-cryptographyMinimum"} - - {VERSION: "3.8", TOXENV: "py38-cryptographyMinimum"} - - {VERSION: "3.9", TOXENV: "py39-cryptographyMinimum"} - - {VERSION: "3.10", TOXENV: "py310-cryptographyMinimum"} - - {VERSION: "3.11", TOXENV: "py311-cryptographyMinimum"} - - {VERSION: "3.12", TOXENV: "py312-cryptographyMinimum"} - - {VERSION: "3.13-dev", TOXENV: "py313-cryptographyMinimum"} - - {VERSION: "pypy-3.10", TOXENV: "pypy3-cryptographyMinimum"} + - {VERSION: "3.7", NOXSESSION: "tests"} + - {VERSION: "3.8", NOXSESSION: "tests"} + - {VERSION: "3.9", NOXSESSION: "tests"} + - {VERSION: "3.10", NOXSESSION: "tests"} + - {VERSION: "3.11", NOXSESSION: "tests"} + - {VERSION: "3.12", NOXSESSION: "tests"} + - {VERSION: "3.13-dev", NOXSESSION: "tests"} + - {VERSION: "pypy-3.9", NOXSESSION: "tests"} + - {VERSION: "pypy-3.10", NOXSESSION: "tests"} + - {VERSION: "3.11", NOXSESSION: "tests-wheel", OS: "windows-2022"} + # -cryptography-main + - {VERSION: "3.8", NOXSESSION: "tests-cryptography-main"} + - {VERSION: "3.9", NOXSESSION: "tests-cryptography-main"} + - {VERSION: "3.10", NOXSESSION: "tests-cryptography-main"} + - {VERSION: "3.11", NOXSESSION: "tests-cryptography-main"} + - {VERSION: "3.12", NOXSESSION: "tests-cryptography-main"} + - {VERSION: "3.13-dev", NOXSESSION: "tests-cryptography-main"} + - {VERSION: "pypy-3.9", NOXSESSION: "tests-cryptography-main"} + - {VERSION: "pypy-3.10", NOXSESSION: "tests-cryptography-main"} + # -cryptography-minimum + - {VERSION: "3.7", NOXSESSION: "tests-cryptography-minimum"} + - {VERSION: "3.8", NOXSESSION: "tests-cryptography-minimum"} + - {VERSION: "3.9", NOXSESSION: "tests-cryptography-minimum"} + - {VERSION: "3.10", NOXSESSION: "tests-cryptography-minimum"} + - {VERSION: "3.11", NOXSESSION: "tests-cryptography-minimum"} + - {VERSION: "3.12", NOXSESSION: "tests-cryptography-minimum"} + - {VERSION: "3.13-dev", NOXSESSION: "tests-cryptography-minimum"} + - {VERSION: "pypy-3.10", NOXSESSION: "tests-cryptography-minimum"} # Cryptography wheels - - {VERSION: "3.9", TOXENV: "py39-cryptographyMinimum-useWheel"} - - {VERSION: "3.9", TOXENV: "py39-useWheel"} + - {VERSION: "3.9", NOXSESSION: "tests-cryptography-minimum-wheel"} + - {VERSION: "3.9", NOXSESSION: "tests-wheel"} # Random order - - {VERSION: "3.9", TOXENV: "py39-randomorder"} + - {VERSION: "3.9", NOXSESSION: "tests-random-order"} # Meta - - {VERSION: "3.9", TOXENV: "check-manifest"} - - {VERSION: "3.11", TOXENV: "lint"} - - {VERSION: "3.13", TOXENV: "py313-mypy"} - - {VERSION: "3.9", TOXENV: "docs"} - name: "${{ matrix.PYTHON.TOXENV }}${{ matrix.PYTHON.OS && format(' on {0}', matrix.PYTHON.OS) || '' }}" + - {VERSION: "3.9", NOXSESSION: "check-manifest"} + - {VERSION: "3.11", NOXSESSION: "lint"} + - {VERSION: "3.13", NOXSESSION: "mypy"} + - {VERSION: "3.9", NOXSESSION: "docs"} steps: - uses: actions/checkout@v4 - name: Setup python uses: actions/setup-python@v5 with: python-version: ${{ matrix.PYTHON.VERSION }} - - run: python -m pip install tox - - run: tox -v + - run: python -m pip install nox + - run: nox env: - TOXENV: ${{ matrix.PYTHON.TOXENV }} + NOXSESSION: ${{ matrix.PYTHON.NOXSESSION }} - uses: ./.github/actions/upload-coverage linux-docker: @@ -69,16 +68,16 @@ jobs: fail-fast: false matrix: TEST: - # cryptographyMain used since there's no wheel - - {CONTAINER: "ubuntu-rolling", TOXENV: "py313-cryptographyMain"} - name: "${{ matrix.TEST.TOXENV }} on ${{ matrix.TEST.CONTAINER }}" + # cryptography-main used since there's no wheel + - {CONTAINER: "ubuntu-rolling", NOXSESSION: "tests-cryptography-main"} + name: "${{ matrix.TEST.NOXSESSION }} on ${{ matrix.TEST.CONTAINER }}" steps: - uses: actions/checkout@v4 - - run: /venv/bin/pip install tox - - run: /venv/bin/tox -v + - run: /venv/bin/pip install nox + - run: /venv/bin/nox env: - TOXENV: ${{ matrix.TEST.TOXENV }} RUSTUP_HOME: /root/.rustup + NOXSESSION: ${{ matrix.TEST.NOXSESSION }} - uses: ./.github/actions/upload-coverage linux-downstream: diff --git a/.gitignore b/.gitignore index e3057ad70..edca32488 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ dist *.pyc *.pyo __pycache__ -.tox +.nox doc/_build/ .coverage* .eggs diff --git a/MANIFEST.in b/MANIFEST.in index 12d6d8545..1eba7bd4b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include LICENSE MANIFEST.in *.rst tox.ini .coveragerc src/OpenSSL/py.typed +include LICENSE MANIFEST.in *.rst noxfile.py .coveragerc src/OpenSSL/py.typed exclude .readthedocs.yml mypy.ini recursive-include tests *.py recursive-include doc * diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 000000000..f0ee8b676 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,88 @@ +import nox + +nox.options.reuse_existing_virtualenvs = True +nox.options.default_venv_backend = "uv|virtualenv" + +MINIMUM_CRYPTOGRAPHY_VERSION = "41.0.5" + + +@nox.session +@nox.session(name="tests-cryptography-main") +@nox.session(name="tests-cryptography-minimum") +@nox.session(name="tests-wheel") +@nox.session(name="tests-cryptography-minimum-wheel") +@nox.session(name="tests-random-order") +def tests(session: nox.Session) -> None: + cryptography_version = None + use_wheel = False + random_order = False + + if "cryptography-main" in session.name: + cryptography_version = "main" + elif "cryptography-minimum" in session.name: + cryptography_version = "minimum" + + if "wheel" in session.name: + use_wheel = True + + if "random-order" in session.name: + random_order = True + + session.env.update( + { + "PIP_NO_BINARY": "" if use_wheel else "cryptography", + } + ) + + deps = ["coverage>=4.2"] + + if cryptography_version == "minimum": + deps.append(f"cryptography=={MINIMUM_CRYPTOGRAPHY_VERSION}") + + if random_order: + deps.append("pytest-randomly") + + session.install(*deps) + session.install("-e", ".[test]") + if cryptography_version == "main": + session.install("git+https://github.com/pyca/cryptography.git") + + session.run("openssl", "version", external=True) + session.run("coverage", "run", "--parallel", "-m", "OpenSSL.debug") + session.run( + "coverage", "run", "--parallel", "-m", "pytest", "-v", *session.posargs + ) + + +@nox.session +def lint(session: nox.Session) -> None: + session.install("ruff") + session.run("ruff", "check", ".") + session.run("ruff", "format", "--check", ".") + + +@nox.session +def mypy(session: nox.Session) -> None: + session.install("-e", ".[test]") + session.install("mypy") + session.run("mypy", "src/", "tests/") + + +@nox.session(name="check-manifest") +def check_manifest(session: nox.Session) -> None: + session.install("check-manifest") + session.run("check-manifest") + + +@nox.session +def docs(session: nox.Session) -> None: + session.install("-e", ".[docs]") + session.run( + "sphinx-build", + "-W", + "-b", + "html", + "doc", + "doc/_build/html", + *session.posargs, + ) diff --git a/pyproject.toml b/pyproject.toml index c1b65aa3f..af106976a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,10 +6,10 @@ source = ["OpenSSL", "tests/"] [tool.coverage.paths] source = [ "src/OpenSSL", - "*.tox/*/lib/python*/site-packages/OpenSSL", - "*.tox/*/lib/pypy*/site-packages/OpenSSL", - "*.tox/pypy/site-packages/OpenSSL", - "*.tox\\*\\Lib\\site-packages\\OpenSSL", + "*.nox/*/lib/python*/site-packages/OpenSSL", + "*.nox/*/lib/pypy*/site-packages/OpenSSL", + "*.nox/pypy/site-packages/OpenSSL", + "*.nox\\*\\Lib\\site-packages\\OpenSSL", ] [tool.coverage.report] diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 4a673e559..000000000 --- a/tox.ini +++ /dev/null @@ -1,70 +0,0 @@ -[tox] -envlist = py{py3,37,38,39,310,311,312,313}{,-cryptographyMinimum}{,-useWheel}{,-randomorder},check-manifest,lint,py313-mypy,docs,coverage-report - -[testenv] -allowlist_externals = - openssl -passenv = - ARCHFLAGS - CFLAGS - LC_ALL - LDFLAGS - PATH - LD_LIBRARY_PATH - TERM - RUSTUP_TOOLCHAIN - RUSTUP_HOME -extras = - test -deps = - coverage>=4.2 - cryptographyMinimum: cryptography==41.0.5 - randomorder: pytest-randomly -setenv = - # Do not allow the executing environment to pollute the test environment - # with extra packages. - PYTHONPATH= - PIP_NO_BINARY=cryptography - useWheel: PIP_NO_BINARY= -commands = - cryptographyMain: pip install -U git+https://github.com/pyca/cryptography.git - openssl version - coverage run --parallel -m OpenSSL.debug - coverage run --parallel -m pytest -v {posargs} - -[testenv:lint] -basepython = python3 -deps = - ruff -skip_install = true -commands = - ruff check . - ruff format --check . - -[testenv:py313-mypy] -extras = - test -deps = - mypy -commands = - mypy src/ tests/ - -[testenv:check-manifest] -deps = - check-manifest -skip_install = true -commands = - check-manifest - -[testenv:docs] -extras = - docs -commands = - sphinx-build -W -b html doc doc/_build/html {posargs} - -[testenv:coverage-report] -deps = coverage[toml]>=4.2 -skip_install = true -commands = - coverage combine - coverage report