Skip to content

Commit 1c06c9e

Browse files
authored
Migrate PyRTL to uv (#476)
* Migrate PyRTL to `uv`. This has several advantages: * The new workflow is significantly faster on my computer: ``` $ # New workflow $ uv run just tests ... real 0m11.830s user 1m31.411s sys 0m7.255s ``` ``` $ # Old workflow $ tox ... real 0m19.537s user 2m2.577s sys 0m7.972s ``` * `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 ``` To run both: ``` $ uv run just presubmit ``` 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 1c06c9e

File tree

16 files changed

+1279
-216
lines changed

16 files changed

+1279
-216
lines changed

.github/workflows/python-release.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@ jobs:
1818

1919
steps:
2020
- uses: actions/checkout@v4
21-
- name: Set up Python
22-
uses: actions/setup-python@v5
21+
- uses: astral-sh/setup-uv@v6
2322
with:
24-
python-version: "3.x"
25-
- name: Install pypa/build
26-
run: python3 -m pip install build
23+
enable-cache: true
2724
- name: Build distribution archives
28-
run: python3 -m build
25+
run: uv build
2926
- name: Upload distribution archives
3027
uses: actions/upload-artifact@v4
3128
with:

.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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ build:
1313
python: "3"
1414
apt_packages:
1515
- graphviz
16+
jobs:
17+
pre_create_environment:
18+
- asdf plugin add uv
19+
- asdf install uv latest
20+
- asdf global uv latest
21+
create_environment:
22+
- uv venv "${READTHEDOCS_VIRTUALENV_PATH}"
23+
install:
24+
- UV_PROJECT_ENVIRONMENT="${READTHEDOCS_VIRTUALENV_PATH}" uv sync --frozen
1625

1726
# Build documentation in the docs/ directory with Sphinx
1827
sphinx:
@@ -21,8 +30,3 @@ sphinx:
2130
# Optionally build your docs in additional formats such as PDF
2231
formats:
2332
- 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: 30 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*
@@ -123,6 +139,14 @@ $ ruff format
123139
* When pushing a fix to a bug or enhancement please reference issue number in
124140
commit message, e.g. [Fix to Issue
125141
#56](https://github.com/UCSBarchlab/PyRTL/commit/1d5730db168a9e4490c580cb930075715468047a)
142+
* Before sending a pull request, please run:
143+
144+
```shell
145+
$ uv run just presubmit
146+
```
147+
148+
to verify that all tests pass and that documentation can be generated with
149+
your changes.
126150

127151
*Documentation*
128152

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/release/README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,21 @@ commands.
124124

125125
### Manual build
126126

127-
1. Update build tools:
128-
```shell
129-
$ pip install --upgrade -r release/requirements.txt
130-
```
131-
2. Build distribution archive:
132-
```shell
133-
$ python3 -m build
134-
```
135-
This produces two files in `dist/`: a `.whl` file and a `.tar.gz` file.
127+
Build distribution archive:
128+
129+
```shell
130+
$ uv build
131+
```
132+
133+
This produces two files in `dist/`: a `.whl` file and a `.tar.gz` file.
136134

137135
### Manual publish on TestPyPI
138136

139137
1. If necessary, create a TestPyPI API token, by going to
140138
https://test.pypi.org/manage/account/ and clicking 'Add API token'.
141139
2. Upload distribution archive to TestPyPI:
142140
```shell
143-
$ twine upload --repository testpypi dist/*
141+
$ uv run --with twine twine upload --repository testpypi dist/*
144142
```
145143
3. Enter your API token when prompted.
146144
4. Check the new release's status at https://test.pypi.org/project/pyrtl/#history
@@ -156,7 +154,7 @@ commands.
156154
https://pypi.org/manage/account/ and clicking 'Add API token'.
157155
2. Upload distribution archive to PyPI:
158156
```shell
159-
$ twine upload dist/*
157+
$ uv run --with twine twine upload dist/*
160158
```
161159
3. Enter your API token when prompted.
162160
4. Check the new release's status at https://pypi.org/project/pyrtl/#history

docs/release/requirements.txt

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

docs/requirements.in

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

0 commit comments

Comments
 (0)