Commit graph

3324 commits

Author SHA1 Message Date
Zanie Blue
bef72a8880
Display skipped managed interpreters during Python discovery (#7668)
e.g.

```
❯ cargo run -- python find 3.11rc2 -v
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/uv python find 3.11rc2 -v`
DEBUG uv 0.4.15
DEBUG Searching for Python 3.11rc2 in managed installations or system path
DEBUG Found `cpython-3.12.1-macos-aarch64-none` at `/Users/zb/workspace/uv/.venv/bin/python3` (active virtual environment)
DEBUG Found `cpython-3.12.1-macos-aarch64-none` at `/Users/zb/workspace/uv/.venv/bin/python3` (virtual environment)
DEBUG Searching for managed installations at `/Users/zb/.local/share/uv/python`
DEBUG Skipping incompatible managed installation `cpython-3.13.0rc2-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `cpython-3.12.1-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `cpython-3.11.7-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `cpython-3.10.13-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `cpython-3.9.18-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `cpython-3.8.18-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `cpython-3.8.12-macos-aarch64-none`
DEBUG Skipping incompatible managed installation `pypy-3.9.19-macos-aarch64-none`
DEBUG Found `cpython-3.12.1-macos-aarch64-none` at `/Users/zb/workspace/uv/.venv/bin/python` (search path)
DEBUG Found `cpython-3.12.1-macos-aarch64-none` at `/Users/zb/workspace/uv/.venv/bin/python3` (search path)
DEBUG Found `cpython-3.12.6-macos-aarch64-none` at `/opt/homebrew/bin/python3` (search path)
DEBUG Found `cpython-3.11.10-macos-aarch64-none` at `/opt/homebrew/bin/python3.11` (search path)
DEBUG Found `cpython-3.9.6-macos-aarch64-none` at `/usr/bin/python3` (search path)
error: No interpreter found for Python 3.11rc2 in virtual environments, managed installations, or system path
```
2024-09-24 14:41:41 -05:00
Zanie Blue
e81ed8ec5d
Bump version to 0.4.16 (#7669) 2024-09-24 14:39:21 -05:00
Zanie Blue
e6cd6c9b01
Use the first pre-release discovered when only pre-release Python versions are available (#7666) 2024-09-24 18:00:28 +00:00
Zanie Blue
a53ddaa24a
Require opt-in to use alternative Python implementations (#7650)
Closes #7118 

This only really affects managed interpreters, as we exclude alternative
Python implementations from the search path during the
`VersionRequest::executable_names` part of discovery.
2024-09-24 12:52:15 -05:00
Charlie Marsh
538b0f1099
Remove serde::Serialize implementations for rkyv-able structs (#7663)
## Summary

Random, but I noticed that we can remove a ton of serialize and
deserialize derives by using `rkyv` for the flat-index caches. (We
already use `rkyv` for these same structs in the registry cache.)
2024-09-24 13:23:47 -04:00
konsti
c4c5378c0b
Add build backend scaffolding (#7662) 2024-09-24 19:23:17 +02:00
Zanie Blue
bcd14ec799
Display Python implementation when creating environments (#7652)
e.g.

```
❯ cargo run -q -- venv -p pypy
Using PyPy 3.9.19
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
```
2024-09-24 11:45:52 -05:00
Zanie Blue
0c6117f5da
Unhide the --directory option (#7653) 2024-09-24 11:45:33 -05:00
konsti
5da73a24cb
Rename MetadataResolver to ResolutionMetadata (#7661) 2024-09-24 16:25:19 +00:00
konsti
16a6fd2c42
Add retries to uv publish (#7635) 2024-09-24 16:24:44 +00:00
konsti
205bf8cabe
Implement trusted publishing (#7548)
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-09-24 16:07:20 +00:00
konsti
c053dc84f4
Progress bars for uv publish (#7613) 2024-09-24 15:55:33 +00:00
konsti
1995d20298
Add uv publish: Basic upload with username/password or keyring (#7475)
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-09-24 15:33:06 +00:00
konsti
484717d42f
Split metadata parsing into a module (#7656) 2024-09-24 17:16:21 +02:00
Andrew Gallant
83f1abdf57 uv-resolver: add error checking for conflicting distributions
This PR adds some additional sanity checking on resolution graphs to
ensure we can never install different versions of the same package into
the same environment.

I used code similar to this to provoke bugs in the resolver before the
release, but it never made it into `main`. Here, we add the error
checking to the creation of `ResolutionGraph`, since this is where it's
most convenient to access the "full" markers of each distribution.

We only report an error when `debug_assertions` are enabled to avoid
rendering `uv` *completely* unusuable if a bug were to occur in a
production binary. For example, maybe a conflict is detected in a marker
environment that isn't actually used. While not ideal, `uv` is still
usable for any other marker environment.

Closes #5598
2024-09-24 10:55:23 -04:00
Bas Schoenmaeckers
77c2496f47
Allow creating venv with free-threaded python builds (#7431)
<!--
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

closes #4828

First iteration for an implementation. I need to add more tests but
wanted your opinion on the implementation first.

<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan
Currently tested using the following command but will add tests shortly:

```console
D:\repo\uv> cargo run venv -p 3.13t && .venv\Scripts\python.exe
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.52s
     Running `target\debug\uv.exe venv -p 3.13t`
Using Python 3.13.0rc1 interpreter at: C:\Users\bschoen\AppData\Local\Programs\Python\Python313\python3.13t.exe
Creating virtualenv at: .venv
Activate with: .venv\Scripts\activate
Python 3.13.0rc1 experimental free-threading build (tags/v3.13.0rc1:e4a3e78, Jul 31 2024, 21:06:58) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 
```

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-09-23 17:36:16 -05:00
Zanie Blue
0dea932d83
Improve Python executable name discovery when using alternative implementations (#7649)
There are two parts to this. 

The first is a restructuring and refactoring. We had some debt around
expected executable name generation, which we address here by
consolidating into a single function that generates a combination of
names. This includes a bit of extra code around free-threaded variants
because this was written on top of #7431 — I'll rebase that on top of
this.

The second addresses some bugs around alternative implementations.
Notably, `uv python list` does not discovery executables with
alternative implementation names. Now, we properly generate all of the
executable names for `VersionRequest::Any` (originally implemented in
https://github.com/astral-sh/uv/pull/7508) to properly show all the
implementations we can find:

```
❯ cargo run -q -- python list --no-python-downloads
cpython-3.12.6-macos-aarch64-none     /opt/homebrew/opt/python@3.12/bin/python3.12 -> ../Frameworks/Python.framework/Versions/3.12/bin/python3.12
cpython-3.11.10-macos-aarch64-none    /opt/homebrew/opt/python@3.11/bin/python3.11 -> ../Frameworks/Python.framework/Versions/3.11/bin/python3.11
cpython-3.9.6-macos-aarch64-none      /Library/Developer/CommandLineTools/usr/bin/python3 -> ../../Library/Frameworks/Python3.framework/Versions/3.9/bin/python3
pypy-3.10.14-macos-aarch64-none       /opt/homebrew/bin/pypy3 -> ../Cellar/pypy3.10/7.3.17/bin/pypy3
```

While doing both of these changes, I ended up changing the priority of
interpreter discovery slightly. For example, given that the executables
are in the same directory, do we query `python` or `python3.10` first
when you request `--python 3.10`? Previously, we'd check `python3.10`
but I think that was an incorrect optimization. I think we should always
prefer the bare name (i.e. `python`) first. Similarly, this applies to
`python` and an executable for an alternative implementation like
`pypy`. If it's not compatible with the request, we'll skip it anyway.
We might have to query more interpreters with this approach but it seems
rare.


Closes https://github.com/astral-sh/uv/issues/7286 superseding
https://github.com/astral-sh/uv/pull/7508
2024-09-23 17:17:55 -05:00
Huang, Hong-Chang
63b60bc0c8
Remove double whitespaces from the code (#7623)
Co-authored-by: konstin <konstin@mailbox.org>
2024-09-23 20:15:06 +00:00
Zanie Blue
bbb1d3f85a
Determine if pre-release Python downloads should be allowed using the version specifiers (#7638)
Closes #7637

```
❯ uv python install '>=3.11'
Installed Python 3.12.6 in 1.70s
 + cpython-3.12.6-macos-aarch64-none

❯ uv python install 3.13
Installed Python 3.13.0rc2 in 1.89s
 + cpython-3.13.0rc2-macos-aarch64-none

❯ uv python uninstall --all
Searching for Python installations
Uninstalled 2 versions in 94ms
 - cpython-3.12.6-macos-aarch64-none
 - cpython-3.13.0rc2-macos-aarch64-none

❯ uv python install '>=3.11a1'
Installed Python 3.13.0rc2 in 1.89s
 + cpython-3.13.0rc2-macos-aarch64-none
```
2024-09-23 14:08:59 -05:00
Charlie Marsh
b14696ca7c
Show a dedicated PubGrub hint for --unsafe-best-match (#7645)
## Summary

Closes https://github.com/astral-sh/uv/issues/5510.
2024-09-23 19:02:19 +00:00
Charlie Marsh
a541d6cf70
Avoid adding double-newlines for CRLF (#7640)
## Summary

Closes https://github.com/astral-sh/uv/issues/7621.
2024-09-23 13:58:24 +00:00
Charlie Marsh
ff066c8ce7
Respect lockfile preferences for --with requirements (#7627)
## Summary

This is a long-time TODO to respect versions from the base environment
when resolving `--with` requirements.

Closes https://github.com/astral-sh/uv/issues/7416
2024-09-23 07:36:37 -04:00
renovate[bot]
ab2bba285e
Update Rust crate thiserror to v1.0.64 (#7630) 2024-09-22 22:33:03 -04:00
renovate[bot]
400543133f
Update Rust crate anyhow to v1.0.89 (#7628) 2024-09-22 21:01:24 -04:00
Abdó Roig-Maranges
542afe7474
Fix link-mode=clone on linux (#7620)
- **Do not attempt to reflink directories on linux**
- **Refactor clone_recursive**

## Summary

On linux, reflink does not work on a directory. Currently, we first
attempt to reflink directory, and only if it fails with `AlreadyExists`
we attempt to reflink recursively.

This has the effect that, on linux, `uv pip install --link-mode=clone`
would always fall back to `copy`.

We resolve this by only attempting to reflink directories on macos. In
the process, we refactored `clone_recursive` in an attempt to make it
easier to reason about its logic.


## Test Plan

I tested that after this change, `uv pip install --link-mode=clone
numpy` would behave as expected in the following cases:

* linux, btrfs filesystem, venv on the same filesystem as cache
(correctly reflinked)
* linux, btrfs filesystem, venv on a different filesystem than cache
(fallback to copy)

I have not tested it on macos or windows, as I currently don't have
access to any macos or windows machines, unfortunately.
2024-09-22 13:40:52 -04:00
Charlie Marsh
5d328a4550
Avoid retaining forks when requires-python range changes (#7624)
## Summary

If the `requires-python` bound expands, the space covered by
`resolution-markers` may no longer include all supported Python
versions. In such cases, we need to avoid reusing the forks (but we
_can_ reuse the preferred versions).

Closes https://github.com/astral-sh/uv/issues/7618.
2024-09-22 17:36:12 +00:00
Charlie Marsh
35d6274c31
Add a --project argument to run a command from a project (#7603)
## Summary

`uv run --project ./path/to/project` now uses the provided directory as
the starting point for any file discovery. However, relative paths are
still resolved relative to the current working directory.

Closes https://github.com/astral-sh/uv/issues/5613.
2024-09-21 20:19:49 +00:00
konsti
d9a5f5ca1c
Add only_authenticated option to the client (#7545) 2024-09-21 16:09:14 +02:00
Charlie Marsh
0d81bfbc67
Bump version to v0.4.15 (#7612) 2024-09-21 09:01:20 -04:00
Zanie Blue
aca36fe3b6
Revert "Treat invalid platform as more compatible than invalid Python (#7556)" (#7608)
Closes https://github.com/astral-sh/uv/issues/7606

We'll need to dig deeper into the cause here.
2024-09-21 08:34:12 -04:00
Zanie Blue
a497b156bb
Bump version to 0.4.14 (#7600) 2024-09-20 15:08:54 -05:00
Charlie Marsh
445d1c0d43
Avoid validating workspace members when --no-sources is provided (#7599)
## Summary

Closes https://github.com/astral-sh/uv/issues/7572.
2024-09-20 19:03:31 +00:00
Zanie Blue
d6c9603594
Fix handling of sys.base_prefix collision in interpreter identity check during tool installs (#7596)
Closes https://github.com/astral-sh/uv/issues/7586

Extends https://github.com/astral-sh/uv/pull/7593 (thanks @lucab!)

---------

Co-authored-by: Luca BRUNO <lucab@lucabruno.net>
2024-09-20 14:01:14 -05:00
Zanie Blue
e93b54e240
Adjust messaging for frozen hint on resolution failure during uv add (#7597)
The existing message has been driving me a little crazy :) it's too
vague.
2024-09-20 14:01:07 -05:00
Charlie Marsh
86ff740100
Remove flatten to improve deserialization error messages (#7598)
## Summary

`#[serde(flatten)]` has a disastrous effect on error messages: serde no
longer tells you which field errored, nor does it show it to you in the
diagnostic output.

Before:

```
warning: Failed to parse `pyproject.toml` during settings discovery:
  TOML parse error at line 9, column 1
    |
  9 | [tool.uv]
    | ^^^^^^^^^
  invalid type: string "foo", expected a sequence
```

After:

```
warning: Failed to parse `pyproject.toml` during settings discovery:
  TOML parse error at line 10, column 19
     |
  10 | extra-index-url = "foo"
     |                   ^^^^^
  invalid type: string "foo", expected a sequence
```

Closes https://github.com/astral-sh/uv/issues/7113.
2024-09-20 14:54:12 -04:00
Charlie Marsh
85af2732ea
Revert "Remove duplicate warning for settings discovery errors (#7384)" (#7594)
## Summary

This reverts commit 3060fd22c0.

These are now _never_ shown to users, because `tracing` isn't set up at
that point. I'm going to try and improve the solution more holistically,
but this is better than the status quo.

Closes https://github.com/astral-sh/uv/issues/7573.
2024-09-20 14:18:40 -04:00
Luca Bruno
2c6d353711
Provide resolution hints in case of possible local name conflicts (#7505)
This enhances the hints generator in the resolver with some heuristic to
detect and warn in case of failures due to version mismatches on a local
package. Those may be the symptom of name conflict/shadowing with a
transitive dependency.

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

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-09-20 13:07:34 -05:00
Zanie Blue
9164999f23
Allow system environments during project environment validity check (#7585) 2024-09-20 12:28:17 -05:00
bluss
7a25a82fc9
Move uvx shell completion to uvx --generate-shell-completion (#7511)
## Summary

Because a problem was found with Powershell and combining the generated
completion scripts for uv and uvx, let's try separating uv and uvx
command completion scripts.

The generated powershell script template can be seen in clap_complete
source, and it starts with `using` directives, which makes it impossible
(apparently) to concatenate two of those script outputs.

As a side effect, this is available under `uv tool run
--generate-shell-completion` too.

Fixes #7482

## Test Plan

- `eval "$(cargo run --bin uvx -- --generate-shell-completion bash)"`
- Test Powershell
2024-09-20 01:27:25 +00:00
Charlie Marsh
99d354b893
Replace pretix ecosystem test with saleor (#7567)
## Summary

The AGPL license is confusing some analyzers. This replaces pretix with
saleor which (similarly) is a web application.

Closes https://github.com/astral-sh/uv/issues/7566.
2024-09-19 21:20:44 -04:00
Charlie Marsh
f9b882939f
Make uv cache prune robust to unreadable rkyv entries (#7561)
## Summary

We're robust to these in the rest of the CLI, but not in `uv cache
prune`.
2024-09-19 20:48:20 +00:00
Zanie Blue
b8f9ee3b4d
Bump version to 0.4.13 (#7558) 2024-09-19 20:43:56 +00:00
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.,
3035128927

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