Commit Graph

4089 Commits

Author SHA1 Message Date
Charlie Marsh f3463b3d08
Heal cache entries with missing source distributions (#7559)
## Summary

`uv cache prune --ci` will remove the source distribution directory. If
we then need to build a _different_ wheel (e.g., you're building a
package that has Python minor version-specific wheels), we fail, because
we expect the source to be there.

Now, if the source is missing, we re-download it. It would be slightly
easier to just _ignore_ that revision, but that would mean we'd also
lose the already-built wheels -- so if you ran against many Python
versions, we'd continuously lose the cached data.

Closes https://github.com/astral-sh/uv/issues/7543.

## Test Plan

We can add tests, but they _need_ to build non-pure Python wheels, which
tends to be expensive...

For reference:

```console
$ cargo run venv --python 3.12
$ cargo run pip install mercurial==6.8.1 --verbose
$ cargo run cache prune --ci
$ cargo run venv --python 3.11
$ cargo run pip install mercurial==6.8.1 --verbose
```

I also did this with a local `.tar.gz` that I downloaded from PyPI.
2024-09-19 20:31:55 +00:00
Charlie Marsh 5de6d2338d
Bump the wheel and sdist cache versions (#7560)
## Summary

Both of these can contain rkyv data in their HTTP cache envelopes. As
such, the entries aren't readable by earlier versions of uv, and `uv
cache prune` can break. I should make `uv cache prune` robust to this,
but this feels safest.
2024-09-19 19:53:06 +00:00
Charlie Marsh 18c18b8406
Treat invalid platform as more compatible than invalid Python (#7556)
## Summary

I think this is just inverted. It means that when we fail in
https://github.com/astral-sh/uv/issues/7553, we show a message for
"invalid Python implementation" (since there are some wheels that don't
match), but we should be showing "invalid platform", matching the order
of operations in our compatibility check.

Closes https://github.com/astral-sh/uv/issues/7553.
2024-09-19 13:25:21 -04:00
Zanie Blue 5206a33e78
Do not error if the `CACHEDIR.TAG` file exists but cannot be written to (#7550)
Attempting to address the error in
https://github.com/astral-sh/uv/issues/7434 — it seems overkill to fail
if the file exists but isn't writable.
2024-09-19 09:39:59 -05:00
Zanie Blue 99d57ca80e
Improve invalid environment warning messages (#7544)
Adds display of the target path of the link (since the link filename
itself is basically static) and distinguishes between broken links and
missing files.
2024-09-19 09:11:17 -05:00
Luca Bruno 248bef13bd
Compute resolver hints using the final reduced derivation tree (#7546)
This switches the no-solution formatter to use the final derivation tree
(simplified and reduced) when generating hints.
2024-09-19 16:06:55 +02:00
Zanie Blue df90cc6f95
Filter flaky counts in `sync_build_isolation_extra` (#7531)
I've seen this flake several times now, e.g.,
https://github.com/astral-sh/uv/actions/runs/10933201998/job/30351289277?pr=7530

I don't quite understand why, but we have a standard filter for this.
2024-09-19 07:03:03 -05:00
You Jiacheng a235b7d70d
Clarify behavior of of overrides in CLI reference (#7537)
## Summary
Improve the description of override-dependencies based on the statement
in `concepts/resolution.md`: "As with constraints, overrides do not add
a dependency on the package and only take effect if the package is
requested in a direct or transitive dependency."

I tested it locally, `concepts/resolution.md` is correct. It would be
better to also include this in the Reference Chapter of the docs.
2024-09-19 07:02:42 -05:00
Zanie Blue 6b08aaecad
Avoid warning about bad Python interpreter links for empty project environment directories (#7527)
Someone reported this a while back (will try to find the issue), and I
ran into it working on #7522
2024-09-19 06:49:35 -05:00
konsti 4fdf5fc73f
Use a single lint task in CI (#7540) 2024-09-19 13:32:08 +02:00
Zanie Blue 8d26e11380
Avoid deleting the project environment directory if it is not a virtual environment (#7522)
Closes https://github.com/astral-sh/uv/issues/7519
2024-09-19 11:21:05 +00:00
Zanie Blue 09a2ebca8b
Add new `PythonRequest::Any` and `VersionRequest::Any` variants (#7517)
Follow-up to https://github.com/astral-sh/uv/pull/7514 and #7526 adding
the `Any` variants again with slightly different semantics (i.e., they
allow pre-releases)

We'll be able to use this in https://github.com/astral-sh/uv/pull/7508
to avoid querying a bunch of alternative interpreters unnecessarily in
the non-list case.
2024-09-19 11:19:13 +00:00
Zanie Blue 0f9a2e3870
Rename `VersionRequest::Any` -> `VersionRequest::Default` (#7526)
As in https://github.com/astral-sh/uv/pull/7514
2024-09-19 11:05:09 +00:00
Zanie Blue 0cc36a457b
Use placeholder for virtual environment activation bin filter (#7530)
I think it's best practice to use a placeholder when we transform
something, and #7522 is having snapshot issues because this filter
conflicts with `with_filtered_virtualenv_bin`
2024-09-19 05:56:46 -05:00
Zanie Blue 5941709e55
Rename `PythonRequest::Any` -> `PythonRequest::Default` (#7514)
As we support more complex Python discovery behaviors such as:

- #7431 
- #7335 
- #7300 

`Any` is no longer accurate, we actually are looking for a reasonable
default Python version to use which may exclude the first one we find.
Separately, we need the idea of `Any` to improve behavior when listing
versions (e.g., #7286) where we do actually want to match _any_ Python
version. As a first step, we'll rename `Any` to `Default`. Then, we'll
introduce a new `Any` that actually behaves as we'd expect.
2024-09-19 05:56:05 -05:00
Zanie Blue 209c870232
Add `UV_LINK_MODE` to Docker caching example (#7510)
As mentioned in https://github.com/astral-sh/uv/issues/7509
2024-09-19 05:55:54 -05:00
Zanie Blue 7778a11b2d
Use more verbose spelling of "virtualenv" during creation (#7523)
This stands out alongside other messaging which uses the longer spelling
"virtual environment"
2024-09-18 21:22:37 -05:00
Charlie Marsh e36cc99b0d
Use portable paths when serializing sources (#7504)
## Summary

Closes https://github.com/astral-sh/uv/issues/7493.
2024-09-18 18:51:14 +00:00
Andrew Gallant 1379b530f6 uv: migrate to rkyv 0.8
Recently, rkyv 0.8 was released. Its API is a fair bit simpler now for
higher level uses (like for us in `uv`) and results in us being able to
delete a fair bit of code. This also removes our last dependency on `syn
1.0`, and thus drops that dependency.

Performance (via testing on the `transformers` example) seems to remain
about the same, which is what was expected:

```
$ hyperfine -w5 -r100 'uv lock' 'uv-ag-rkyv-update lock'
Benchmark 1: uv lock
  Time (mean ± σ):      55.6 ms ±   6.4 ms    [User: 30.4 ms, System: 35.1 ms]
  Range (min … max):    43.0 ms …  73.1 ms    100 runs

Benchmark 2: uv-ag-rkyv-update lock
  Time (mean ± σ):      56.5 ms ±   7.2 ms    [User: 30.5 ms, System: 36.3 ms]
  Range (min … max):    39.1 ms …  71.5 ms    100 runs

Summary
  uv lock ran
    1.02 ± 0.18 times faster than uv-ag-rkyv-update lock
```

Closes #7415
2024-09-18 14:49:54 -04:00
Andrew Gallant 91a574c6d2 uv/tests: filter out link mode warning in two more tests
More whack-a-mole following in the tradition of #7012.
2024-09-18 14:10:53 -04:00
Charlie Marsh fe4e39a230
Add `socks` support (#7503)
## Summary

This adds about 50 KB to the binary:

```
❯ du ./target/release/socks
44736	./target/release/socks

❯ du ./target/release/uv
44632	./target/release/uv
```

So need some input on whether it's worth supporting.

Closes https://github.com/astral-sh/uv/issues/7484.
2024-09-18 11:46:06 -04:00
Zanie Blue 8b830de94d
Do not use a user-facing warning for "Waiting to acquire lock..." message (#7502)
Closes https://github.com/astral-sh/uv/issues/7489
2024-09-18 15:34:27 +00:00
Zanie Blue 4611412757
Allow Python pre-releases to be used if they are first on the `PATH` (#7470)
Closes https://github.com/astral-sh/uv/issues/7469
2024-09-18 10:19:10 -05:00
Luca Bruno 67cfb4a9c0
Use a single buffer for hints on resolver errors (#7497)
This changes the structure of the hints generator in the resolver when
encountering solution errors, so that it re-uses a single output buffer
owned by the caller.
It avoids repeated allocations of a temporary buffer within each
recursive function call.
2024-09-18 16:16:22 +02:00
Charlie Marsh 039b68367e
Add test for `uv cache prune --ci` with source distributions (#7500)
## Summary

See: https://github.com/astral-sh/uv/issues/7485. The test was using `uv
pip sync` which doesn't require fetching metadata, and the failure was
in fetching metadata.
2024-09-18 10:01:07 -04:00
Zanie Blue 2545bca692
Bump version to 0.4.12 (#7499) 2024-09-18 08:50:04 -05:00
samypr100 5e49f21adf
docs: add warning note on self-hosted github runners (#5757)
## Summary

Related discussion: #5731

This adds a warning section for caching on non-ephemeral (e.g. ec2) self
hosted github runners.

## Test Plan

Prettier was ran on the file.

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-09-18 13:34:25 +00:00
Charlie Marsh 97ae811b86
Avoid fatal error when searching for egg-info with missing directory (#7498)
## Summary

Closes https://github.com/astral-sh/uv/issues/7485.

## Test Plan

```
$ cargo run cache clean
$ cargo run venv
$ cargo run pip install django-allauth==0.51.0
$ cargo run venv
$ cargo run pip install django-allauth==0.51.0
```
2024-09-18 09:33:11 -04:00
konsti f942561158
Cache ecosystem tests (#7432) 2024-09-18 11:30:59 +02:00
Luca Bruno 969b4a2222
uv-tool/install: ignore existing environments on interpreter mismatch (#7451)
This changes `uv tool install` behavior with regards to re-using
existing environments.
In particular, this replaces the existing version-matching logic with a
tighter one, enforcing
a same-interpreter match.
This allows to properly switch between system and managed interpreter,
at the cost of
more eagerly invalidating existing environments every time there is an
interpreter change.

Closes: https://github.com/astral-sh/uv/issues/7320
2024-09-18 08:37:41 +02:00
Charlie Marsh fda227616c
Allow users to provide pre-defined metadata for resolution (#7442)
## Summary

This PR enables users to provide pre-defined static metadata for
dependencies. It's intended for situations in which the user depends on
a package that does _not_ declare static metadata (e.g., a
`setup.py`-only sdist), and that is expensive to build or even cannot be
built on some architectures. For example, you might have a Linux-only
dependency that can't be built on ARM -- but we need to build that
package in order to generate the lockfile. By providing static metadata,
the user can instruct uv to avoid building that package at all.

For example, to override all `anyio` versions:

```toml
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["anyio"]

[[tool.uv.dependency-metadata]]
name = "anyio"
requires-dist = ["iniconfig"]
```

Or, to override a specific version:

```toml
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["anyio"]

[[tool.uv.dependency-metadata]]
name = "anyio"
version = "3.7.0"
requires-dist = ["iniconfig"]
```

The current implementation uses `Metadata23` directly, so we adhere to
the exact schema expected internally and defined by the standards. Any
entries are treated similarly to overrides, in that we won't even look
for `anyio@3.7.0` metadata in the above example. (In a way, this also
enables #4422, since you could remove a dependency for a specific
package, though it's probably too unwieldy to use in practice, since
you'd need to redefine the _rest_ of the metadata, and do that for every
package that requires the package you want to omit.)

This is under-documented, since I want to get feedback on the core ideas
and names involved.

Closes https://github.com/astral-sh/uv/issues/7393.
2024-09-18 03:18:05 +00:00
kyoto7250 e5dd67f58e
Add support for `--with-editable` to `uv tool` (#6744)
<!--
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
<!-- What's the purpose of the change? What does it do, and why? -->
close #6272 

## Test Plan
<!-- How was it tested? -->
As in https://github.com/astral-sh/uv/pull/6262

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-09-17 20:51:34 +00:00
Charlie Marsh 6c52f36655
Bump version to v0.4.11 (#7478) 2024-09-17 19:48:37 +00:00
Charlie Marsh adbd99a1d6
Document `store_credentials_from_workspace` (#7477) 2024-09-17 19:19:45 +00:00
Charlie Marsh c2ad31aa58
Respect `pyproject.toml` credentials from user-provided requirements (#7474)
## Summary

When syncing a lockfile, we need to respect credentials defined in the
`pyproject.toml`, even if they won't be used for resolution.
Unfortunately, this includes credentials in `tool.uv.sources`,
`tool.uv.dev-dependencies`, `project.dependencies`, and
`project.optional-dependencies`.

Closes https://github.com/astral-sh/uv/issues/7453.
2024-09-17 15:09:11 -04:00
Zanie Blue 08a7c708d1
Do not allow local versions in Python version requests either (#7468)
Accidentally squashed https://github.com/astral-sh/uv/pull/7465 into the
wrong target.
2024-09-17 16:10:38 +00:00
Ilya Grigoriev e31252e82e
docs `installation.md`: describe how to pass options to the installer on Linux (#6839)
(This is a suggestion that was easy for me to make a PR for; if other
approaches are considered better, feel free to consider this as a FR for
those instead)

I'd feel more comfortable using the installer with the instructions in
this commit, since I'm uncomfortable with random scripts trying to
modify my system config (PATH in this case).

Currently, the installer seems to be the best way to install `uv` that
allows updating it on a system without Homebrew or `pipx`. I hope
somebody will provide similar instructions for Windows.

I considered recommending saving the script to a file and then running
that, but I think it's better to have fewer options in the instructions.
Most people who'd want to save the file would figure it out.

As an aside, I would personally appreciate if `uv` could be installed
easily with `cargo install` or `cargo binstall`, but a friendly script
that acts predictably is probably more useful for more people.


## Test Plan

I tested the command on my machine, but I did not test compiling the
docs (yet). If the CI does not compile the docs, I could test this a bit
later, or perhaps this would be easier for somebody who already has a
dev environment set up.

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-09-17 16:09:30 +00:00
Zanie Blue 8d7925026d
Add `VersionRequest` test cases for post and dev segments (#7464) 2024-09-17 10:59:41 -05:00
Charlie Marsh 778da3350a
Add `--no-editable` support to `uv sync` and `uv export` (#7371)
## Summary

Closes https://github.com/astral-sh/uv/issues/5792.
2024-09-17 14:50:36 +00:00
Mikko Leppänen bb0ffa32e4
Support pre-releases in Python version requests - `command --python <major.minor.pre-release>` (#7335)
## Summary

This PR adds support to include Python pre-releases when requesting
versions.
Check out the docs for commands that support the `Python` option: 
```text
--python, -p python
The Python interpreter to use for the virtual environment.
```
At least the following scenarios are supported:
```bash
3.13.0a1
3.13b2
3.13rc4
313rc1
```

## Test Plan

I added a basic unit test to `uv/crates/uv-python/src/discovery.rs`. I
could have added more, but I have not discovered any relevant places.

CI passes

Note: I was unable to execute the entire test set locally. There were at
least some timeout issues (some tests took over 60 seconds).

========== output ===========
beta version
```bash
cargo run -- venv --python 3.13.0b3                                                                                                           ░▒▓ 94% 󰁹
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.20s
     Running `target/debug/uv venv --python 3.13.0b3`
Using Python 3.13.0b3 interpreter at: /home/mikko/.pyenv/versions/3.13.0b3/bin/python3
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate
````
release candidate
```bash
 cargo run -- venv --python 3.13.0rc2                                                                                                          ░▒▓ 94% 󰁹
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.83s
     Running `target/debug/uv venv --python 3.13.0rc2`
Using Python 3.13.0rc2 interpreter at: /home/mikko/.pyenv/versions/3.13.0rc2/bin/python3
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate
```

```bash
cargo run -- venv --python 313rc2                                                                                                             ░▒▓ 94% 󰁹
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.31s
     Running `target/debug/uv venv --python 313rc2`
Using Python 3.13.0rc2 interpreter at: /home/mikko/.pyenv/versions/3.13.0rc2/bin/python3
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate
```

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-09-17 09:46:46 -05:00
Charlie Marsh 2cb3acdb1f
Remove uvx shell completion instructions (#7459)
## Summary

I misunderstood and this isn't necessary.
2024-09-17 09:28:28 -04:00
Charlie Marsh c87ce7aaf8
Run `cargo upgrade` (#7448)
Co-authored-by: konstin <konstin@mailbox.org>
2024-09-17 12:39:58 +02:00
Zanie Blue f679987fe1
Include the parent interpreter in Python discovery when `--system` is used (#7440)
Closes https://github.com/astral-sh/uv/issues/7417

Tested with this epic blurb

```
❯ uv pip install --python /Users/zb/.local/share/uv/python/cpython-3.13.0rc2-macos-aarch64-none/bin/python3 . --break-system-packages --reinstall
Resolved 1 package in 0.91ms
   Built uv @ file:///Users/zb/workspace/uv
Prepared 1 package in 2m 48s
Uninstalled 1 package in 1ms
Installed 1 package in 1ms
 - uv==0.4.10
 + uv==0.4.10 (from file:///Users/zb/workspace/uv)
❯ /Users/zb/.local/share/uv/python/cpython-3.13.0rc2-macos-aarch64-none/bin/python3 -m uv pip install --system -v httpx
DEBUG uv 0.4.10
DEBUG Searching for Python interpreter in system path
DEBUG Found `cpython-3.13.0rc2-macos-aarch64-none` at `/Users/zb/.local/share/uv/python/cpython-3.13.0rc2-macos-aarch64-none/bin/python3` (parent interpreter)
DEBUG Using Python 3.13.0rc2 environment at /Users/zb/.local/share/uv/python/cpython-3.13.0rc2-macos-aarch64-none/bin/python3
```
2024-09-16 22:51:50 -05:00
bluss e9378be919
Generate shell completion for `uvx` (#7388)
## Summary

Generate shell completion for uvx.

Create a `uvx` toplevel command just for completion by combining `uv
tool uvx` (hidden alias for `uv tool run`) with global arguments. This
explicit combination is needed otherwise global arguments are missing
(if they are missing, clap debug assertions fail when `uv tool run`
arguments refer to global arguments in directives like conflicts with).


Fixes #7258 

## Test Plan

- Tested using bash using `eval "$(cargo run --bin uv
generate-shell-completion bash)"`
2024-09-17 03:27:19 +00:00
Charlie Marsh d1c7cb8bc2
Include `--branch` et al when resolving unnamed URLs in `uv add` (#7447)
## Summary

Closes #7433.
2024-09-16 22:21:42 -04:00
Charlie Marsh 424ee439d6
Use consistent PyPI cache bucket (#7443)
## Summary

All the registry wheels were getting cached under
`index/b2a7eb67d4c26b82` rather than `pypi`, because we used
`IndexUrl::Url` rather than `IndexUrl::from`.
2024-09-16 23:33:32 +00:00
Charlie Marsh 9f7d9da449
Prune unzipped source distributions in `uv cache prune --ci` (#7446)
## Summary

It's very unlikely that retaining these is beneficial, since you tend to
partition the cache by platform anyway.

Closes https://github.com/astral-sh/uv/issues/7394.
2024-09-16 19:18:20 -04:00
Charlie Marsh e31851fb52
Avoid erroneous version warning for .dist-info (#7444)
## Summary

Since https://github.com/astral-sh/uv/pull/7208, this is now _always_
firing, for every directory, because the version gets normalized (e.g.,
`1.2.3` gets normalized to `1-2-3`, which never matches the parsed
version). pip doesn't warn here, I guess we won't either, because I
can't figure out a robust way to do this... We need to get the
non-normalized remainder after stripping the normalized package name,
but we strip the normalized package name from the normalized string, so
we only have a normalized remainder.
2024-09-16 22:32:56 +00:00
Zanie Blue d3e6765cea
Add test case for Python selection when invoked with `python -m uv --system` (#7439) 2024-09-16 15:42:06 -05:00
Zanie Blue 6066989ed4
Add test case for Python pre-release versions from parent interpreter (#7438) 2024-09-16 15:41:58 -05:00