Commit graph

2385 commits

Author SHA1 Message Date
Andrew Gallant
abdb58d2df uv: fix doc test
[Doc tests can't use crate internal APIs unfortunately.][internal-doc]
I really want them to be able to, but for now, mark such tests as
`ignore`.

I was motivated to do this because it otherwise breaks `cargo t --all`
for me.

[internal-doc]: https://github.com/rust-lang/rust/issues/50784
2024-07-12 07:57:29 -07:00
Silvano Cerza
663c190c2d
Unhide --isolated global argument (#5005)
## Summary

This PR makes the `--isolated` global argument visible, previously it
was hidden.
Fixes #4981.

## Test Plan

I ran `cargo run -- help` to verify `--isolated` was visible and it is.
I ran clippy with `cargo clippy --workspace --all-targets --all-features
--locked -- -D warnings` as CI does.

I also ran tests locally with:
```
cargo nextest run \
            --features python-patch \
            --workspace \
            --status-level skip --failure-output immediate-final --no-fail-fast -j 12 --final-status-level slow
```
2024-07-12 09:34:00 -05:00
Andrew Gallant
8d6c49b36c pep508: add MarkerTree::negate
It does what you think it does, for the most part.
2024-07-12 04:37:36 -07:00
Andrew Gallant
da8a4a6faa pep508: write x.y.* when serializing MarkerExpression
It's unclear to me whether this was intentional or not, but
I realized that converting a MarkerExpression to a string
treated EqualStar and NotEqualStar as Equal and NotEqual,
respectively. I tweaked this to match the Display impl for
VersionSpecifier.

(Negation tests in the next commit cover this change.)
2024-07-12 04:37:36 -07:00
Ahmed Ilyas
23c6cd774b
uv tool run suggest valid commands when command is not found (#4997)
## Summary

Resolves #4979.


## Test Plan

`cargo test`

<img width="619" alt="Screenshot 2024-07-11 at 22 45 36"
src="https://github.com/user-attachments/assets/62526010-9123-43f5-9f8d-1f9e89f6be59">

<img width="636" alt="Screenshot 2024-07-11 at 22 45 23"
src="https://github.com/user-attachments/assets/a348cd73-f891-40b1-8934-afbd1aa19326">
2024-07-12 02:26:15 +00:00
Charlie Marsh
6949796110
Allow URL dependencies in tool run --from (#5002)
## Summary

Converting to a lock requires that we generate hashes; but generating
hashes isn't required here. So let's just use a different representation
for the cache key.

Closes https://github.com/astral-sh/uv/issues/4990.
2024-07-12 01:31:07 +00:00
Caíque Porfirio
9643fb99d1
Rename python install --force parameter to --reinstall (#4999)
## Summary

Rename the `--force` parameter of `uv python install` to `--reinstall`.

Closes #4961.
2024-07-12 01:06:54 +00:00
Charlie Marsh
c345484c93
Fall back to streaming wheel when Content-Length header is absent (#5000)
## Summary

Closes https://github.com/astral-sh/uv/issues/4993
2024-07-12 01:04:21 +00:00
Charlie Marsh
55b41d7d3d
Lock directories to synchronize wheel-install copies (#4978)
## Summary

Closes https://github.com/astral-sh/uv/issues/4831.
2024-07-12 00:53:20 +00:00
Billy Doyle
22cca77329
Exit with zero when uv tool install request is already satisfied (#4986)
## Summary

`uv tool install X` fails for tools already installed and exits with
code 1. Allow already installed tools to exit with code 0.
2024-07-11 20:43:31 -04:00
Charlie Marsh
9307928765
Improve missing wheel error message with --no-build-isolation (#4964)
Closes https://github.com/astral-sh/uv/issues/4069.
2024-07-10 21:10:20 +00:00
Zanie Blue
527b711bc7
Bump version to 0.2.24 (#4974) 2024-07-10 13:50:12 -05:00
Zanie Blue
c14de2a92a
Allow uv crate to be used as a library (#4642)
This is pulled out of #4632 — a user noted that it would be useful to
use the `uv` crate from Rust. This makes it way easier to invoke `uv`
from Rust with arbitrary arguments as well as use various functionality
in the `uv` crate.

Note this is no longer needed for #4632 and is not particularly urgent.
2024-07-10 17:15:54 +00:00
Zanie Blue
e0fae8e6f4
Add uv python pin (#4950)
Adds a `uv python pin` command to write to a `.python-version` file.

We support all of our Python version request formats. We also support a
`--resolved` flag to pin to a specific interpreter instead of the
provided version. We canonicalize the request with #4949, it's not just
printed verbatim. We always attempt to find the interpreter so we can
warn if it's not available. With `--resolved`, if we can't find the
interpreter we fail. If no arguments are provided, we'll attempt to
display the current pin.

In the future:

- We should confirm that this satisfies the `Requires-Python` metadata
if a `pyproject.toml` is present
- We should support writing to a `uv.python-version` field if
`pyproject.toml` or `uv.toml` are present
- We should support finding and updating the "nearest" Python version
file (looking in ancestors)
- We should support finding version files in workspaces
- We should support some sort of global pin
2024-07-10 16:52:24 +00:00
Charlie Marsh
7925d255f7
Add manylinux_2_31 to supported --python-platform (#4965)
## Summary

I'll make an issue for arbitrary `manylinux_x_y` support.

Closes https://github.com/astral-sh/uv/issues/4956.
2024-07-10 16:30:35 +00:00
Zanie Blue
f3c5d26417
Lock for the duration of tool commands (#4720)
Feedback from
https://github.com/astral-sh/uv/pull/4501#discussion_r1655391958
2024-07-10 16:16:13 +00:00
Zanie Blue
a4044be95b
Respect --isolated in uv python install (#4938)
We ignore Python version files when `--isolated` is used, logging that
we skipped them if they exist.
2024-07-10 15:36:25 +00:00
Zanie Blue
acfb57b072
Add support for serializing PythonRequest to a canonical string (#4949)
For #4950
2024-07-10 10:24:45 -05:00
Charlie Marsh
1fcc3c4797
Warn if tool binary directory is not on path (#4951)
## Summary

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

## Test Plan

```
❯ XDG_BIN_HOME="/Users/crmarsh/workspace/uv/foo bar" cargo run tool install black --force
Installed 2 executables: black, blackd
warning: `/Users/crmarsh/workspace/uv/foo bar` is not on your PATH. To use installed tools, run:
  export PATH="/Users/crmarsh/workspace/uv/foo bar:$PATH"
```
2024-07-10 15:24:16 +00:00
Zanie Blue
3d1ab81c28
Add support for any Python requests (#4948)
For roundtrip in #4949 — it should also be fine to request `any` but the
user can't construct it right now.
2024-07-10 10:20:06 -05:00
Zanie Blue
aa8f126f13
Add standard filters for virtual environment bin directories and python executables (#4787)
Needed over in https://github.com/astral-sh/uv/pull/4674

These filters are relatively aggressive and may have a high false
positive rate, we don't need them for most tests so we leave them as
opt-in for now.
2024-07-10 10:09:43 -05:00
Zanie Blue
f5dce1124b
Retry on connection reset network errors (#4960)
See helpful discussion at
https://github.com/seanmonstar/reqwest/issues/1602#issuecomment-1220990725
and https://github.com/astral-sh/uv/issues/3514#issuecomment-2216986250

Should help with #3514 though I'll wait to close until it's confirmed as
we cannot reproduce this.
2024-07-10 10:08:47 -05:00
Zanie Blue
d497adaacb
Improve 'any' search message during uv python install (#4940)
Special cases the `Any` request in output

e.g.,

```
❯ cargo run -q -- python install --isolated
warning: `uv python install` is experimental and may change without warning.
Searching for Python installations
Found existing installation: cpython-3.12.3-macos-aarch64-none
Python is already available. Use `uv python install <request>` to install a specific version.
```

instead of 

```
❯ cargo run -q -- python install --isolated
warning: `uv python install` is experimental and may change without warning.
Searching for Python versions matching: any Python
Found existing installation for any Python: cpython-3.12.3-macos-aarch64-none
Python is already available. Use `uv python install <request>` to install a specific version.
```
2024-07-10 15:03:22 +00:00
Jo
42ccce9641
Fix index_strategy doc (#4955)
## Summary

There is a missing `)` after `first_match`.
2024-07-10 08:54:23 -05:00
Ibraheem Ahmed
d833910a5d
Avoid reparsing wheel URLs (#4947)
## Summary

We currently store wheel URLs in an unparsed state because we don't have
a stable parsed representation to use with rykv. Unfortunately this
means we end up reparsing unnecessarily in a lot of places, especially
when constructing a `Lock`. This PR adds a `UrlString` type that lets us
avoid reparsing without losing the validity of the `Url`.

## Test Plan

Shaves off another ~10 ms from
https://github.com/astral-sh/uv/issues/4860.

```
➜  transformers hyperfine "../../uv/target/profiling/uv lock" "../../uv/target/profiling/baseline lock" --warmup 3
Benchmark 1: ../../uv/target/profiling/uv lock
  Time (mean ± σ):     120.9 ms ±   2.5 ms    [User: 126.0 ms, System: 80.6 ms]
  Range (min … max):   116.8 ms … 125.7 ms    23 runs
 
Benchmark 2: ../../uv/target/profiling/baseline lock
  Time (mean ± σ):     129.9 ms ±   4.2 ms    [User: 127.1 ms, System: 86.1 ms]
  Range (min … max):   123.4 ms … 141.2 ms    23 runs

Summary
  ../../uv/target/profiling/uv lock ran
    1.07 ± 0.04 times faster than ../../uv/target/profiling/baseline lock
```
2024-07-10 05:16:30 -04:00
Charlie Marsh
23eb42deed
Allow constraints to be provided in --upgrade-package (#4952)
## Summary

Allows, e.g., `--upgrade-package flask<3.0.0`.

Closes https://github.com/astral-sh/uv/issues/1964.
2024-07-09 20:09:13 -07:00
Ibraheem Ahmed
aff9c9bd91
Switch to Current-Thread Tokio Runtime (#4934)
## Summary

Move completely off tokio's multi-threaded runtime. We've slowly been
making changes to be smarter about scheduling in various places instead
of depending on tokio's general purpose work-stealing, notably
https://github.com/astral-sh/uv/pull/3627 and
https://github.com/astral-sh/uv/pull/4004. We now no longer benefit from
the multi-threaded runtime, as we run on all I/O on the main thread.
There's one remaining instance of `block_in_place` that can be swapped
for `rayon::spawn`.

This change is a small performance improvement due to removing some
unnecessary overhead of the multi-threaded runtime (e.g. spawning
threads), but nothing major. It also removes some noise from profiles.

## Test Plan

```
Benchmark 1: ./target/profiling/uv (resolve-warm)
  Time (mean ± σ):      14.9 ms ±   0.3 ms    [User: 3.0 ms, System: 17.3 ms]
  Range (min … max):    14.1 ms …  15.8 ms    169 runs
 
Benchmark 2: ./target/profiling/baseline (resolve-warm)
  Time (mean ± σ):      16.1 ms ±   0.3 ms    [User: 3.9 ms, System: 18.7 ms]
  Range (min … max):    15.1 ms …  17.3 ms    162 runs
 
Summary
  ./target/profiling/uv (resolve-warm) ran
    1.08 ± 0.03 times faster than ./target/profiling/baseline (resolve-warm)
```
2024-07-09 18:21:16 -04:00
Charlie Marsh
540ff24302
Perform lock in uv sync by default (#4839)
## Summary

- `uv sync` will now lock by default.
- `uv sync --locked` will lock, and error if the generated lock does not
match `uv.lock` on-disk.
- `uv sync --frozen` will skip locking and just use `uv.lock`.

Closes https://github.com/astral-sh/uv/issues/4812.
Closes https://github.com/astral-sh/uv/issues/4803.
2024-07-09 15:18:30 -07:00
Ibraheem Ahmed
8c9bd70c71
Avoid serializing if lockfile does not change (#4945)
## Summary

Avoid serializing and writing the lockfile if a cheap comparison shows
that the contents have not changed.

## Test Plan

Shaves ~10ms off of https://github.com/astral-sh/uv/issues/4860 for me.

```
➜  transformers hyperfine "../../uv/target/profiling/uv lock" "../../uv/target/profiling/baseline lock" --warmup 3
Benchmark 1: ../../uv/target/profiling/uv lock
  Time (mean ± σ):     130.5 ms ±   2.5 ms    [User: 130.3 ms, System: 85.0 ms]
  Range (min … max):   126.8 ms … 136.9 ms    23 runs
 
Benchmark 2: ../../uv/target/profiling/baseline lock
  Time (mean ± σ):     140.5 ms ±   5.0 ms    [User: 142.8 ms, System: 85.5 ms]
  Range (min … max):   133.2 ms … 153.3 ms    21 runs
 
Summary
  ../../uv/target/profiling/uv lock ran
    1.08 ± 0.04 times faster than ../../uv/target/profiling/baseline lock
```
2024-07-09 17:08:27 -04:00
Zanie Blue
dc80fdba2c
Do not use pager for root uv help and improve after help hint (#4936)
Adds a nice hint at the bottom of `uv help` output indicating how to get
more details about a specific command, roughly matching Cargo's
interface.

We use the short help and skip the pager for the root `uv help` since
it's intended to be a landing page for the help interface more than an
in-depth display. This also matches Cargo, though I like that they have
the global options above the commands and I've not changed that here.
2024-07-09 14:38:28 -05:00
Charlie Marsh
55e1a7e011
Enable --all to uninstall all managed tools (#4937)
## Summary

Like #4932 but for tools.
2024-07-09 19:26:17 +00:00
Charlie Marsh
bb703b8343
Reinstall and recreate environments when interpreter is removed (#4935)
## Summary

We now recreate the environment in `uv sync`, `uv tool install`, and `uv
tool run` if the underlying interpreter has been removed.

Closes https://github.com/astral-sh/uv/issues/4933.
2024-07-09 19:25:23 +00:00
konsti
53db63f6dd
Apply extra to overrides and constraints (#4829)
This is an attempt to solve https://github.com/astral-sh/uv/issues/ by
applying the extra marker of the requirement to overrides and
constraints.

Say in `a` we have a requirements
```
b==1; python_version < "3.10"
c==1; extra == "feature"
```

and overrides
```
b==2; python_version < "3.10"
b==3; python_version >= "3.10"
c==2; python_version < "3.10"
c==3; python_version >= "3.10"
```

Our current strategy is to discard the markers in the original
requirements. This means that on 3.12 for `a` we install `b==3`, but it
also means that we add `c` to `a` without `a[feature]`, causing #4826.
With this PR, the new requirement become,

```
b==2; python_version < "3.10"
b==3; python_version >= "3.10"
c==2; python_version < "3.10" and extra == "feature"
c==3; python_version >= "3.10" and extra == "feature"
```

allowing to override markers while preserving optional dependencies as
such.

Fixes #4826
2024-07-09 20:37:24 +02:00
Charlie Marsh
0a04108a15
Enable --all to uninstall all managed Pythons (#4932)
## Summary

Allows `--all` as an alternative to specifying specific targets.

## Test Plan

Verified that `cargo run python uninstall` still fails.

```
❯ cargo run python uninstall --all
   Compiling uv-cli v0.0.1 (/Users/crmarsh/workspace/puffin/crates/uv-cli)
   Compiling uv v0.2.23 (/Users/crmarsh/workspace/puffin/crates/uv)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.86s
     Running `target/debug/uv python uninstall --all`
warning: `uv python uninstall` is experimental and may change without warning.
Searching for Python installations
Found existing installation: cpython-3.9.18-macos-aarch64-none
Found existing installation: cpython-3.8.18-macos-aarch64-none
Found existing installation: cpython-3.8.12-macos-aarch64-none
Found existing installation: cpython-3.12.1-macos-aarch64-none
Found existing installation: cpython-3.11.7-macos-aarch64-none
Found existing installation: cpython-3.10.13-macos-aarch64-none
Uninstalled cpython-3.10.13-macos-aarch64-none
Uninstalled cpython-3.11.7-macos-aarch64-none
Uninstalled cpython-3.12.1-macos-aarch64-none
Uninstalled cpython-3.8.12-macos-aarch64-none
Uninstalled cpython-3.8.18-macos-aarch64-none
Uninstalled cpython-3.9.18-macos-aarch64-none
Uninstalled 6 versions in 479ms
```
2024-07-09 18:15:16 +00:00
Zanie Blue
bd7a25f604
Use paging for uv help display when available (#4909)
Extends https://github.com/astral-sh/uv/pull/4906

Adds paged display of "long' help to `uv help` invocations when `less`
or `more` is available.
2024-07-09 18:06:27 +00:00
Charlie Marsh
92290d8dcb
Respect resolver settings in uv remove (#4930)
## Summary

Closes https://github.com/astral-sh/uv/issues/4925
2024-07-09 17:46:31 +00:00
Zanie Blue
5f20bdb2ee
Implement uv help manually instead of using Clap default (#4906)
Extends #4772 

Implements `uv help` ourselves so we can do things like #4909 
Adds hints to use `uv help` for more details during short help display.
2024-07-09 17:43:13 +00:00
Charlie Marsh
2e307d9081
Avoid inferring package name for GitHub Archives (#4928)
## Summary

Closes https://github.com/astral-sh/uv/issues/4917.
2024-07-09 17:30:43 +00:00
Zanie Blue
0bf562f197
Display short help menu when --help is used (#4772)
I feel like I'm always drowning in the help output from `uv` because we
have so many options.

I basically agree with the commentary in
https://github.com/clap-rs/clap/issues/4687 that having different
behaviors for `-h` and `--help` is surprising. I think `--help` is more
obvious for users and I want to optimize for that experience.

This roughly matches the help menus in Cargo and pip.

The `uv help` command can be used for long help. In #4906 and #4909 we
improve that command.

Extends #4904 which adds test cases for the existing behavior.
2024-07-09 17:12:01 +00:00
Charlie Marsh
72dd34b225
Filter out markers based on Python requirement (#4912)
## Summary

In marker normalization, we now remove any markers that are redundant
with the `requires-python` specifier (i.e., always true for the given
Python requirement).

For example, given `iniconfig ; python_version >= '3.7'`, we can remove
the `python_version >= '3.7'` marker when resolving with
`--python-version 3.8`.

Closes #4852.
2024-07-09 09:15:58 -07:00
Charlie Marsh
a046d23f79
Avoid AND-ing multi-term specifiers in marker normalization (#4911)
## Summary

Given `python_version != '3.8' and python_version < '3.10'`, the first
term was expanded to `python_version < '3.8'` and `python_version >
'3.8'`. We then AND'd all three terms together. We don't seem to have a
way to differentiate between the terms to AND and the terms to OR in the
normalization code (it all gets flattened together), so instead this PR
expands the expressions at the leaf level and then flattens them at the
level above when appropriate.

Closes https://github.com/astral-sh/uv/issues/4910.
2024-07-09 16:04:26 +00:00
Zanie Blue
b4a7d96d4e
Add test cases for the CLI help menu (#4904)
No changes in behavior here, adding these test cases to demonstrate
changes to come.
2024-07-09 09:07:43 -05:00
Charlie Marsh
72982c1bff
Add command-separation for Python discovery display (#4916)
## Summary

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

```
error: No interpreter found for Python 3.12.4 in virtual environments, managed installations, or system path
```
2024-07-09 05:51:30 +00:00
Charlie Marsh
f862457f05
Avoid debug error for uv run with unknown Python version (#4913)
## Summary

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

## Test Plan

```
> cargo run -- run -vv --preview --isolated --python 3.12.4 python -V
error: No interpreter found for Python 3.12.4 in virtual environments or managed installations or system path
```
2024-07-09 05:29:55 +00:00
Ibraheem Ahmed
ed4234d52e
Filter and flatten markers (#4639)
## Summary

More marker simplification:
- Filters out redundant subtrees based on outer expressions, e.g. `a and (a or
b)` simplifies to `a`.
- Flattens nested trees internally, e.g. `(a and b) and c`

Resolves https://github.com/astral-sh/uv/issues/4536.
2024-07-08 18:59:21 +00:00
Ibraheem Ahmed
dc7ad3abdb
Implement uv tree (#4708)
## Summary

Implements the `uv tree`, which displays dependencies from the lockfile
as a tree. Resolves https://github.com/astral-sh/uv/issues/4699.
2024-07-08 18:07:48 +00:00
Zanie Blue
4bc36c0cb8
Bump version to 0.2.23 (#4903) 2024-07-08 12:29:37 -05:00
Andrew Gallant
857d2e8f1e uv-resolver: partially revert Requires-Python version narrowing
The PR #4707 introduced the notion of "version narrowing," where a
Requires-Python constraint was _possibly_ narrowed whenever the
universal resolver created a fork. The version narrowing would occur
when the fork was a result of a marker expression on `python_version`
that is *stricter* than the configured `Requires-Python` (via, say,
`pyproject.toml`).

The crucial conceptual change made by #4707 is therefore that
`Requires-Python` is no longer an invariant configuration of resolution,
but rather a mutable constraint that can vary from fork to fork. This in
turn can result in some cases, such as in #4885, where different
versions of dependencies are selected. We aren't sure whether we can fix
those or not, with version narrowing, so for now, we do this revert to
restore the previous behavior and we'll try to address the version
narrowing some other time.

This also adds the case from #4885 as a regression test, ensuring that
we don't break that in the future. I confirmed that with version
narrowing, this test outputs duplicate distributions. Without narrowing,
there are no duplicates.

Ref #4707, Fixes #4885
2024-07-08 09:56:59 -07:00
Charlie Marsh
ac3a085084
Respect requires-python when prefetching (#4900)
## Summary

This is fallout from https://github.com/astral-sh/uv/pull/4705. We need
to respect `requires-python` in the prefetch code to avoid building
unsupported distributions.

Closes https://github.com/astral-sh/uv/issues/4898.
2024-07-08 16:32:09 +00:00
Charlie Marsh
71c6a9fad3
Sort dependencies before wheels and source distributions (#4897)
Closes https://github.com/astral-sh/uv/issues/4889.
2024-07-08 14:25:05 +00:00