Skip to content

Commit 03799b3

Browse files
Leverage uv for documentation in nox session (#1420)
* Modernize setup.py * Farewell to retworkx * Add release note about retworkx removal * Move even more data to pyproject.toml * PEP 639 says this is deprecated * Add dependency groups later * Move even from setup.py to pyproject.toml * Migrate all setup.py to pyproject.toml * Move nox dependencies to pyproject.toml * Document new way to do debug builds now that we no longer use setup.py * Better way to phrase the documentation * Remove duplicate section * Try updating setuptools for coverage job * Add docs dependency group as well * Make description the same as the paper * This doesn't work yet * Pin uv in CI * Make workflow work with newer Python versions * Pass frozen via environment variables * Update CONTRIBUTING.md to mention uv.lock procedures * Explicitly install rustworkx and use debug mode * Use multiple threads in sphinx * Don't make -j auto mandatory in CI * Document how to build faster in the guide * Fix typo * Revert retworkx code * Say this will be the last retworkx release * Trying to make retworkx work * retworkx has its own setup.py * Account for new directory when publishing * Document setuptools-rust * Edit message saying it is the final release * sunset -> retired * Endline * Frozen is implied * Ensure setuptools-rust is up-to-date * Use setuptools>=70.1.0 and remove wheel * Apply suggestions from code review Co-authored-by: Matthew Treinish <[email protected]> * Black * Use dependency groups in CI * Trying a newer setup-tools * Fix coverage * testinfra -> releaseinfra * Pip 25.1 arrives by default on GitHub * Fix py-project toml * Update uv in uv.lock * Use uv 0.7.8 * Use uv 0.7.8 (pyproject.toml) --------- Co-authored-by: Matthew Treinish <[email protected]>
1 parent 408397f commit 03799b3

File tree

4 files changed

+3215
-11
lines changed

4 files changed

+3215
-11
lines changed

CONTRIBUTING.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ you'll want to run the test suite locally.
111111
112112
The easiest way to run the test suite is to use
113113
[**Nox**](https://nox.thea.codes/en/stable/). You can install Nox
114-
with pip: `pip install -U nox`. Nox provides several advantages, but the
114+
with pip: `pip install -U "nox[uv]"`. Nox provides several advantages, but the
115115
biggest one is that it builds an isolated virtualenv for running tests. This
116116
means it does not pollute your system python when running. However, by default
117117
Nox will recompile rustworkx from source every time it is run even if there
@@ -302,13 +302,21 @@ update the code formatting to conform to the style.
302302
303303
Just like with tests building documentation is done via Nox. This will handle
304304
compiling rustworkx, installing the python dependencies, and then building the
305-
documentation in an isolated venv. You can run just the docs build with:
305+
documentation in an isolated venv.
306+
307+
Our documentation setup requires that the [uv](https://github.com/astral-sh/uv)
308+
backend for Nox is installed. That can be done with `pip install -U "nox[uv]"`.
309+
310+
You can run just the docs build with:
306311
```
307312
nox -e docs
308313
```
309314
which will output the html rendered documentation in `docs/build/html` which
310315
you can view locally in a web browser.
311316
317+
> [!TIP]
318+
> If you run `nox -e docs -- -j auto`, the documentation uses all CPUs and builds faster.
319+
312320
#### rustworkx-core documentation
313321
314322
To build the rustworkx-core documentation you will use rust-doc. You can do this
@@ -327,6 +335,16 @@ web browser by running:
327335
cargo doc -p rustworkx-core --open
328336
```
329337
338+
#### Updating documentation dependencies
339+
340+
The documentation workflow is currently our step with the most dependencies. Even
341+
though `rustworkx` currently has very few Python dependencies, our documentation depends
342+
on `sphinx` and many others. Therefore, `uv.lock` file contains a frozen list of what
343+
can be used for the workflow.
344+
345+
If you need to add or remove dependencies, update `pyproject.toml` (specifically the `docs`
346+
section in `dependency-groups`), and then run `uv sync --all-groups` to update `uv.lock`.
347+
330348
### Type Annotations
331349
332350
If you have added new methods, functions, or classes, and/or changed any

noxfile.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
deps = nox.project.dependency_groups(pyproject, "test")
99
lint_deps = nox.project.dependency_groups(pyproject, "lint")
1010
stubs_deps = nox.project.dependency_groups(pyproject, "stubs")
11-
docs_deps = nox.project.dependency_groups(pyproject, "docs")
1211

1312
def install_rustworkx(session):
1413
session.install(*deps)
@@ -39,16 +38,35 @@ def lint(session):
3938
session.run("cargo", "fmt", "--all", "--", "--check", external=True)
4039
session.run("python", "tools/find_stray_release_notes.py")
4140

42-
@nox.session(python=["3"])
41+
# For uv environments, we keep the virtualenvs separate to avoid conflicts
42+
@nox.session(python=["3"], venv_backend="uv", reuse_venv=False, default=False)
4343
def docs(session):
44-
install_rustworkx(session)
45-
session.install(*docs_deps, "-c", "constraints.txt")
46-
session.run("python", "-m", "ipykernel", "install", "--user")
47-
session.run("jupyter", "kernelspec", "list")
44+
session.env["UV_PROJECT_ENVIRONMENT"] = session.virtualenv.location
45+
session.env["UV_FROZEN"] = "1"
46+
# faster build as generating docs already takes some time and we discard the env
47+
session.env["SETUPTOOLS_RUST_CARGO_PROFILE"] = "dev"
48+
session.run("uv", "sync", "--only-group", "docs")
49+
session.install(".")
50+
session.run(
51+
"uv", "run", "--", "python", "-m", "ipykernel", "install", "--user"
52+
)
53+
session.run("uv", "run", "jupyter", "kernelspec", "list")
4854
session.chdir("docs")
49-
session.run("sphinx-build", "-W", "-d", "build/.doctrees", "-b", "html", "source", "build/html", *session.posargs)
55+
session.run(
56+
"uv",
57+
"run",
58+
"sphinx-build",
59+
"-W",
60+
"-d",
61+
"build/.doctrees",
62+
"-b",
63+
"html",
64+
"source",
65+
"build/html",
66+
*session.posargs,
67+
)
5068

51-
@nox.session(python=["3"])
69+
@nox.session(python=["3"], default=False)
5270
def docs_clean(session):
5371
session.chdir("docs")
5472
session.run("rm", "-rf", "build", "source/apiref", external=True)

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ build-backend = "setuptools.build_meta"
6969
[dependency-groups]
7070
testinfra = [
7171
"nox==2025.5.1",
72+
"uv==0.7.8",
7273
]
7374
test = [
7475
"setuptools-rust",
@@ -94,11 +95,12 @@ docs = [
9495
"pydot",
9596
"pillow>=4.2.1",
9697
"reno>=3.4.0",
97-
"qiskit-sphinx-theme~=1.14.0rc1",
98+
"qiskit-sphinx-theme==1.16.1",
9899
"matplotlib>=3.4",
99100
"sphinx-reredirects",
100101
"sphinxemoji",
101102
"ipykernel",
103+
"lxml_html_clean",
102104
]
103105
releaseinfra = [
104106
"cibuildwheel==2.23.2",

0 commit comments

Comments
 (0)