Skip to content

Commit 47fa062

Browse files
committed
Migrate PyRTL to uv. This has several advantages:
* The new workflow is about twice as fast as the old one on my computer. * `uv` manages installation of the appropriate versions of Python and all pip packages, greatly simplifying the creation of PyRTL development environments * This pins all developer tools to specific versions. Previously we only pinned documentation tools. This avoids confusing situations where lint errors suddenly appear just because a new version of `ruff` was released. To run all tests with the new workflow: ``` $ uv run just tests ``` To build documentation with the new workflow: ``` $ uv run just docs ``` This replaces the old `tox` based workflow with a new `just` based workflow. `tox` is no longer needed since `uv` manages all virtual environments. `just` is used instead, as a simple portable task runner.
1 parent 001fba1 commit 47fa062

13 files changed

Lines changed: 1257 additions & 199 deletions

.github/workflows/python-test.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,18 @@ on:
55
- pull_request
66

77
jobs:
8-
test:
8+
tests:
99
runs-on: ubuntu-latest
10-
strategy:
11-
matrix:
12-
# When changing the following line, be sure to update `envlist` in
13-
# tox.ini
14-
python-version: [3.9, 3.13]
1510

1611
steps:
1712
- uses: actions/checkout@v4
18-
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v5
13+
- uses: astral-sh/setup-uv@v6
2014
with:
21-
python-version: ${{ matrix.python-version }}
22-
- name: Install dependencies
23-
run: python3 -m pip install tox tox-gh-actions
24-
- name: Test with tox
25-
run: tox
15+
enable-cache: true
16+
- name: Install apt dependencies
17+
run: sudo apt install -y yosys
18+
- name: Run tests
19+
run: uv run just tests
2620
- name: Upload coverage to Codecov
2721
uses: codecov/codecov-action@v4
2822
env:

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

.readthedocs.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ build:
1111
tools:
1212
# Use the latest 3.x version available on Read the Docs.
1313
python: "3"
14-
apt_packages:
15-
- graphviz
14+
jobs:
15+
pre_create_environment:
16+
- asdf plugin add uv
17+
- asdf install uv latest
18+
- asdf global uv latest
19+
create_environment:
20+
- uv venv "${READTHEDOCS_VIRTUALENV_PATH}"
21+
install:
22+
- UV_PROJECT_ENVIRONMENT="${READTHEDOCS_VIRTUALENV_PATH}" uv sync --frozen
1623

