Skip to content

Commit a63ec1f

Browse files
Migrate from rye to uv (#11)
Key changes: - Instead of a single top-level workspace, we go for one workspace per exercise - All exercises now require Python 3.13+ and `maturin` 1.8+ - We use the `dev` profile when building Rust extensions
1 parent a9dff83 commit a63ec1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1723
-567
lines changed

.python-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

.wr.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
command = "cargo"
33
args = ["test"]
44

5-
# Faster feedback than `rye build`
65
[[verification]]
7-
command = "maturin"
8-
args = ["develop"]
6+
command = "uv"
7+
# We use `--all-packages` to avoid having to specify `pytest` as a dev
8+
# dependency in all packages.
9+
args = ["sync", "--all-packages"]
910

1011
[[verification]]
11-
command = "rye"
12-
args = ["test", "--pyproject", "sample/pyproject.toml"]
12+
command = "uv"
13+
args = ["run", "pytest"]

Cargo.lock

Lines changed: 0 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["exercises/*/*", "patcher"]
2+
members = ["exercises/*/*"]
33
resolver = "2"
44

55
[workspace.dependencies]

book/src/01_intro/00_welcome.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ also find solutions to all exercises in the
2727
To follow this course, you must install:
2828

2929
- [Rust](https://www.rust-lang.org/tools/install)
30-
- [`rye`](https://rye.astral.sh/), a Python package manager
30+
- [`uv`](https://docs.astral.sh/uv/), a Python package manager
3131

3232
If Rust is already installed on your machine, make sure to update it to the latest version:
3333

@@ -41,7 +41,7 @@ These commands should successfully run on your machine:
4141

4242
```bash
4343
cargo --version
44-
rye --version
44+
uv --version
4545
```
4646

4747
Don't start the course until you have these tools installed and working.

book/src/01_intro/01_setup.md

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ To invoke Rust code from Python we need to create a **Python extension module**.
2020
We'll use `maturin` to build, package and publish Python extensions written in Rust. Let's install it:
2121

2222
```bash
23-
rye install "maturin>=1.6"
23+
uv tool install "maturin>=1.8"
2424
```
2525

26+
Tools installed via `uv` should be available in your path. Run:
27+
28+
```bash
29+
uv tool update-shell
30+
```
31+
32+
to make sure that's the case.
33+
2634
## Exercise structure
2735

2836
All exercises in this course will follow the same structure:
@@ -153,20 +161,20 @@ Before we move on, let's take a look at `pyproject.toml`, the Python "manifest"
153161

154162
```toml
155163
[build-system]
156-
requires = ["maturin>=1.6,<2.0"]
164+
requires = ["maturin>=1.8,<2.0"]
157165
build-backend = "maturin"
158166

159167
[project]
160168
name = "setup"
161169
# [...]
162-
requires-python = ">=3.8"
163-
dynamic = ["version"]
170+
requires-python = ">=3.13"
171+
164172
[tool.maturin]
165173
features = ["pyo3/extension-module"]
166174
```
167175

168176
It specifies the build system, the extension name and version, the required Python version, and the features to enable when building the extension module.
169-
This is what `rye` looks at when building the extension module, before delegating the build
177+
This is what `uv` looks at when building the extension module, before delegating the build
170178
process to `maturin`, which in turn invokes `cargo` to compile the Rust code.
171179

172180
## What do I need to do?
@@ -177,35 +185,6 @@ that you can build and test a Python extension module without issues.
177185

178186
Things will get a lot more interesting over the coming sections, I promise!
179187

180-
## Troubleshooting
181-
182-
You may run into this error when using `rye` and `pyo3` together:
183-
184-
```plaintext
185-
<compiler output>
186-
= note: ld: warning: search path '/install/lib' not found
187-
ld: library 'python3.12' not found
188-
clang: error: linker command failed with exit code 1
189-
```
190-
191-
This seems to be a [bug in `rye`](https://github.com/astral-sh/rye/issues/1050#issuecomment-2079270180).\
192-
To work around the issue, run the following command in the root of the course repository:
193-
194-
```bash
195-
cargo run -p "patcher"
196-
```
197-
198-
`wr` should now be able to build the extension module without issues and run the tests. No linker errors
199-
should be surfaced.
200-
201-
<div class="warning">
202-
203-
The `patcher` tool is a temporary workaround for a bug in `rye`.\
204-
It hasn't been tested on Windows: please [open an issue](https://github.com/mainmatter/rust-python-interoperability/issues)
205-
if you encounter any problems.
206-
207-
</div>
208-
209188
## References
210189

211190
- [Linking artifacts together (Rust compiler documentation)](https://doc.rust-lang.org/reference/linkage.html)

exercises/01_intro/00_welcome/.wr.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ command = "cargo"
33
args = ["test"]
44

55
[[verification]]
6-
command = "rye"
6+
command = "uv"
77
args = ["sync"]

exercises/01_intro/00_welcome/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ mod tests {
2929
}
3030

3131
#[test]
32-
fn rye_is_installed_and_on_path() {
33-
let output = std::process::Command::new("rye")
32+
fn uv_is_installed_and_on_path() {
33+
let output = std::process::Command::new("uv")
3434
.arg("--version")
3535
.output()
36-
.expect("Failed to run rye");
36+
.expect("Failed to run uv");
3737

3838
assert!(
3939
output.status.success(),
40-
"`rye --version` failed:\n{}",
40+
"`uv --version` failed:\n{}",
4141
String::from_utf8_lossy(&output.stderr)
4242
);
4343
}
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
[build-system]
2-
requires = ["maturin>=1.6,<2.0"]
2+
requires = ["maturin>=1.8,<2.0"]
33
build-backend = "maturin"
44

55
[project]
66
name = "setup"
7-
requires-python = ">=3.8"
7+
requires-python = ">=3.11"
88
classifiers = [
99
"Programming Language :: Rust",
1010
"Programming Language :: Python :: Implementation :: CPython",
1111
"Programming Language :: Python :: Implementation :: PyPy",
1212
]
13-
dynamic = ["version"]
13+
version = "0.1.0"
14+
1415
[tool.maturin]
1516
features = ["pyo3/extension-module"]
17+
18+
[tool.uv.config-settings]
19+
# Faster feedback on Rust builds
20+
build-args = "--profile=dev"
21+
22+
[tool.uv]
23+
cache-keys = ["pyproject.toml", "Cargo.toml", "src/*.rs"]
24+
25+
[tool.uv.sources]
26+
setup = { workspace = true }
27+
28+
[tool.uv.workspace]
29+
members = ["sample"]

exercises/01_intro/01_setup/sample/pyproject.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
[project]
22
name = "setup_sample"
33
version = "0.1.0"
4-
dependencies = []
4+
dependencies = [
5+
"setup",
6+
]
57
readme = "README.md"
6-
requires-python = ">= 3.8"
8+
requires-python = ">=3.11"
79

810
[build-system]
911
requires = ["hatchling"]
1012
build-backend = "hatchling.build"
1113

12-
[tool.rye]
13-
managed = true
14-
dev-dependencies = [
14+
[dependency-groups]
15+
dev = [
1516
"pytest>=8.2.2",
1617
]
1718

0 commit comments

Comments
 (0)