Skip to content

Leverage uv for documentation in nox session #1420

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

Merged
merged 78 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
00eaf75
Modernize setup.py
IvanIsCoding Apr 6, 2025
576a886
Farewell to retworkx
IvanIsCoding Apr 6, 2025
1a15354
Add release note about retworkx removal
IvanIsCoding Apr 6, 2025
13cec34
Move even more data to pyproject.toml
IvanIsCoding Apr 6, 2025
e7d69d6
PEP 639 says this is deprecated
IvanIsCoding Apr 6, 2025
90112c6
Add dependency groups later
IvanIsCoding Apr 6, 2025
d569676
Move even from setup.py to pyproject.toml
IvanIsCoding Apr 6, 2025
fd814cb
Migrate all setup.py to pyproject.toml
IvanIsCoding Apr 6, 2025
ec03072
Move nox dependencies to pyproject.toml
IvanIsCoding Apr 6, 2025
caf72e6
Document new way to do debug builds now that we no longer use setup.py
IvanIsCoding Apr 6, 2025
ae29d4a
Better way to phrase the documentation
IvanIsCoding Apr 6, 2025
8b5532e
Remove duplicate section
IvanIsCoding Apr 6, 2025
51baa2e
Try updating setuptools for coverage job
IvanIsCoding Apr 6, 2025
a9fde4f
Add docs dependency group as well
IvanIsCoding Apr 6, 2025
b8e2efe
Make description the same as the paper
IvanIsCoding Apr 6, 2025
5f52826
This doesn't work yet
IvanIsCoding Apr 6, 2025
24334f2
Pin uv in CI
IvanIsCoding Apr 6, 2025
7205151
Make workflow work with newer Python versions
IvanIsCoding Apr 6, 2025
df87b8f
Pass frozen via environment variables
IvanIsCoding Apr 6, 2025
af22a8e
Update CONTRIBUTING.md to mention uv.lock procedures
IvanIsCoding Apr 6, 2025
91ee307
Explicitly install rustworkx and use debug mode
IvanIsCoding Apr 6, 2025
2f28c9e
Use multiple threads in sphinx
IvanIsCoding Apr 6, 2025
7cf5e4b
Don't make -j auto mandatory in CI
IvanIsCoding Apr 6, 2025
ca2263d
Document how to build faster in the guide
IvanIsCoding Apr 6, 2025
349f34b
Fix typo
IvanIsCoding Apr 6, 2025
b0eb530
Merge branch 'main' into modernize-setup
IvanIsCoding Apr 7, 2025
3c67cdb
Revert retworkx code
IvanIsCoding Apr 7, 2025
3177208
Say this will be the last retworkx release
IvanIsCoding Apr 7, 2025
d3c3d1e
Trying to make retworkx work
IvanIsCoding Apr 7, 2025
93fc909
retworkx has its own setup.py
IvanIsCoding Apr 7, 2025
9749294
Account for new directory when publishing
IvanIsCoding Apr 7, 2025
9cd1112
Document setuptools-rust
IvanIsCoding Apr 7, 2025
bbd37bc
Merge remote-tracking branch 'upstream/main' into modernize-setup
IvanIsCoding Apr 7, 2025
91f5f10
Merge branch 'modernize-setup' into new-uv-branch
IvanIsCoding Apr 7, 2025
87305de
Edit message saying it is the final release
IvanIsCoding Apr 7, 2025
f8e97dd
sunset -> retired
IvanIsCoding Apr 7, 2025
c85ed90
Endline
IvanIsCoding Apr 7, 2025
a49906a
Merge branch 'main' into modernize-setup
IvanIsCoding Apr 8, 2025
cd3849e
Merge branch 'modernize-setup' into new-uv-branch
IvanIsCoding Apr 8, 2025
d0e79da
Frozen is implied
IvanIsCoding Apr 8, 2025
3009010
Merge branch 'main' into modernize-setup
IvanIsCoding Apr 8, 2025
49df6ad
Merge branch 'main' into modernize-setup
IvanIsCoding Apr 9, 2025
23d306e
Merge branch 'main' into modernize-setup
IvanIsCoding Apr 10, 2025
1041709
Merge branch 'main' into modernize-setup
IvanIsCoding Apr 10, 2025
6ac2a82
Merge remote-tracking branch 'upstream/main' into new-uv-branch
IvanIsCoding Apr 12, 2025
6e88243
Merge branch 'main' into modernize-setup
IvanIsCoding Apr 12, 2025
8a894ad
Ensure setuptools-rust is up-to-date
IvanIsCoding Apr 13, 2025
bc17616
Use setuptools>=70.1.0 and remove wheel
IvanIsCoding Apr 13, 2025
2040aa1
Merge branch 'modernize-setup' into new-uv-branch
IvanIsCoding Apr 13, 2025
6979c6b
Merge branch 'main' into modernize-setup
IvanIsCoding Apr 18, 2025
979849c
Apply suggestions from code review
IvanIsCoding Apr 19, 2025
de999e1
Black
IvanIsCoding Apr 19, 2025
318f95e
Merge branch 'main' into modernize-setup
IvanIsCoding Apr 22, 2025
6fd352e
Merge branch 'main' into new-uv-branch
IvanIsCoding Apr 24, 2025
03408bf
Merge branch 'main' into modernize-setup
IvanIsCoding May 1, 2025
4cfa29c
Merge branch 'main' into new-uv-branch
IvanIsCoding May 2, 2025
112654b
Merge branch 'main' into modernize-setup
IvanIsCoding May 2, 2025
5444392
Merge branch 'modernize-setup' into new-uv-branch
IvanIsCoding May 2, 2025
e9a8cfe
Merge remote-tracking branch 'upstream/main' into new-uv-branch
IvanIsCoding May 5, 2025
03c42c7
Use dependency groups in CI
IvanIsCoding May 6, 2025
dcb4010
Merge branch 'dependency-groups' into new-uv-branch
IvanIsCoding May 6, 2025
51ddf4f
Trying a newer setup-tools
IvanIsCoding May 6, 2025
26002fb
Merge branch 'dependency-groups' into new-uv-branch
IvanIsCoding May 6, 2025
dc0c0ff
Fix coverage
IvanIsCoding May 6, 2025
b4b06fa
Merge branch 'dependency-groups' into new-uv-branch
IvanIsCoding May 6, 2025
85694e2
Merge branch 'main' into dependency-groups
IvanIsCoding May 6, 2025
3377305
Merge branch 'main' into new-uv-branch
IvanIsCoding May 6, 2025
e174a57
testinfra -> releaseinfra
IvanIsCoding May 7, 2025
39fb357
Merge branch 'dependency-groups' into new-uv-branch
IvanIsCoding May 7, 2025
2c48049
Pip 25.1 arrives by default on GitHub
IvanIsCoding May 8, 2025
334f24b
Merge branch 'dependency-groups' into new-uv-branch
IvanIsCoding May 8, 2025
57e5896
Merge remote-tracking branch 'upstream/main' into new-uv-branch
IvanIsCoding May 10, 2025
db87094
Fix py-project toml
IvanIsCoding May 10, 2025
7cea72b
Merge branch 'main' into new-uv-branch
IvanIsCoding May 11, 2025
5279876
Merge branch 'main' into new-uv-branch
IvanIsCoding May 17, 2025
c9304d3
Update uv in uv.lock
IvanIsCoding May 22, 2025
981fbf6
Use uv 0.7.8
IvanIsCoding May 24, 2025
d9d5ad0
Use uv 0.7.8 (pyproject.toml)
IvanIsCoding May 24, 2025
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
22 changes: 20 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ you'll want to run the test suite locally.

