From ce80b7e0f3ba73b071c712eaf192b7d8a9c3c167 Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 17 Jan 2022 00:12:40 +0800 Subject: [PATCH] Switch from tox to nox --- .github/workflows/ci.yml | 3 +-- Cargo.toml | 2 +- Makefile | 5 ++--- examples/README.md | 2 +- examples/decorator/README.md | 4 ++-- examples/decorator/cargo-generate.toml | 2 +- examples/decorator/noxfile.py | 8 ++++++++ examples/decorator/tox.ini | 10 ---------- examples/maturin-starter/README.md | 4 ++-- examples/maturin-starter/cargo-generate.toml | 2 +- examples/maturin-starter/noxfile.py | 8 ++++++++ examples/maturin-starter/tox.ini | 10 ---------- examples/setuptools-rust-starter/README.md | 4 ++-- .../setuptools-rust-starter/cargo-generate.toml | 2 +- examples/setuptools-rust-starter/noxfile.py | 8 ++++++++ examples/setuptools-rust-starter/tox.ini | 5 ----- examples/word-count/README.md | 4 ++-- examples/word-count/cargo-generate.toml | 2 +- examples/word-count/noxfile.py | 8 ++++++++ examples/word-count/tox.ini | 5 ----- guide/src/parallelism.md | 2 +- noxfile.py | 6 ++++++ pyproject.toml | 3 ++- pytests/README.md | 2 +- pytests/pyo3-benchmarks/README.md | 4 ++-- pytests/pyo3-benchmarks/noxfile.py | 8 ++++++++ pytests/pyo3-benchmarks/tox.ini | 8 -------- pytests/pyo3-pytests/README.md | 4 ++-- pytests/pyo3-pytests/noxfile.py | 8 ++++++++ pytests/pyo3-pytests/tox.ini | 10 ---------- tox.ini | 14 -------------- xtask/src/main.rs | 17 ++++++++++++----- 32 files changed, 91 insertions(+), 93 deletions(-) create mode 100644 examples/decorator/noxfile.py delete mode 100644 examples/decorator/tox.ini create mode 100644 examples/maturin-starter/noxfile.py delete mode 100644 examples/maturin-starter/tox.ini create mode 100644 examples/setuptools-rust-starter/noxfile.py delete mode 100644 examples/setuptools-rust-starter/tox.ini create mode 100644 examples/word-count/noxfile.py delete mode 100644 examples/word-count/tox.ini create mode 100644 noxfile.py create mode 100644 pytests/pyo3-benchmarks/noxfile.py delete mode 100644 pytests/pyo3-benchmarks/tox.ini create mode 100644 pytests/pyo3-pytests/noxfile.py delete mode 100644 pytests/pyo3-pytests/tox.ini delete mode 100644 tox.ini diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2e6b5ad..8d3a8c43 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -206,11 +206,10 @@ jobs: - name: Test python examples and tests shell: bash run: | - python -m pip install -U pip tox + python -m pip install -U pip nox cargo xtask test-py env: CARGO_TARGET_DIR: ${{ github.workspace }} - TOX_TESTENV_PASSENV: "CARGO_BUILD_TARGET CARGO_TARGET_DIR" - name: Test cross compilation if: ${{ matrix.platform.os == 'ubuntu-latest' && matrix.python-version == '3.9' }} diff --git a/Cargo.toml b/Cargo.toml index ad70e70d..d88464fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/pyo3/pyo3" documentation = "https://docs.rs/crate/pyo3/" categories = ["api-bindings", "development-tools::ffi"] license = "Apache-2.0" -exclude = ["/.gitignore", ".cargo/config", "/codecov.yml", "/Makefile", "/pyproject.toml", "/tox.ini"] +exclude = ["/.gitignore", ".cargo/config", "/codecov.yml", "/Makefile", "/pyproject.toml", "/noxfile.py"] edition = "2018" links = "python" diff --git a/Makefile b/Makefile index 229575d0..5a6b6a18 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,8 @@ test: lint test_py cargo test --features="abi3 $(ALL_ADDITIVE_FEATURES)" test_py: - @for example in examples/*/tox.ini; do echo "-- Running tox for $$example --"; tox -e py -c $$example || exit 1; echo ""; done - @for package in pytests/*/tox.ini; do echo "-- Running tox for $$package --"; tox -e py -c $$package || exit 1; echo ""; done + @for example in examples/*/noxfile.py; do echo "-- Running nox for $$example --"; nox -f $$example/noxfile.py || exit 1; echo ""; done + @for package in pytests/*/noxfile.py; do echo "-- Running nox for $$package --"; nox -f $$package/noxfile.py || exit 1; echo ""; done fmt_py: black . --check @@ -35,7 +35,6 @@ coverage: bash -c "\ set -a\ source <(cargo llvm-cov show-env)\ - export TOX_TESTENV_PASSENV=*\ make test_py\ " cargo llvm-cov $(COVERAGE_PACKAGES) --no-run --summary-only diff --git a/examples/README.md b/examples/README.md index 1e135bf5..7b1bd4d4 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,6 +1,6 @@ # PyO3 Examples -These example crates are a collection of toy extension modules built with PyO3. They are all tested using `tox` in PyO3's CI. +These example crates are a collection of toy extension modules built with PyO3. They are all tested using `nox` in PyO3's CI. Below is a brief description of each of these: diff --git a/examples/decorator/README.md b/examples/decorator/README.md index 22c75cde..ccfb784d 100644 --- a/examples/decorator/README.md +++ b/examples/decorator/README.md @@ -18,10 +18,10 @@ maturin develop pytest ``` -Alternatively, install tox and run the tests inside an isolated environment: +Alternatively, install nox and run the tests inside an isolated environment: ```shell -tox -e py +nox ``` ## Copying this example diff --git a/examples/decorator/cargo-generate.toml b/examples/decorator/cargo-generate.toml index ffa474e1..a854f0c3 100644 --- a/examples/decorator/cargo-generate.toml +++ b/examples/decorator/cargo-generate.toml @@ -1,5 +1,5 @@ [template] -ignore = [".tox"] +ignore = [".tox", ".nox"] [hooks] pre = [".template/pre-script.rhai"] diff --git a/examples/decorator/noxfile.py b/examples/decorator/noxfile.py new file mode 100644 index 00000000..85316138 --- /dev/null +++ b/examples/decorator/noxfile.py @@ -0,0 +1,8 @@ +import nox + + +@nox.session +def python(session): + session.install("-rrequirements-dev.txt") + session.install(".") + session.run("pytest") diff --git a/examples/decorator/tox.ini b/examples/decorator/tox.ini deleted file mode 100644 index f03eeaa6..00000000 --- a/examples/decorator/tox.ini +++ /dev/null @@ -1,10 +0,0 @@ -[tox] -# can't install from sdist because local pyo3 repo can't be included in the sdist -skipsdist = true - -[testenv] -description = Run the unit tests under {basepython} -deps = -rrequirements-dev.txt -commands = - python -m pip install . - pytest {posargs} diff --git a/examples/maturin-starter/README.md b/examples/maturin-starter/README.md index 0959f60e..da1ee9e4 100644 --- a/examples/maturin-starter/README.md +++ b/examples/maturin-starter/README.md @@ -17,10 +17,10 @@ pip install -r requirements-dev.txt maturin develop && pytest ``` -Alternatively, install tox and run the tests inside an isolated environment: +Alternatively, install nox and run the tests inside an isolated environment: ```shell -tox -e py +nox ``` ## Copying this example diff --git a/examples/maturin-starter/cargo-generate.toml b/examples/maturin-starter/cargo-generate.toml index ffa474e1..a854f0c3 100644 --- a/examples/maturin-starter/cargo-generate.toml +++ b/examples/maturin-starter/cargo-generate.toml @@ -1,5 +1,5 @@ [template] -ignore = [".tox"] +ignore = [".tox", ".nox"] [hooks] pre = [".template/pre-script.rhai"] diff --git a/examples/maturin-starter/noxfile.py b/examples/maturin-starter/noxfile.py new file mode 100644 index 00000000..85316138 --- /dev/null +++ b/examples/maturin-starter/noxfile.py @@ -0,0 +1,8 @@ +import nox + + +@nox.session +def python(session): + session.install("-rrequirements-dev.txt") + session.install(".") + session.run("pytest") diff --git a/examples/maturin-starter/tox.ini b/examples/maturin-starter/tox.ini deleted file mode 100644 index f03eeaa6..00000000 --- a/examples/maturin-starter/tox.ini +++ /dev/null @@ -1,10 +0,0 @@ -[tox] -# can't install from sdist because local pyo3 repo can't be included in the sdist -skipsdist = true - -[testenv] -description = Run the unit tests under {basepython} -deps = -rrequirements-dev.txt -commands = - python -m pip install . - pytest {posargs} diff --git a/examples/setuptools-rust-starter/README.md b/examples/setuptools-rust-starter/README.md index 4e0276f4..86f1d460 100644 --- a/examples/setuptools-rust-starter/README.md +++ b/examples/setuptools-rust-starter/README.md @@ -17,10 +17,10 @@ pip install -r requirements-dev.txt python setup.py develop && pytest ``` -Alternatively, install tox and run the tests inside an isolated environment: +Alternatively, install nox and run the tests inside an isolated environment: ```shell -tox -e py +nox ``` ## Copying this example diff --git a/examples/setuptools-rust-starter/cargo-generate.toml b/examples/setuptools-rust-starter/cargo-generate.toml index ffa474e1..a854f0c3 100644 --- a/examples/setuptools-rust-starter/cargo-generate.toml +++ b/examples/setuptools-rust-starter/cargo-generate.toml @@ -1,5 +1,5 @@ [template] -ignore = [".tox"] +ignore = [".tox", ".nox"] [hooks] pre = [".template/pre-script.rhai"] diff --git a/examples/setuptools-rust-starter/noxfile.py b/examples/setuptools-rust-starter/noxfile.py new file mode 100644 index 00000000..fd5840dd --- /dev/null +++ b/examples/setuptools-rust-starter/noxfile.py @@ -0,0 +1,8 @@ +import nox + + +@nox.session +def python(session): + session.install("-rrequirements-dev.txt") + session.install("-e", ".") + session.run("pytest") diff --git a/examples/setuptools-rust-starter/tox.ini b/examples/setuptools-rust-starter/tox.ini deleted file mode 100644 index 2051de43..00000000 --- a/examples/setuptools-rust-starter/tox.ini +++ /dev/null @@ -1,5 +0,0 @@ -[testenv] -usedevelop = true -description = Run the unit tests under {basepython} -deps = -rrequirements-dev.txt -commands = pytest {posargs} diff --git a/examples/word-count/README.md b/examples/word-count/README.md index 2ff90910..42fa6c0e 100644 --- a/examples/word-count/README.md +++ b/examples/word-count/README.md @@ -35,10 +35,10 @@ pytest -v tests ## Testing -To test install tox globally and run +To test install nox globally and run ```shell -tox -e py +nox ``` ## Copying this example diff --git a/examples/word-count/cargo-generate.toml b/examples/word-count/cargo-generate.toml index ffa474e1..a854f0c3 100644 --- a/examples/word-count/cargo-generate.toml +++ b/examples/word-count/cargo-generate.toml @@ -1,5 +1,5 @@ [template] -ignore = [".tox"] +ignore = [".tox", ".nox"] [hooks] pre = [".template/pre-script.rhai"] diff --git a/examples/word-count/noxfile.py b/examples/word-count/noxfile.py new file mode 100644 index 00000000..fd5840dd --- /dev/null +++ b/examples/word-count/noxfile.py @@ -0,0 +1,8 @@ +import nox + + +@nox.session +def python(session): + session.install("-rrequirements-dev.txt") + session.install("-e", ".") + session.run("pytest") diff --git a/examples/word-count/tox.ini b/examples/word-count/tox.ini deleted file mode 100644 index 2051de43..00000000 --- a/examples/word-count/tox.ini +++ /dev/null @@ -1,5 +0,0 @@ -[testenv] -usedevelop = true -description = Run the unit tests under {basepython} -deps = -rrequirements-dev.txt -commands = pytest {posargs} diff --git a/guide/src/parallelism.md b/guide/src/parallelism.md index 30ae1c78..cdf2f9bd 100644 --- a/guide/src/parallelism.md +++ b/guide/src/parallelism.md @@ -56,7 +56,7 @@ We are using `pytest-benchmark` to benchmark four word count functions: 3. Rust sequential version 4. Rust sequential version executed twice with two Python threads -The benchmark script can be found [here](https://github.com/PyO3/pyo3/blob/main/examples/word-count/tests/test_word_count.py), and we can run `tox` in the `word-count` folder to benchmark these functions. +The benchmark script can be found [here](https://github.com/PyO3/pyo3/blob/main/examples/word-count/tests/test_word_count.py), and we can run `nox` in the `word-count` folder to benchmark these functions. While the results of the benchmark of course depend on your machine, the relative results should be similar to this (mid 2020): ```ignore diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 00000000..1a16da58 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,6 @@ +import nox + + +@nox.session(python=["3.7", "3.8", "3.9", "3.10"]) +def test(session): + session.run("cargo", "test", external=True) diff --git a/pyproject.toml b/pyproject.toml index 7822c2a7..e9e2104d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,10 +9,11 @@ exclude = ''' | \.git # root of the project | \.mypy_cache | \.tox + | \.nox | \.venv | venv | target | dist )/ ) -''' \ No newline at end of file +''' diff --git a/pytests/README.md b/pytests/README.md index 075ba7c1..7db3fabe 100644 --- a/pytests/README.md +++ b/pytests/README.md @@ -1,6 +1,6 @@ # PyO3 Python tests -These crates are a collection of test extension modules built with PyO3. They are all tested using `tox` in PyO3's CI. +These crates are a collection of test extension modules built with PyO3. They are all tested using `nox` in PyO3's CI. Below is a brief description of each of these: diff --git a/pytests/pyo3-benchmarks/README.md b/pytests/pyo3-benchmarks/README.md index 9bbc3040..5317d4ec 100644 --- a/pytests/pyo3-benchmarks/README.md +++ b/pytests/pyo3-benchmarks/README.md @@ -11,8 +11,8 @@ python setup.py develop pytest ``` -Or with tox: +Or with nox: ```shell -tox -e py +nox ``` diff --git a/pytests/pyo3-benchmarks/noxfile.py b/pytests/pyo3-benchmarks/noxfile.py new file mode 100644 index 00000000..bd40dc63 --- /dev/null +++ b/pytests/pyo3-benchmarks/noxfile.py @@ -0,0 +1,8 @@ +import nox + + +@nox.session +def python(session): + session.install("-rrequirements-dev.txt") + session.install("-e", ".") + session.run("pytest", "--benchmark-sort=name") diff --git a/pytests/pyo3-benchmarks/tox.ini b/pytests/pyo3-benchmarks/tox.ini deleted file mode 100644 index 635f66aa..00000000 --- a/pytests/pyo3-benchmarks/tox.ini +++ /dev/null @@ -1,8 +0,0 @@ -[testenv] -usedevelop = True -description = Run the unit tests under {basepython} -deps = -rrequirements-dev.txt -commands = pytest --benchmark-sort=name {posargs} -# Use recreate so that tox always rebuilds, otherwise changes to Rust are not -# picked up. -recreate = True diff --git a/pytests/pyo3-pytests/README.md b/pytests/pyo3-pytests/README.md index 89268d24..ddb9573b 100644 --- a/pytests/pyo3-pytests/README.md +++ b/pytests/pyo3-pytests/README.md @@ -12,8 +12,8 @@ maturin develop pytest ``` -Alternatively, install tox and run the tests inside an isolated environment: +Alternatively, install nox and run the tests inside an isolated environment: ```shell -tox -e py +nox ``` diff --git a/pytests/pyo3-pytests/noxfile.py b/pytests/pyo3-pytests/noxfile.py new file mode 100644 index 00000000..85316138 --- /dev/null +++ b/pytests/pyo3-pytests/noxfile.py @@ -0,0 +1,8 @@ +import nox + + +@nox.session +def python(session): + session.install("-rrequirements-dev.txt") + session.install(".") + session.run("pytest") diff --git a/pytests/pyo3-pytests/tox.ini b/pytests/pyo3-pytests/tox.ini deleted file mode 100644 index f03eeaa6..00000000 --- a/pytests/pyo3-pytests/tox.ini +++ /dev/null @@ -1,10 +0,0 @@ -[tox] -# can't install from sdist because local pyo3 repo can't be included in the sdist -skipsdist = true - -[testenv] -description = Run the unit tests under {basepython} -deps = -rrequirements-dev.txt -commands = - python -m pip install . - pytest {posargs} diff --git a/tox.ini b/tox.ini deleted file mode 100644 index a1cfba86..00000000 --- a/tox.ini +++ /dev/null @@ -1,14 +0,0 @@ -[tox] -envlist = py37, - py38, - py39, - py310, -minversion = 3.7.0 -skip_missing_interpreters = true - -[testenv] -description = Run the unit tests under {basepython} -skip_install = True -usedevelop = True -whitelist_externals = cargo -commands = cargo test diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 12814b14..e9fa71a2 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -58,14 +58,22 @@ fn run_python_tests<'a>( ) -> Result<()> { for entry in std::fs::read_dir("pytests")? { let path = entry?.path(); - if path.is_dir() && path.join("tox.ini").exists() { - run(Command::new("tox").arg("-c").arg(path).envs(env))?; + if path.is_dir() && path.join("noxfile.py").exists() { + run(Command::new("nox") + .arg("--non-interactive") + .arg("-f") + .arg(path.join("noxfile.py")) + .envs(env))?; } } for entry in std::fs::read_dir("examples")? { let path = entry?.path(); - if path.is_dir() && path.join("tox.ini").exists() { - run(Command::new("tox").arg("-c").arg(path).envs(env))?; + if path.is_dir() && path.join("noxfile.py").exists() { + run(Command::new("nox") + .arg("--non-interactive") + .arg("-f") + .arg(path.join("noxfile.py")) + .envs(env))?; } } Ok(()) @@ -81,7 +89,6 @@ fn get_coverage_env() -> Result> { env.insert(key.to_owned(), value.trim_matches('"').to_owned()); } - env.insert("TOX_TESTENV_PASSENV".to_owned(), "*".to_owned()); env.insert("RUSTUP_TOOLCHAIN".to_owned(), "nightly".to_owned()); Ok(env)