Skip to content
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

Migrate from rye to uv #11

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

11 changes: 6 additions & 5 deletions .wr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
command = "cargo"
args = ["test"]

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

[[verification]]
command = "rye"
args = ["test", "--pyproject", "sample/pyproject.toml"]
command = "uv"
args = ["run", "pytest"]
72 changes: 0 additions & 72 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["exercises/*/*", "patcher"]
members = ["exercises/*/*"]
resolver = "2"

[workspace.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions book/src/01_intro/00_welcome.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ also find solutions to all exercises in the
To follow this course, you must install:

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

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

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

```bash
cargo --version
rye --version
uv --version
```

Don't start the course until you have these tools installed and working.
Expand Down
47 changes: 13 additions & 34 deletions book/src/01_intro/01_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ To invoke Rust code from Python we need to create a **Python extension module**.
We'll use `maturin` to build, package and publish Python extensions written in Rust. Let's install it:

```bash
rye install "maturin>=1.6"
uv tool install "maturin>=1.8"
```

Tools installed via `uv` should be available in your path. Run:

```bash
uv tool update-shell
```

to make sure that's the case.

## Exercise structure

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

```toml
[build-system]
requires = ["maturin>=1.6,<2.0"]
requires = ["maturin>=1.8,<2.0"]
build-backend = "maturin"

[project]
name = "setup"
# [...]
requires-python = ">=3.8"
dynamic = ["version"]
requires-python = ">=3.13"

[tool.maturin]
features = ["pyo3/extension-module"]
```

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

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

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

## Troubleshooting

You may run into this error when using `rye` and `pyo3` together:

```plaintext
<compiler output>
= note: ld: warning: search path '/install/lib' not found
ld: library 'python3.12' not found
clang: error: linker command failed with exit code 1
```

This seems to be a [bug in `rye`](https://github.com/astral-sh/rye/issues/1050#issuecomment-2079270180).\
To work around the issue, run the following command in the root of the course repository:

```bash
cargo run -p "patcher"
```

`wr` should now be able to build the extension module without issues and run the tests. No linker errors
should be surfaced.

<div class="warning">

The `patcher` tool is a temporary workaround for a bug in `rye`.\
It hasn't been tested on Windows: please [open an issue](https://github.com/mainmatter/rust-python-interoperability/issues)
if you encounter any problems.

</div>

## References

- [Linking artifacts together (Rust compiler documentation)](https://doc.rust-lang.org/reference/linkage.html)
Expand Down
2 changes: 1 addition & 1 deletion exercises/01_intro/00_welcome/.wr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ command = "cargo"
args = ["test"]

[[verification]]
command = "rye"
command = "uv"
args = ["sync"]
8 changes: 4 additions & 4 deletions exercises/01_intro/00_welcome/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ mod tests {
}

#[test]
fn rye_is_installed_and_on_path() {
let output = std::process::Command::new("rye")
fn uv_is_installed_and_on_path() {
let output = std::process::Command::new("uv")
.arg("--version")
.output()
.expect("Failed to run rye");
.expect("Failed to run uv");

assert!(
output.status.success(),
"`rye --version` failed:\n{}",
"`uv --version` failed:\n{}",
String::from_utf8_lossy(&output.stderr)
);
}
Expand Down
20 changes: 17 additions & 3 deletions exercises/01_intro/01_setup/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
[build-system]
requires = ["maturin>=1.6,<2.0"]
requires = ["maturin>=1.8,<2.0"]
build-backend = "maturin"

[project]
name = "setup"
requires-python = ">=3.8"
requires-python = ">=3.11"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]
version = "0.1.0"

[tool.maturin]
features = ["pyo3/extension-module"]

[tool.uv.config-settings]
# Faster feedback on Rust builds
build-args = "--profile=dev"

[tool.uv]
cache-keys = ["pyproject.toml", "Cargo.toml", "src/*.rs"]

[tool.uv.sources]
setup = { workspace = true }

[tool.uv.workspace]
members = ["sample"]
11 changes: 6 additions & 5 deletions exercises/01_intro/01_setup/sample/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
[project]
name = "setup_sample"
version = "0.1.0"
dependencies = []
dependencies = [
"setup",
]
readme = "README.md"
requires-python = ">= 3.8"
requires-python = ">=3.11"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.rye]
managed = true
dev-dependencies = [
[dependency-groups]
dev = [
"pytest>=8.2.2",
]

Expand Down
Empty file.
83 changes: 83 additions & 0 deletions exercises/01_intro/01_setup/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading