Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Tox with Nox #861

Merged
merged 46 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3a1b2ac
Use nox
IvanIsCoding Apr 14, 2023
7e84def
Trying to fix nox
IvanIsCoding Apr 14, 2023
fb91487
Fix tests
IvanIsCoding Apr 14, 2023
2bbbb02
Minor items in lint
IvanIsCoding Apr 14, 2023
bff21e5
More nox details
IvanIsCoding Apr 14, 2023
a4c5773
Update Contributing.md
IvanIsCoding Apr 14, 2023
4967c9e
Add release notes
IvanIsCoding Apr 14, 2023
1b498d0
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Apr 14, 2023
1ac8aa8
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Jun 21, 2023
38584d3
Add scipy requirement to noxfile
IvanIsCoding Jun 21, 2023
d13a609
Merge branch 'main' into swap-nox-tox
IvanIsCoding Jun 23, 2023
891562f
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Sep 2, 2023
6f6e311
Move flake8 to pyproject.toml (against its will)
IvanIsCoding Sep 2, 2023
5dd0a7d
Revert RETWORKX_TEST_PRESERVE_IMAGES
IvanIsCoding Sep 2, 2023
9c8fd28
Running tox errors
IvanIsCoding Sep 2, 2023
afa4583
Capitalization
IvanIsCoding Sep 2, 2023
9cc214e
Try to make docs work
IvanIsCoding Sep 2, 2023
0582176
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Sep 12, 2023
01cee00
Edit error messages for tox
IvanIsCoding Sep 12, 2023
8a6109a
Add constraints to docs install
IvanIsCoding Sep 12, 2023
7290689
Include extras appropriately
IvanIsCoding Sep 12, 2023
eb62655
Add test_with_version
IvanIsCoding Sep 12, 2023
5451cc6
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Sep 17, 2023
dfe1cbe
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Sep 22, 2023
fb319da
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Oct 18, 2023
ddf2da8
Merge remote-tracking branch 'origin/main' into swap-nox-tox
IvanIsCoding Oct 18, 2023
28886d8
Switch lint to ruff
IvanIsCoding Oct 18, 2023
f2e1353
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Jan 9, 2024
206614b
Port some changes from nox to tox
IvanIsCoding Jan 9, 2024
6cdaf49
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Jan 11, 2024
e0cdfc6
Remove file that should not be there
IvanIsCoding Jan 13, 2024
a625ef8
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Jan 13, 2024
27a8f1f
Merge branch 'main' into swap-nox-tox
IvanIsCoding Jan 17, 2024
c9af9cc
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Jan 21, 2024
7701174
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Jan 21, 2024
6a87159
Incorporate recent changes into Nox
IvanIsCoding Jan 21, 2024
6112415
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Jan 24, 2024
703724f
Fix Noxfile
IvanIsCoding Jan 26, 2024
25f02ff
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Jan 28, 2024
62c7fef
Merge remote-tracking branch 'upstream/main' into swap-nox-tox
IvanIsCoding Mar 23, 2024
74eacd4
Revert tox usage
IvanIsCoding Mar 23, 2024
d980f26
Include Python 3.12
IvanIsCoding Mar 23, 2024
0f4b22a
Faster lint phase
IvanIsCoding Mar 23, 2024
4235ac1
Reuse install code
IvanIsCoding Mar 23, 2024
70e63de
Restore tox.ini and add print to the end of commands
mtreinish Mar 28, 2024
9d58cd8
Merge branch 'main' into swap-nox-tox
mtreinish Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U virtualenv setuptools wheel tox
pip install -U virtualenv setuptools wheel nox
sudo apt-get install graphviz pandoc
- name: Build docs
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U virtualenv setuptools wheel tox
pip install -U virtualenv setuptools wheel nox
sudo apt-get install graphviz pandoc
- name: Build docs
run: |
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ jobs:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.platform.rust-target }}
- name: 'Install dependencies'
run: python -m pip install --upgrade tox
run: python -m pip install --upgrade nox
- name: 'Install binary dependencies'
run: sudo apt-get install -y graphviz
if: runner.os == 'Linux'
- name: 'Run tests'
run: tox -epy
run: nox -e test
tests_stubs:
if: github.repository_owner == 'Qiskit'
needs: [tests]
Expand All @@ -114,9 +114,9 @@ jobs:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: 'Install dependencies'
run: python -m pip install --upgrade tox
run: python -m pip install --upgrade nox
- name: 'Run rustworkx stub tests'
run: tox -estubs
run: nox -estubs
coverage:
if: github.repository_owner == 'Qiskit'
needs: [tests]
Expand Down Expand Up @@ -179,9 +179,9 @@ jobs:
- name: Install binary deps
run: sudo apt-get install -y graphviz
- name: Install deps
run: pip install -U tox
run: pip install -U nox
- name: Build Docs
run: tox -edocs
run: nox -e docs
- uses: actions/upload-artifact@v4
with:
name: html_docs
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ docs/apiref/
docs/source/apiref/
docs/source/stubs/
.tox/
.nox/
retworkx/*.so
retworkx/*pyd
*.stestr/
Expand Down
55 changes: 32 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,37 @@ also run successfully. Before you open a new pull request for your change,
you'll want to run the test suite locally.

The easiest way to run the test suite is to use
[**tox**](https://tox.readthedocs.io/en/latest/#). You can install tox
with pip: `pip install -U tox`. Tox provides several advantages, but the
[**Nox**](https://nox.thea.codes/en/stable/). You can install Nox
with pip: `pip install -U nox`. Nox provides several advantages, but the
biggest one is that it builds an isolated virtualenv for running tests. This
means it does not pollute your system python when running. However, by default
tox will recompile rustworkx from source every time it is run even if there
Nox will recompile rustworkx from source every time it is run even if there
are no changes made to the rust code. To avoid this you can use the
`--skip-pkg-install` package if you'd like to rerun tests without recompiling.
Note, you only want to use this flag if you recently ran tox and there are no
`--no-install` package if you'd like to rerun tests without recompiling.
Note, you only want to use this flag if you recently ran Nox and there are no
rust code (or packaged python code) changes to the repo since then. Otherwise
the rustworkx package tox installs in it's virtualenv will be out of date (or
the rustworkx package Nox installs in it's virtualenv will be out of date (or
missing).

Note, if you run tests outside of tox that you can **not** run the tests from
Note, if you run tests outside of Nox that you can **not** run the tests from
the root of the repo, this is because rustworkx packaging shim will conflict
with imports from rustworkx the installed version of rustworkx (which contains
the compiled extension).

#### Running tests with a specific Python version

If you want to run the tests with a specific version of Python, use the `test_with_version`
target. For example, to launch a test with version 3.11 the command is:

```python
nox --python 3.11 -e test_with_version
```

#### Running subsets of tests

If you just want to run a subset of tests you can pass a selection regex to the
test runner. For example, if you want to run all tests that have "dag" in the
test id you can run: `tox -epy -- dag`. You can pass arguments directly to the
test id you can run: `nox -e test -- dag`. You can pass arguments directly to the
IvanIsCoding marked this conversation as resolved.
Show resolved Hide resolved
test runner after the bare `--`. To see all the options on test selection you
can refer to the stestr manual:

Expand All @@ -142,30 +151,30 @@ you can do this faster with the `-n`/`--no-discover` option. For example:

to run a module:
```
tox -epy -- -n test_max_weight_matching
nox -e test -- -n test_max_weight_matching
```
or to run the same module by path:
```
tox -epy -- -n graph/test_nodes.py
nox -e test -- -n graph/test_nodes.py
```
to run a class:
```
tox -epy -- -n graph.test_nodes.TestNodes
nox -e test -- -n graph.test_nodes.TestNodes
```
to run a method:
```
tox -epy -- -n graph.test_nodes.TestNodes.test_no_nodes
nox -e test -- -n graph.test_nodes.TestNodes.test_no_nodes
```

It's important to note that tox will be running from the `tests/` directory in
It's important to note that Nox will be running from the `tests/` directory in
the repo, so any paths you pass to the test runner via path need to be relative
to that directory.

#### Visualization Tests

When running the visualization tests, each test will generate a visualization
and only fail if an exception is raised by the call. Each test saves the output
image to the current working directory (which if running tests with `tox` is
image to the current working directory (which if running tests with `nox` is
`tests/`) to ensure the generated image is usable. However to not clutter the
system each test cleans up this generated image and by default a test run does
not include any way to view the images from the visualization tests.
Expand All @@ -177,7 +186,7 @@ skip the cleanup. This will enable you to look at the output image and ensure th
visualization is correct. For example, running:

```
RUSTWORKX_TEST_PRESERVE_IMAGES=1 tox -epy
RUSTWORKX_TEST_PRESERVE_IMAGES=1 nox -e test
```

will run the visualization tests and preserve the generated image files after
Expand Down Expand Up @@ -230,25 +239,25 @@ cargo clippy
Python is used primarily for tests and some small pieces of packaging
and namespace configuration code in the actual library.
[black](https://github.com/psf/black) and [flake8](https://flake8.pycqa.org/en/latest/) are used to enforce consistent
style in the python code in the repository. You can run them via tox using:
style in the python code in the repository. You can run them via Nox using:

```bash
tox -elint
nox -e lint
```

This will also run `cargo fmt` in check mode to ensure that you ran `cargo fmt`
and will fail if the Rust code doesn't conform to the style rules.

If black returns a code formatting error you can run `tox -eblack` to automatically
If black returns a code formatting error you can run `nox -e black` to automatically
update the code formatting to conform to the style.

### Building documentation

Just like with tests building documentation is done via tox. This will handle
Just like with tests building documentation is done via Nox. This will handle
compiling rustworkx, installing the python dependencies, and then building the
documentation in an isolated venv. You can run just the docs build with:
```
tox -edocs
nox -e docs
```
which will output the html rendered documentation in `docs/build/html` which
you can view locally in a web browser.
Expand Down Expand Up @@ -291,10 +300,10 @@ Having type annotations is very helpful for Python end-users. Adding
annotations lets users type check their code with [mypy](http://mypy-lang.org/),
which can be helpful for finding bugs when using rustworkx.

Just like with tests for the code, annotations are also tested via tox.
Just like with tests for the code, annotations are also tested via Nox.

```
tox -estubs
nox -e stubs
```

One important thing to note is that if you're adding a new function to the Rust
Expand Down Expand Up @@ -433,7 +442,7 @@ it has been tagged::

Building the release notes is part of the standard rustworkx documentation
builds. To check what the rendered html output of the release notes will look
like for the current state of the repo you can run: `tox -edocs` which will
like for the current state of the repo you can run: `nox -e docs` which will
build all the documentation into `docs/_build/html` and the release notes in
particular will be located at `docs/_build/html/release_notes.html`

Expand Down
78 changes: 78 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import nox

nox.options.reuse_existing_virtualenvs = True
nox.options.stop_on_first_error = True

deps = [
"setuptools-rust",
"fixtures",
"testtools>=2.5.0",
"networkx>=2.5",
"scipy>=1.7",
"stestr>=4.1",
]

lint_deps = [
"black~=22.0",
"ruff~=0.1",
"setuptools-rust",
]

stubs_deps = [
"mypy==1.8.0",
"typing-extensions",
]

def install_rustworkx(session):
session.install(*deps)
session.install(".[all]", "-c", "constraints.txt")

# We define a common base such that -e test triggers a test with the current
# Python version of the interpreter and -e test_with_version launches
# a test with the specified version of Python.
def base_test(session):
install_rustworkx(session)
session.chdir("tests")
session.run("python", "-m", "unittest", "discover", *session.posargs)

@nox.session(python=["3"])
def test(session):
base_test(session)

@nox.session(python=["3.8", "3.9", "3.10", "3.11", "3.12"])
def test_with_version(session):
base_test(session)

@nox.session(python=["3"])
def lint(session):
black(session)
session.install(*lint_deps)
session.run("ruff", "check", "rustworkx", "retworkx", "setup.py")
session.run("cargo", "fmt", "--all", "--", "--check", external=True)
session.run("python", "tools/find_stray_release_notes.py")

@nox.session(python=["3"])
def docs(session):
install_rustworkx(session)
session.install("-r", "docs/source/requirements.txt", "-c", "constraints.txt")
session.run("python", "-m", "ipykernel", "install", "--user")
session.run("jupyter", "kernelspec", "list")
session.chdir("docs")
session.run("sphinx-build", "-W", "-d", "build/.doctrees", "-b", "html", "source", "build/html", *session.posargs)

@nox.session(python=["3"])
def docs_clean(session):
session.chdir("docs")
session.run("rm", "-rf", "build", "source/apiref", external=True)

@nox.session(python=["3"])
def black(session):
session.install(*[d for d in lint_deps if "black" in d])
session.run("black", "rustworkx", "tests", "retworkx", *session.posargs)

@nox.session(python=["3"])
def stubs(session):
install_rustworkx(session)
session.install(*stubs_deps)
session.chdir("tests")
session.run("python", "-m", "mypy.stubtest", "--concise", "rustworkx")
6 changes: 6 additions & 0 deletions releasenotes/notes/swap-nox-tox-dea2bb14c400641c.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
other:
- |
Switched automated testing environment from
Tox to `Nox <https://nox.thea.codes/en/stable/>`__. This
change should not impact the end-user
2 changes: 1 addition & 1 deletion tools/build_documentation_dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
set -e

# Build the documentation.
RUSTWORKX_DEV_DOCS=1 tox -edocs
RUSTWORKX_DEV_DOCS=1 nox -e docs

# Copy the stable docs from the git repo
TMP_DIR=$(mktemp -d)
Expand Down
2 changes: 1 addition & 1 deletion tools/build_documentation_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
set -e

# Build the documentation.
tox -edocs
nox -edocs

# Extract the release version from Cargo.toml
VERSION=$(grep -Po -m1 'version = "\K[0-9]+\.[0-9]+' Cargo.toml)
Expand Down
16 changes: 13 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ passenv =
changedir = {toxinidir}/tests
commands =
python -m unittest discover {posargs}
python -c "print('\nrustworkx no longer supports tox. Please run the equivalent comand with nox:\n\n\tnox -e test\n')"

[testenv:lint]
basepython = python3
Expand All @@ -41,6 +42,8 @@ commands =
ruff check ../rustworkx ../retworkx . ../setup.py
cargo fmt --all -- --check
python {toxinidir}/tools/find_stray_release_notes.py
python -c "print('\nrustworkx no longer supports tox. Please run the equivalent comand with nox:\n\n\tnox -e lint\n')"


[testenv:docs]
basepython = python3
Expand All @@ -59,19 +62,24 @@ commands =
python -m ipykernel install --user
jupyter kernelspec list
sphinx-build -W -d {toxinidir}/docs/build/.doctrees -b html source build/html {posargs}
python -c "print('\nrustworkx no longer supports tox. Please run the equivalent comand with nox:\n\n\tnox -e docs\n')"

[testenv:docs-clean]
skip_install = true
deps =
allowlist_externals = rm
commands = rm -rf {toxinidir}/docs/build {toxinidir}/docs/source/apiref
commands =
rm -rf {toxinidir}/docs/build {toxinidir}/docs/source/apiref
python -c "print('\nrustworkx no longer supports tox. Please run the equivalent comand with nox:\n\n\tnox -e docs_clean\n')"

[testenv:black]
basepython = python3
skip_install = true
deps =
black~=22.0
commands = black {posargs} '../rustworkx' '../tests' '../retworkx'
commands =
black {posargs} '../rustworkx' '../tests' '../retworkx'
python -c "print('\nrustworkx no longer supports tox. Please run the equivalent comand with nox:\n\tnox -e black\n')"

[testenv:stubs]
basepython = python3
Expand All @@ -81,4 +89,6 @@ deps =
extras =
mpl
graphviz
commands = python -m mypy.stubtest --concise rustworkx
commands =
python -m mypy.stubtest --concise rustworkx
python -c "print('\nrustworkx no longer supports tox. Please run the equivalent comand with nox:\n\n\tnox -e stubs\n')"
Loading