Skip to content

Commit 3b166e3

Browse files
authored
ci: use uv, require recent nox (#394)
* ci: try using a bit of uv Signed-off-by: Henry Schreiner <[email protected]> * chore: use uv if available in noxfile Signed-off-by: Henry Schreiner <[email protected]> * docs: add mentions of uv and pixi Signed-off-by: Henry Schreiner <[email protected]> * Update docs/pages/tutorials/dev-environment.md --------- Signed-off-by: Henry Schreiner <[email protected]>
1 parent e5f1fd7 commit 3b166e3

File tree

6 files changed

+107
-25
lines changed

6 files changed

+107
-25
lines changed

.github/workflows/reusable-cookie.yml

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ jobs:
3737
python-version: ${{ matrix.python-version }}
3838
allow-prereleases: true
3939

40+
- name: Setup uv
41+
uses: yezz123/setup-uv@v4
42+
with:
43+
uv-venv: ".venv"
44+
4045
- name: Install nox
41-
run: pip install nox
46+
run: uv pip install nox
4247

4348
- name: Test setuptools
4449
run: nox -s 'tests(setuptools, novcs)' -s 'tests(setuptools, vcs)'
@@ -97,64 +102,77 @@ jobs:
97102
steps:
98103
- uses: actions/checkout@v4
99104

105+
- uses: actions/setup-python@v5
106+
with:
107+
python-version: ${{ matrix.python-version }}
108+
allow-prereleases: true
109+
110+
- name: Setup uv
111+
uses: yezz123/setup-uv@v4
112+
with:
113+
uv-venv: ".venv"
114+
115+
- name: Install nox
116+
run: uv pip install nox
117+
100118
- name: Test setuptools
101119
run: |
102-
pipx run nox -s 'nox(setuptools, vcs)'
103-
pipx run nox -s 'nox(setuptools, vcs)' -- docs
120+
nox -s 'nox(setuptools, vcs)'
121+
nox -s 'nox(setuptools, vcs)' -- docs
104122
105123
- name: Test pybind11
106124
run: |
107-
pipx run nox -s 'nox(pybind11, vcs)'
108-
pipx run nox -s 'nox(pybind11, vcs)' -- docs
125+
nox -s 'nox(pybind11, vcs)'
126+
nox -s 'nox(pybind11, vcs)' -- docs
109127
110128
- name: Test scikit-build
111129
run: |
112-
pipx run nox -s 'nox(skbuild, vcs)'
113-
pipx run nox -s 'nox(skbuild, vcs)' -- docs
130+
nox -s 'nox(skbuild, vcs)'
131+
nox -s 'nox(skbuild, vcs)' -- docs
114132
115133
- name: Test poetry
116134
run: |
117-
pipx run nox -s 'nox(poetry, novcs)'
118-
pipx run nox -s 'nox(poetry, novcs)' -- docs
135+
nox -s 'nox(poetry, novcs)'
136+
nox -s 'nox(poetry, novcs)' -- docs
119137
120138
- name: Test flit
121139
run: |
122-
pipx run nox -s 'nox(flit, novcs)'
123-
pipx run nox -s 'nox(flit, novcs)' -- docs
140+
nox -s 'nox(flit, novcs)'
141+
nox -s 'nox(flit, novcs)' -- docs
124142
125143
- name: Test pdm
126144
run: |
127-
pipx run nox -s 'nox(pdm, vcs)'
128-
pipx run nox -s 'nox(pdm, vcs)' -- docs
145+
nox -s 'nox(pdm, vcs)'
146+
nox -s 'nox(pdm, vcs)' -- docs
129147
130148
- name: Test whey
131149
run: |
132-
pipx run nox -s 'nox(whey, novcs)'
133-
pipx run nox -s 'nox(whey, novcs)' -- docs
150+
nox -s 'nox(whey, novcs)'
151+
nox -s 'nox(whey, novcs)' -- docs
134152
135153
- name: Test maturin
136154
run: |
137-
pipx run nox -s 'nox(maturin, novcs)'
138-
pipx run nox -s 'nox(maturin, novcs)' -- docs
155+
nox -s 'nox(maturin, novcs)'
156+
nox -s 'nox(maturin, novcs)' -- docs
139157
140158
- name: Test hatch
141159
run: |
142-
pipx run nox -s 'nox(hatch, vcs)'
143-
pipx run nox -s 'nox(hatch, vcs)' -- docs
160+
nox -s 'nox(hatch, vcs)'
161+
nox -s 'nox(hatch, vcs)' -- docs
144162
145163
- name: Test setuptools PEP 621
146164
run: |
147-
pipx run nox -s 'nox(setuptools621, vcs)'
148-
pipx run nox -s 'nox(setuptools621, vcs)' -- docs
165+
nox -s 'nox(setuptools621, vcs)'
166+
nox -s 'nox(setuptools621, vcs)' -- docs
149167
150168
- name: Activate MSVC for Meson
151169
if: runner.os == 'Windows'
152170
uses: ilammy/msvc-dev-cmd@v1
153171

154172
- name: Test meson-python
155173
run: |
156-
pipx run nox -s 'nox(mesonpy, novcs)'
157-
pipx run nox -s 'nox(mesonpy, novcs)' -- docs
174+
nox -s 'nox(mesonpy, novcs)'
175+
nox -s 'nox(mesonpy, novcs)' -- docs
158176
159177
dist:
160178
name: Distribution build

docs/pages/guides/gha_basic.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,21 @@ And many other useful ones:
261261
built-in caching.
262262
- [conda-incubator/setup-miniconda](https://github.com/conda-incubator/setup-miniconda):
263263
Setup conda or mamba on GitHub Actions.
264+
- [prefix-dev/setup-pixi](https://github.com/prefix-dev/setup-pixi): Set up pixi
265+
and install your environment(s). Try `cache: false` if saving/loading the
266+
cache is slow.
264267
- [ruby/setup-ruby](https://github.com/ruby/setup-ruby): Setup Ruby if you need
265268
it for something.
266269
- [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request):
267270
Make a new PR with the current changes (more options than just using `gh`).
268271
You can even auto-merge PRs with `run: gh pr merge --merge --auto "1"`
269272
afterwards.
273+
- [yezz123/setup-uv](https://github.com/yezz123/setup-uv): Set up `uv`. Has a
274+
handy `uv-venv` option that will also set up and activate a virtual
275+
environment for you.
276+
- [gautamkrishnar/keepalive-workflow](https://github.com/gautamkrishnar/keepalive-workflow):
277+
Keep GitHub actions alive for more than 60 days. Not usually needed if you've
278+
set up the other suggestions here, like dependabot and pre-commit.
270279

271280
A couple more from Python developers; note these do not provide `vX` moving tags
272281
like the official actions and most other actions, but instead have `release/vX`
@@ -276,6 +285,8 @@ branches that you can use.
276285
Publish Python packages to PyPI. Supports trusted publisher deployment.
277286
- [re-actors/alls-green](https://github.com/re-actors/alls-green): Tooling to
278287
check to see if all jobs passed (supports allowed failures, too).
288+
- [sigstore/gh-action-sigstore-python](https://github.com/sigstore/gh-action-sigstore-python):
289+
Signing files in GitHub Actions with sigstore.
279290

280291
There are also a few useful tools installed which can really simplify your
281292
workflow or adding custom actions. This includes system package managers (like

docs/pages/guides/tasks.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ action:
8080
8181
You can now access all current versions of Python from nox. At least in GitHub
8282
Actions, you should add `--forcecolor` to your nox runs to get color output in
83-
your logs, or set `env: FORCE_COLOR: 3`. If you'd like to customise the versions
83+
your logs, or set `env: FORCE_COLOR: 3`. If you'd like to customize the versions
8484
of Python prepared for you, then use input like this:
8585

8686
```yaml
@@ -314,6 +314,36 @@ def build(session: nox.Session) -> None:
314314
<!-- prettier-ignore-end -->
315315
<!-- [[[end]]] -->
316316

317+
(Removing the build directory is helpful for setuptools)
318+
319+
### Faster with uv
320+
321+
The [uv](https://github.com/astral-sh/uv) project is a Rust reimplementation of
322+
pip, pip-tools, and venv that is very, very fast. You can tell nox to use `uv`
323+
if it is on your system by adding the following to your `noxfile.py`:
324+
325+
```python
326+
nox.needs_version = ">=2024.3.2"
327+
nox.options.default_venv_backend = "uv|virtualenv"
328+
```
329+
330+
You can install `uv` with `pipx`, `brew`, etc. If you want to use uv in GitHub
331+
Actions, one way is to use this:
332+
333+
```yaml
334+
- name: Setup uv
335+
uses: yezz123/setup-uv@v4
336+
```
337+
338+
You do not need to set `with: uv-venv: ".venv"` for `nox` to be able to use
339+
`uv`.
340+
341+
Check your jobs with `uv`; most things do not need to change. The main
342+
difference is `uv` doesn't install `pip` unless you ask it to. If you want to
343+
interact with uv, nox might be getting uv from it's environment instead of the
344+
system environment, so you can install `uv` if `shutil.which("uv")` returns
345+
`None`.
346+
317347
### Examples
318348

319349
A standard

docs/pages/tutorials/dev-environment.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ leave the environment (or just close your shell).
8787
> If you like a different shell, like fish, there are several `activate`
8888
> scripts; the default one expects a bash-like shell.
8989
90+
{: .note-title }
91+
92+
> Fast alternative
93+
>
94+
> You can also consider the [uv][] package, which is much, much faster version
95+
> of pip and venv implemented in Rust. Just put `uv` in front of the commands
96+
> you'd normally use; as long as you use venvs, it should be nearly the same.
97+
98+
[uv]: https://github.com/astral-sh/uv
99+
90100
### Option 2: Using conda
91101

92102
You can also develop in conda. This is an especially good option if:
@@ -113,6 +123,16 @@ conda activate env_name
113123

114124
To deactivate, use `conda deactivate`, or leave your shell.
115125

126+
> Modern faster alternative
127+
>
128+
> You can also consider the [pixi][] package, which is much, much faster version
129+
> of conda implemented in Rust. It has been completely redesigned to work around
130+
> projects with a `pixi.toml` file instead of global environments. It's a new
131+
> way to work (more similar to pdm/hatch/poetry from Python), but very powerful
132+
> if you learn it.
133+
134+
[pixi]: https://pixi.sh
135+
116136
## Choosing an Editor
117137

118138
Any plain text editor will serve our purposes for this guide. Bare bones editors

noxfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424

2525
import nox
2626

27-
nox.needs_version = ">=2022.1.7"
27+
nox.needs_version = ">=2024.3.2"
2828
nox.options.sessions = ["rr_lint", "rr_tests", "rr_pylint", "readme"]
29+
nox.options.default_venv_backend = "uv|virtualenv"
2930

3031
DIR = Path(__file__).parent.resolve()
3132
with DIR.joinpath("cookiecutter.json").open() as f:

{{cookiecutter.project_name}}/noxfile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
{% endif -%}
1515

16+
nox.needs_version = ">=2024.3.2"
1617
nox.options.sessions = ["lint", "pylint", "tests"]
18+
nox.options.default_venv_backend = "uv|virtualenv"
1719

1820

1921
@nox.session

0 commit comments

Comments
 (0)