1724
# Build documentation in the docs/ directory with Sphinx
1825
sphinx:
@@ -21,8 +28,3 @@ sphinx:
2128
# Optionally build your docs in additional formats such as PDF
2229
formats:
2330
- pdf
24-
25-
# Optionally set the requirements required to build your docs
26-
python:
27-
install:
28-
- requirements: docs/requirements.txt

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,36 @@ The package contains the following files and directories:
6868
* [`docs`](https://github.com/UCSBarchlab/PyRTL/tree/development/docs)
6969
Location of the Sphinx documentation.
7070

71-
Testing requires the Python packages `tox` and `pytest`, which are installed by
72-
`requirements.txt`. Once installed, a complete test of the system can be run with:
71+
### The PyRTL Development Environment
72+
73+
All PyRTL developers should use the exact same tools to avoid confusing
74+
situations where a test fails only on one person's computer, or the generated
75+
documentation looks weird on another person's computer.
76+
77+
PyRTL uses [`uv`](https://docs.astral.sh/uv/) to ensure everyone's development
78+
environments are consistent. `uv` manages the installation and versioning for
79+
all other PyRTL developer tools, like `pytest` and `ruff`.
80+
81+
So to set up a PyRTL development environment, you only need to install `uv`, by
82+
following the
83+
[`uv` installation instructions](https://docs.astral.sh/uv/getting-started/installation/)
84+
85+
After installing [`uv`](https://docs.astral.sh/uv/), you can run all the tests
86+
with:
7387

7488
```shell
75-
$ tox
89+
$ uv run just tests
7690
```
7791

78-
PyRTL's code is automatically formatted with `ruff`, also installed by
79-
`requirements.txt`. Reformat any changed code with:
92+
And you can generate the Sphinx documentation with:
8093

8194
```shell
82-
$ ruff format
95+
$ uv run just docs
8396
```
8497

98+
`uv` will download and install Python and any required `pip` packages as
99+
needed. `uv` caches installed software so future `uv` invocations will be fast.
100+
85101
### Contributing to PyRTL
86102

87103
*Picking a first project*

docs/Makefile

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/README.md

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,52 +52,16 @@ not worth showing in every example. These blocks look like:
5252
>>> pyrtl.reset_working_block()
5353
```
5454

55-
## Installing Sphinx
56-
57-
Sphinx and its dependencies are all pinned to specific versions for
58-
[reproducible documentation builds](https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html).
59-
This avoids problems where documentation builds randomly fail due to bugs or
60-
incompatibilities in the newest version of Sphinx or one of its
61-
dependencies.
62-
63-
Use of an environment manager like [`conda`](https://docs.conda.io/en/latest/)
64-
or [`virtualenv`](https://virtualenv.pypa.io/en/latest/) is strongly
65-
recommended. To install Sphinx locally, run the following commands from the
66-
repository root:
67-
68-
```shell
69-
# Install Sphinx.
70-
$ pip install --upgrade -r docs/requirements.txt
71-
```
72-
73-
## Installing Graphviz
74-
75-
[Install graphviz](https://www.graphviz.org/download/#executable-packages). Use
76-
of a package manager like
77-
[`apt`](https://ubuntu.com/server/docs/package-management) or
78-
[`brew`](https://brew.sh/) is strongly recommended. Instructions vary depending
79-
on your operating system, see the installation link for details.
80-
8155
## Running Sphinx
8256

83-
Run Sphinx with the provided [`docs/Makefile`](https://github.com/UCSBarchlab/PyRTL/blob/development/docs/Makefile):
57+
Run Sphinx with the provided
58+
[`justfile`](https://github.com/UCSBarchlab/PyRTL/blob/development/justfile),
59+
from the repository's root directory:
8460

8561
```shell
8662
# Run Sphinx to build PyRTL's documentation.
87-
$ make -C docs
88-
```
89-
90-
A local copy of PyRTL's documentation should be available in
91-
`docs/_build/html`. `docs/_build/html/index.html` is the home page.
92-
93-
## Updating Sphinx
94-
95-
To update the pinned version of Sphinx, run
96-
97-
```shell
98-
# Run pip-compile to generate docs/requirements.txt from docs/requirements.in.
99-
$ make -C docs requirements.txt
63+
$ uv run just docs
10064
```
10165

102-
It's a good idea to update the pinned version of Sphinx whenever you update the
103-
documentation.
66+
This builds a local copy of PyRTL's documentation in `docs/_build/html`.
67+
`docs/_build/html/index.html` is the home page.

docs/requirements.in

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/requirements.txt

Lines changed: 0 additions & 74 deletions
This file was deleted.

justfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# PyRTL uses `just` instead of `make` because:
2+
# * `make` is not installed by default on Windows.
3+
# * `uv` can install `just` on all supported platforms from PyPI.
4+
tests:
5+
# Run `pytest` with the latest version of Python supported by PyRTL,
6+
# which is the default for `uv`. The default is set with `uv python
7+
# pin` and written to `.python_version`.
8+
uv run pytest -n auto --cov=pyrtl --cov-report=xml
9+
10+
# Run `pytest` in an isolated virtual environment, with the earliest
11+
# version of Python supported by PyRTL.
12+
uv run --python=3.9 --isolated pytest -n auto
13+
14+
# Run `ruff format` to check that code is formatted properly.
15+
#
16+
# If this fails, try running
17+
#
18+
# $ uv run ruff format
19+
#
20+
# to automatically reformat any changed code.
21+
uv run ruff format --diff
22+
23+
# Run `ruff check` to check for lint errors.
24+
#
25+
# If this fails, try running
26+
#
27+
# $ uv run ruff check --fix
28+
#
29+
# to automatically apply fixes, when possible.
30+
uv run ruff check
31+
32+
docs:
33+
# Run `sphinx-build` to generate documentation.
34+
#
35+
# Output: docs/_build/html/index.html
36+
uv run sphinx-build -M html docs/ docs/_build

pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ classifiers = [
3737
"Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)",
3838
"Topic :: System :: Hardware",
3939
]
40+
dependencies = []
4041

4142
[project.optional-dependencies]
4243
# Required by `input_from_blif`.
@@ -112,3 +113,18 @@ ignore = [
112113
# `__all__` is not sorted
113114
"RUF022",
114115
]
116+
117+
[dependency-groups]
118+
dev = [
119+
"furo>=2025.9.25",
120+
"graphviz>=0.21",
121+
"pyparsing>=3.2.5",
122+
"pytest>=8.4.2",
123+
"pytest-cov>=7.0.0",
124+
"pytest-xdist>=3.8.0",
125+
"ruff>=0.14.2",
126+
"rust-just>=1.43.0",
127+
"sphinx>=7.4.7",
128+
"sphinx-autodoc-typehints>=2.3.0",
129+
"sphinx-copybutton>=0.5.2",
130+
]

0 commit comments

Comments
 (0)