Commit graph

2698 commits

Author SHA1 Message Date
Charlie Marsh
21187e1f36
Accept package names in the tool API (#4737)
## Summary

It seems helpful that these _not_ accept arbitrary strings.
2024-07-02 15:30:40 -04:00
Zanie Blue
c8987269ff
Lock the toolchains directory during toolchain operations (#4733) 2024-07-02 13:31:30 -05:00
Ibraheem Ahmed
a380e8e4df
Add conversion from lockfile Distribution to Metadata (#4706)
## Summary

Splitting this out from https://github.com/astral-sh/uv/pull/4495
because it's also useful to reuse the `uv pip tree` code for `uv tree`.
2024-07-02 18:03:20 +00:00
konsti
4b19319485
Show when we retried requests (#4725)
In #3514 and #2755, users had intermittent network errors, but it was
not always clear whether we had already retried these requests or not.
Building upon https://github.com/TrueLayer/reqwest-middleware/pull/159,
this PR adds the number of retries to the error message, so we can see
at first glance where we're missing retries and where we might need to
change retry settings.

Example error trace:

```
Could not connect, are you offline?
  Caused by: Request failed after 3 retries
  Caused by: error sending request for url (https://pypi.org/simple/uv/)
  Caused by: client error (Connect)
  Caused by: dns error: failed to lookup address information: Name or service not known
  Caused by: failed to lookup address information: Name or service not known
```

This code is ugly since i'm missing a better pattern for attaching
context to reqwest middleware errors in
https://github.com/TrueLayer/reqwest-middleware/pull/159.
2024-07-02 19:04:11 +02:00
Zanie Blue
12e12d066d
Restructure documentation sections to focus on new user experience (#4586)
Moving the preview features to top-level concepts and pushing the
pip-compatible interface down.

e.g.

<img width="291" alt="Screenshot 2024-06-27 at 7 03 48 AM"
src="500ad97d-899d-4051-b59d-e74786b3a45f">
2024-07-02 11:44:45 -05:00
Charlie Marsh
d05bb45c74
Omit pythonX.Y segment in stdlib on managed Windows (#4727)
## Summary

Windows omits this segment, IIRC.

Closes https://github.com/astral-sh/uv/issues/4724.
2024-07-02 09:21:15 -04:00
Zanie Blue
2c0cb6e021
Allow uv pip sync to clear an environment with opt-in (#4517)
Closes https://github.com/astral-sh/uv/issues/4516

Open to some deliberation about the opt-in strategy here.
2024-07-02 13:14:27 +00:00
Charlie Marsh
d9f389a58d
Narrow requires-python requirement in resolver forks (#4707)
## Summary

Given:

```text
numpy >=1.26 ; python_version >= '3.9'
numpy <1.26 ; python_version < '3.9'
```

When resolving for Python 3.8, we need to narrow the `requires-python`
requirement in the top branch of the fork, because `numpy >=1.26` all
require Python 3.9 or later -- but we know (in that branch) that we only
need to _solve_ for Python 3.9 or later.

Closes https://github.com/astral-sh/uv/issues/4669.
2024-07-02 12:23:38 +00:00
Charlie Marsh
89b3324ae1
Move Requires-Python incompatibilities out of version map (#4705)
## Summary

This is required to solve https://github.com/astral-sh/uv/issues/4669,
because the `Requires-Python` version can now vary across a resolution.
For example, within certain forks, we might have a more narrow range,
which would allow us to use distributions that would not be allowed for
the global resolution.

This should be fine because `requires-python` is part of the package
metadata, so it should be consistent between files within a package
version. As such, there shouldn't be any risk that we incorrectly
prioritize distributions by omitting this information.

(To be more specific, the risk is something like: we prioritize some
wheel over a source distribution within a package-version, so we don't
track the source distribution at all. Then, later, when we choose a
candidate, we see that the wheel doesn't meet the `Requires-Python`
requirement, even though the source distribution _would've_ met it. If
files within a distribution could have varied support, this would be a
real risk.)
2024-07-02 08:15:39 -04:00
Zanie Blue
8dabc29d80
Add uv toolchain uninstall (#4646) 2024-07-02 02:37:53 +00:00
Zanie Blue
ad5151cda8
Fetch managed toolchains if necessary in uv tool install and uv tool run (#4717)
Hey we should download toolchains here if we need to, right!?
2024-07-01 21:27:43 -05:00
Zanie Blue
c0a06a2c1b
Drop prefer prefix from toolchain-preference values (#4602)
I think `--toolchain-preference system` is sufficiently clear and
`--toolchain-preference prefer-system` is excessively verbose. This was
discussed in the original pull request at
https://github.com/astral-sh/uv/pull/4424 but because we had a case for
preferring "installed managed" toolchains I was hesitant to change it.
Now that I've dropped that in #4601, I think we can drop the prefix.
2024-07-02 02:07:30 +00:00
Zanie Blue
6799cc883a
Allow configuring the toolchain fetch strategy (#4601)
Adds a `toolchain-fetch` option alongside `toolchain-preference` with
`automatic` (default) and `manual` values allowing automatic toolchain
fetches to be disabled (replaces
https://github.com/astral-sh/uv/pull/4425). When `manual`, toolchains
must be installed with `uv toolchain install`.

Note this was previously implemented with `if-necessary`, `always`,
`never` variants but the interaction between this and
`toolchain-preference` was too confusing. By reducing to a binary
option, things should be clearer. The `if-necessary` behavior moved to
`toolchain-preference=installed`. See
https://github.com/astral-sh/uv/pull/4601#discussion_r1657839633 and
https://github.com/astral-sh/uv/pull/4601#discussion_r1658658755
2024-07-02 01:54:24 +00:00
Zanie Blue
ec2723a9f5
Add uvx alias for uv tool run (#4632)
Closes https://github.com/astral-sh/uv/issues/4476

Originally, this used the changes in #4642 to invoke `main()` from a
`uvx` binary. This had the benefit of `uvx` being entirely standalone at
the cost of doubling our artifact size. We think that's the incorrect
trade-off.

Instead, we assume `uvx` is always next to `uv` and create a tiny binary
(<1MB) that invokes `uv` in a child process. This seems preferable to a
`cargo-dist` alias because we have more control over it. This binary
should "just work" for all of our cargo-dist distributions and
installers, but we'll need to add a new entry point for our PyPI
distribution. I'll probably tackle support there separately?

```
❯ ls -lah target/release/uv target/release/uvx
-rwxr-xr-x  1 zb  staff    31M Jun 28 23:23 target/release/uv
-rwxr-xr-x  1 zb  staff   452K Jun 28 23:22 target/release/uvx
```

This includes some small overhead:

```
❯ hyperfine --shell=none --warmup=100 './target/release/uv tool run --help' './target/release/uvx --help' --min-runs 2000
Benchmark 1: ./target/release/uv tool run --help
  Time (mean ± σ):       2.2 ms ±   0.1 ms    [User: 1.3 ms, System: 0.5 ms]
  Range (min … max):     2.0 ms …   4.0 ms    2000 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: ./target/release/uvx --help
  Time (mean ± σ):       2.9 ms ±   0.1 ms    [User: 1.7 ms, System: 0.9 ms]
  Range (min … max):     2.8 ms …   4.2 ms    2000 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Summary
  ./target/release/uv tool run --help ran
    1.35 ± 0.09 times faster than ./target/release/uvx --help
```

I presume there may be some other downsides to a child process? The
wrapper is a little awkward. We could consider `execv` but this is
complicated across platforms. An example implementation of that over in
[monotrail](433af5aed9/crates/monotrail/src/monotrail.rs (L764-L799)).
2024-07-01 20:42:02 -05:00
Charlie Marsh
8e935e2c17
Support unnamed requirements in uv tool install (#4716)
## Summary

This PR adds support for (e.g.) `uv tool install
git+https://github.com/psf/black`.

Closes https://github.com/astral-sh/uv/issues/4664.
2024-07-01 21:37:14 -04:00
Charlie Marsh
368276d7d1
Shared Git and in-memory index across operations (#4715)
## Summary

I ended up needing this for https://github.com/astral-sh/uv/issues/4664
but I think it's a good change more broadly. We should be able to share
this cached information across operations within a given invocation.
2024-07-01 20:27:01 -04:00
Charlie Marsh
13077406f8
Add lockfile snapshots for branching URL tests (#4713)
## Summary

These are changing in one of my branches but I can't tell _what's_
changing. Some tests include the lock, but others don't. This PR adds it
for all successful resolves in the suite.
2024-07-01 22:24:50 +00:00
Chan Kang
61014d48b0
Implement --package for pip tree (#4655)
## Summary

Part of https://github.com/astral-sh/uv/issues/4439.

## Test Plan

The existing tests pass + added a couple of tests to ensure `--package` behaves as expected.
2024-07-01 21:12:59 +00:00
Charlie Marsh
a4417eba4a
Enable projects to opt-out of workspace management (#4565)
## Summary

You can now add `managed = false` under `[tool.uv]` in a
`pyproject.toml` to explicitly opt out of the project and workspace
APIs.

If a project sets `managed = false`, we will (1) _not_ discover it as a
workspace root, and (2) _not_ discover it as a workspace member (similar
to using `exclude` in the workspace parent).

Closes https://github.com/astral-sh/uv/issues/4551.
2024-07-01 16:17:43 -04:00
Ibraheem Ahmed
be2a67cd9b
Replace map_or(false, ..) uses with is_some_and and is_ok_and (#4703)
## Summary

Looks like there isn't a clippy lint for this yet.
2024-07-01 19:28:42 +00:00
Ibraheem Ahmed
8a2af8bc83
More uv pip tree cleanup (#4702)
## Summary

Follow up to https://github.com/astral-sh/uv/pull/4700.
2024-07-01 15:21:38 -04:00
Ibraheem Ahmed
ea031461c5
Simplify OnceMap::wait_blocking (#4704)
## Summary

De-duplicate by calling directly into the async version.
2024-07-01 15:17:37 -04:00
Charlie Marsh
f3d1e52e65
Use requires-python semantics for --universal (#4701)
## Summary

This doesn't actually change any behaviors, but it does make it a bit
easier to solve #4669, because we don't have to support "version
narrowing" for the non-`RequiresPython` variants in here. Right now, the
semantics are kind of muddied, because the `target` variant is
_sometimes_ interpreted as an exact version and sometimes as a lower
bound.
2024-07-01 15:16:40 -04:00
Ibraheem Ahmed
348efa26ba
Clean up uv pip tree code (#4700)
## Summary

Minor improvements/nits.
2024-07-01 17:56:16 +00:00
Ibraheem Ahmed
58499439d3
Fix implementation of GitDatabase::contains (#4698)
## Summary

`GitDatabase::contains` previously only parsed the commit to see if it
was a valid hash and didn't verify if the commit existed in the object
database. This led to the database never being updated.

Resolves https://github.com/astral-sh/uv/issues/4378.

## Test Plan

Added a test that fails without this change.
2024-07-01 13:01:29 -04:00
Chan Kang
5715def24b
Implement --invert for pip tree (#4621)
## Summary

Part of https://github.com/astral-sh/uv/issues/4439.

## Test Plan

Existing tests pass + added a couple of new tests with `--invert`.
2024-07-01 12:58:28 -04:00
konsti
0ee4a2cc6e
Remove SolveState to ForkState (#4683)
It's hard to talk about solve state and resolver state, so i'm renaming
them to fork state and resolver state, indicating the hierarchy between
more directly.
2024-07-01 12:33:50 -04:00
Charlie Marsh
305868cdcc
Show dedicated message for tools with no entrypoints (#4694)
## Summary

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

## Test Plan

```
❯ cargo run tool install ruff
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/uv tool install ruff`
warning: `uv tool install` is experimental and may change without warning.
Resolved 1 package in 136ms
Installed 1 package in 3ms
 + ruff==0.5.0
No entrypoints to install for tool `ruff`
```
2024-07-01 12:22:45 -04:00
Charlie Marsh
324e9fe5cf
Respect data scripts in uv tool install (#4693)
## Summary

Packages that provide scripts that _aren't_ Python entrypoints need to
respected in `uv tool install`. For example, Ruff ships a script in
`ruff-0.5.0.data/scripts`.

Unfortunately, the `.data` directory doesn't exist in the virtual
environment at all (it's removed, per the spec, after install). So this
PR changes the entry point detection to look at the `RECORD` file, which
is the only evidence that the scripts were installed.

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

## Test Plan

`cargo run uv tool install ruff` (snapshot tests to-come)
2024-07-01 12:22:37 -04:00
Ahmed Ilyas
081f092781
Add tool dir and toolchain dir commands (#4695)
## Summary

Resolves #4483 
Resolves #4484 

## Test Plan

`cargo test`

```sh
❯ cargo run -- toolchain dir
warning: `uv toolchain dir` is experimental and may change without warning.
/Users/ahmedilyas/Library/Application Support/uv/toolchains

❯ cargo run -- tool dir
warning: `uv tool dir` is experimental and may change without warning.
/Users/ahmedilyas/Library/Application Support/uv/tools
```
2024-07-01 14:51:59 +00:00
Charlie Marsh
65cd676da7
Reinstall entrypoints with --force (#4697)
## Summary

I think this may have just been a typo.

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

## Test Plan

Run `cargo run tool install flask --force --reinstall` repeatedly.
2024-07-01 14:25:11 +00:00
Charlie Marsh
977a5c8835
Use a single mutable preferences for forks (#4690)
## Summary

Avoids a quadratic loop.

See: https://github.com/astral-sh/uv/pull/4662.
2024-07-01 12:47:28 +00:00
Charlie Marsh
1557ad1b3c
DRY up some project interpreter validation and discovery (#4658)
## Summary

I noticed that `init_environment` and `find_interpreter` were both
calling `find_environment`, which seemed like a code smell to me.
Instead, `find_interpreter` now returns either a compatible environment
or an interpreter (if no compatible environment was found).

Additionally, `interpreter_meets_requirements` now no longer validates
`requires-python` if `--python` or `.python-version` is set. Instead, we
warn, which matches the behavior we get when creating a new environment
at the bottom of `find_interpreter`.

In total, I think this makes the data flow in project interpreter
discovery less repetitive and easier to reason about.
2024-07-01 12:31:42 +00:00
Charlie Marsh
2d57309b0f
Set fork solution as preference when resolving (#4662)
## Summary

This should both make it faster to solve forks (since we have a guess
for a valid resolution, and will bias towards packages we've already
fetched) and improve consistency between forks.

Closes https://github.com/astral-sh/uv/issues/4617.
2024-07-01 08:25:40 -04:00
Charlie Marsh
bfadadefaf
Add PEP 723 support to uv run (#4656)
Closes #3096 

## Summary

Enables `uv run foo.py` to execute PEP 723-compatible scripts.

For example, given:

```python
# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "requests<3",
#   "rich",
# ]
# ///

import requests
from rich.pretty import pprint

resp = requests.get("https://peps.python.org/api/peps.json")
data = resp.json()
pprint([(k, v["title"]) for k, v in data.items()][:10])
```

![Screenshot 2024-06-29 at 7 23
52 PM](c60f2415-4874-4b15-b9f5-dd8c8c35382e)
2024-07-01 08:20:24 -04:00
konsti
bbd2deb64f
Fix tool dist-info directory normalization (#4686)
`.dist-info` directories use a different normalization.

Fixes #4685
2024-07-01 10:43:56 +00:00
konsti
049833e037
Log when we start solving a fork (#4684)
Adds a debug log message with the markers.
2024-07-01 08:46:54 +00:00
renovate[bot]
8f881d4796
Update Rust crate dashmap to v6 (#4682) 2024-07-01 01:49:15 +00:00
renovate[bot]
d680241486
Update pre-commit hook astral-sh/ruff-pre-commit to v0.5.0 (#4681) 2024-07-01 01:48:10 +00:00
renovate[bot]
36625465c1
Update Rust crate reqwest-retry to 0.6.0 (#4680) 2024-06-30 21:45:35 -04:00
renovate[bot]
56ecc4617a
Update Rust crate either to v1.13.0 (#4678) 2024-06-30 21:45:19 -04:00
renovate[bot]
8b5d979010
Update Rust crate serde_json to v1.0.119 (#4677) 2024-06-30 21:45:03 -04:00
renovate[bot]
87b7ccb37c
Update Rust crate reqwest-middleware to v0.3.2 (#4676) 2024-06-30 21:44:57 -04:00
renovate[bot]
4c8aaed532
Update Rust crate clap to v4.5.8 (#4675) 2024-06-30 21:40:23 -04:00
Charlie Marsh
8ea47ab45f
Add --disable-pip-version-check to compatibility arguments (#4672)
## Summary

Closes https://github.com/astral-sh/uv/issues/4590.
2024-06-30 23:43:23 +00:00
Charlie Marsh
d5501274d8
Omit (*) in uv pip tree for empty packages (#4673)
## Summary

Closes https://github.com/astral-sh/uv/issues/4665.
2024-06-30 23:42:06 +00:00
Charlie Marsh
ac87fd4006
Disable Clippy's too-many-arguments rule (#4663)
## Summary

We allow this constantly, I think it's just too pedantic for us.
2024-06-30 19:30:38 +00:00
Charlie Marsh
b4c53fd15f
Add a command abstraction to uv run (#4657)
## Summary

Small refactor broken out from #4656.
2024-06-30 10:40:37 -04:00
Chan Kang
7cc4565b5b
fix the issue with pruning the last package in pip tree (#4652)
<!--
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
resolves https://github.com/astral-sh/uv/issues/4651
(pruning needs to happen at the parent level so that the number of
children being used to figure out the output is correct)

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

## Test Plan
added a test that would've caught this bug 🌵 
<!-- How was it tested? -->
2024-06-29 17:45:34 -05:00
Charlie Marsh
13b0beb56f
Bump version to v0.2.18 (#4650) 2024-06-29 14:30:01 -04:00