uv itself is a large package with many dependencies and lots of
features. To build a package using the uv build backend, you shouldn't
have to download and install the entirety of uv. For platform where we
don't provide wheels, it should be possible and fast to compile the uv
build backend. To that end, we're introducing a python package that
contains a trimmed down version of uv that only contains the build
backend, with a minimal dependency tree in rust.
The `uv_build` package is publish from CI just like uv itself. It is
part of the workspace, but has much less dependencies for its own
binary. We're using cargo deny to enforce that the network stack is not
part of the dependencies. A new build profile ensure we're getting the
minimum possible binary size for a rust binary.
---------
Co-authored-by: Zanie Blue <contact@zanie.dev>
From PEP 517:
> All command-line scripts provided by the build-required packages must
be present in the build environment’s PATH. For example, if a project
declares a build-requirement on flit, then the following must work as a
mechanism for running the flit command-line tool:
>
> ```python
> import subprocess
> import shutil
> subprocess.check_call([shutil.which("flit"), ...])
> ```
Fixes#9991
---------
Co-authored-by: Charles Tapley Hoyt <cthoyt@gmail.com>
See #9686
```
❯ uv run python -c "import uv; uv.build_sdist"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/zb/workspace/uv/python/uv/__init__.py", line 45, in __getattr__
raise AttributeError(err)
AttributeError: Using `uv.build_sdist` is not allowed. The uv build backend requires preview mode to be
enabled, e.g., via the `UV_PREVIEW=1` environment variable.
❯ uv run python -c "import uv; uv.foo"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/zb/workspace/uv/python/uv/__init__.py", line 48, in __getattr__
raise AttributeError(err)
AttributeError: module 'uv' has no attribute 'foo'
❯ uv run python -c "import uv; uv.find_uv_bin"
```
It used to report:
```
» mypy
python/uv/_build_backend.py:40: error: Incompatible types in assignment (expression has type "list[str]", variable has type "CompletedProcess[bytes]") [assignment]
python/uv/_build_backend.py:41: error: Value of type "CompletedProcess[bytes]" is not indexable [index]
python/uv/_build_backend.py:46: error: Value of type "CompletedProcess[bytes]" is not indexable [index]
Found 3 errors in 1 file (checked 6 source files)
```
So, I had to fix this problem by renaming the `result` var.
<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:
- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->
## Summary
[ruff's `find_bin`
implementation](19cd9d7d8a/python/ruff/__main__.py (L31))
can find the binary in relative to the package root. It'd be nice to
have the same functionality for `uv`.
Closes#2222
Closes https://github.com/astral-sh/uv/issues/2058
Replaces https://github.com/astral-sh/uv/pull/2338
See also https://github.com/astral-sh/uv/issues/2649
We use an environment variable (`UV_INTERNAL__PARENT_INTERPRETER`) to
track the invoking interpreter when `python -m uv` is used. The parent
interpreter is preferred over all other sources (though it will be
skipped if it does not meet a `--python` request or if `--system` is
used and it belongs to a virtual environment). We warn if `--system` is
not provided and this interpreter would mutate system packages, but
allow it.
Add a single job for for fast lint tools. Rustfmt for rust, ruff for
python formatting and linting, prettier avoids inconsistent formatter
changes between pycharm and vscode.
First, replace all usages in files in-place. I used my editor for this.
If someone wants to add a one-liner that'd be fun.
Then, update directory and file names:
```
# Run twice for nested directories
find . -type d -print0 | xargs -0 rename s/puffin/uv/g
find . -type d -print0 | xargs -0 rename s/puffin/uv/g
# Update files
find . -type f -print0 | xargs -0 rename s/puffin/uv/g
```
Then add all the files again
```
# Add all the files again
git add crates
git add python/uv
# This one needs a force-add
git add -f crates/uv-trampoline
```
## Summary
This PR adds a release workflow powered by `cargo-dist`. It's similar to
the version that's PR'd in Ruff
(https://github.com/astral-sh/ruff/pull/9559), with the exception that
it doesn't include the Docker build or the "update dependents" step for
pre-commit.