The easiest way to run the test suite is to use
[**Nox**](https://nox.thea.codes/en/stable/). You can install Nox
with pip: `pip install -U nox`. Nox provides several advantages, but the
with pip: `pip install -U "nox[uv]"`. 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
Nox will recompile rustworkx from source every time it is run even if there
Expand Down Expand Up @@ -302,13 +302,21 @@ update the code formatting to conform to the style.

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:
documentation in an isolated venv.

Our documentation setup requires that the [uv](https://github.com/astral-sh/uv)
backend for Nox is installed. That can be done with `pip install -U "nox[uv]"`.

You can run just the docs build with:
```
nox -e docs
```
which will output the html rendered documentation in `docs/build/html` which
you can view locally in a web browser.

> [!TIP]
> If you run `nox -e docs -- -j auto`, the documentation uses all CPUs and builds faster.

#### rustworkx-core documentation

To build the rustworkx-core documentation you will use rust-doc. You can do this
Expand All @@ -327,6 +335,16 @@ web browser by running:
cargo doc -p rustworkx-core --open
```

#### Updating documentation dependencies

The documentation workflow is currently our step with the most dependencies. Even
though `rustworkx` currently has very few Python dependencies, our documentation depends
on `sphinx` and many others. Therefore, `uv.lock` file contains a frozen list of what
can be used for the workflow.

If you need to add or remove dependencies, update `pyproject.toml` (specifically the `docs`
section in `dependency-groups`), and then run `uv sync --all-groups` to update `uv.lock`.

### Type Annotations

If you have added new methods, functions, or classes, and/or changed any
Expand Down
34 changes: 26 additions & 8 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
deps = nox.project.dependency_groups(pyproject, "test")
lint_deps = nox.project.dependency_groups(pyproject, "lint")
stubs_deps = nox.project.dependency_groups(pyproject, "stubs")
docs_deps = nox.project.dependency_groups(pyproject, "docs")

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

@nox.session(python=["3"])
# For uv environments, we keep the virtualenvs separate to avoid conflicts
@nox.session(python=["3"], venv_backend="uv", reuse_venv=False, default=False)
def docs(session):
install_rustworkx(session)
session.install(*docs_deps, "-c", "constraints.txt")
session.run("python", "-m", "ipykernel", "install", "--user")
session.run("jupyter", "kernelspec", "list")
session.env["UV_PROJECT_ENVIRONMENT"] = session.virtualenv.location
session.env["UV_FROZEN"] = "1"
# faster build as generating docs already takes some time and we discard the env
session.env["SETUPTOOLS_RUST_CARGO_PROFILE"] = "dev"
session.run("uv", "sync", "--only-group", "docs")
session.install(".")
session.run(
"uv", "run", "--", "python", "-m", "ipykernel", "install", "--user"
)
session.run("uv", "run", "jupyter", "kernelspec", "list")
session.chdir("docs")
session.run("sphinx-build", "-W", "-d", "build/.doctrees", "-b", "html", "source", "build/html", *session.posargs)
session.run(
"uv",
"run",
"sphinx-build",
"-W",
"-d",
"build/.doctrees",
"-b",
"html",
"source",
"build/html",
*session.posargs,
)

@nox.session(python=["3"])
@nox.session(python=["3"], default=False)
def docs_clean(session):
session.chdir("docs")
session.run("rm", "-rf", "build", "source/apiref", external=True)
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ build-backend = "setuptools.build_meta"
[dependency-groups]
testinfra = [
"nox==2025.5.1",
"uv==0.7.8",
]
test = [
"setuptools-rust",
Expand All @@ -94,11 +95,12 @@ docs = [
"pydot",
"pillow>=4.2.1",
"reno>=3.4.0",
"qiskit-sphinx-theme~=1.14.0rc1",
"qiskit-sphinx-theme==1.16.1",
"matplotlib>=3.4",
"sphinx-reredirects",
"sphinxemoji",
"ipykernel",
"lxml_html_clean",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this used for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently if you run nox -edocs with Python 3.13 it fails. I had to add this dependency to make it work.

It has to do with Python 3.13 resolving a newer lxml or something of sorts.

]
releaseinfra = [
"cibuildwheel==2.23.2",
Expand Down
Loading