Commit graph

2395 commits

Author SHA1 Message Date
Charlie Marsh
cf004fd644
Rename EphemeralEnvironment to CachedEnvironment (#4804) 2024-07-04 13:57:12 +00:00
Charlie Marsh
c6f72d333a
Resolve requirements prior to nuking tool environments (#4788)
## Summary

Closes #4747.
2024-07-04 09:45:26 -04:00
konsti
d178d97a40
Document the RequiresPython fields (#4798) 2024-07-04 08:27:02 -04:00
Ibraheem Ahmed
576ba9c522
Avoid hangs before exiting CLI (#4793)
## Summary

The resolver sometimes starts HTTP requests that end up not being
necessary. When dropping the Tokio runtime before exiting we currently
wait for those to complete. This can cause noticeable hangs in the CLI,
particularly when the runtime is blocked on slow DNS resolution.

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

## Test Plan

This change resolves any reproducible hangs for me locally.
2024-07-03 20:05:44 -04:00
Charlie Marsh
de40f798b9
Cache tool environments in uv tool run (#4784)
## Summary

The basic strategy:

- When the user does `uv tool run`, we resolve the `from` and `with`
requirements (always).
- After resolving, we generate a hash of the requirements. For now, I'm
just converting to a lockfile and hashing _that_, but that's an
implementation detail.
- Once we have a hash, we _also_ hash the interpreter.
- We then store environments in
`${CACHE_DIR}/${INTERPRETER_HASH}/${RESOLUTION_HASH}`.

Some consequences:

- We cache based on the interpreter, so if you request a different
Python, we'll create a new environment (even if they're compatible).
This has the nice side-effect of ensuring that we don't use environments
for interpreters that were later deleted.
- We cache the `from` and `with` together. In practice, we may want to
cache them separately, then layer them? But this is also an
implementation detail that we could change later.
- Because we use the lockfile as the cache key, we will invalidate the
cache when the format changes. That seems ok, but we could improve it in
the future by generating a stable hash from a lockfile that's
independent of the schema.

Closes https://github.com/astral-sh/uv/issues/4752.
2024-07-03 19:25:39 -04:00
Charlie Marsh
6a4c4ace2b
Always use exact semantics in update_environment (#4790)
## Summary

We don't need to expose this -- these are always environments that we
want to be perfectly synced.
2024-07-03 21:23:21 +00:00
Charlie Marsh
814b3c45bc
Fix misleading description contains docstring (#4783)
## Summary

This doesn't include pre-releases by default. Maybe it did at one point!
2024-07-03 14:28:40 -04:00
Caíque Porfirio
c17761904e
feat: add tool version to list command (#4674)
<!--
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?
-->
Closes #4653

## Summary
Adds the tool version to the list command right beside the tool name

```
$ uv tool list
black v24.2.0
```

Following the proposed format discussed in #4653


## Test Plan
`cargo test tool_list`

<!-- How was it tested? -->

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-07-03 18:24:37 +00:00
Charlie Marsh
d24b075b2d
Add --exclude-newer to installer arguments (#4785)
## Summary

We already support this in `pip sync` and have it stubbed to `None` in
`sync.
2024-07-03 18:05:05 +00:00
konsti
37f15367bb
Box clap commands to avoid windows debug clap stack overflow (#4768)
The changes in https://github.com/astral-sh/uv/pull/4708 caused an
overflow in debug mode only of the 1MB default stack size in windows
during clap. This means that even trivial wrong argument tests would
fail without increasing the stack size. As remedy, we box the clap
types.
2024-07-03 19:06:15 +02:00
Zanie Blue
1c6c8db1a2
Add dedicated help menu for uvx (#4770)
Closes #4749
2024-07-03 16:38:54 +00:00
Zanie Blue
c0875fd8fe
Improvements to the Python metadata fetch script (#4780)
This fell out of my investigation of
https://github.com/astral-sh/uv/issues/4774 but the bug was fixed by the
reporter in #4775

- Adds support for `GH_TOKEN` authentication again — basically needed to
avoid rate limits when hacking on this.
- Clarifies some handling and logging of flavors
2024-07-03 11:36:59 -05:00
Zanie Blue
81442f0b4c
Update "about" in help menu (#4782)
Following #4773 

```
❯ cargo run -q -- -h
An extremely fast Python package manager.

Usage: uv [OPTIONS] <COMMAND>
```
2024-07-03 11:36:38 -05:00
Charlie Marsh
f980e3f4fc
Use already-installed tools in uv tool run (#4750)
## Summary

This doesn't cache the tool environment; rather, it just uses the `tool
install` environment if it satisfies the request.

Closes https://github.com/astral-sh/uv/issues/4742.
2024-07-03 16:35:11 +00:00
Zanie Blue
a604f15028
Drop the crate description from the uv help menu (#4773)
Previously this displayed:

```
❯ cargo run -q -- --help
The command line interface for the uv binary.

Usage: uv [OPTIONS] <COMMAND>
```

This is.. weird. Here I remove it entirely. I could see adding
`about_long` text being helpful in the future.
2024-07-03 11:11:36 -05:00
Di-Is
dc4ff84443
Use optimized versions of managed Python on Linux (#4775)
Fix #4774.

## Summary

Change the python interpreter for linux installed with `uv python` to an
optimized one.

## Test Plan

I ran the following command on Linux (glibc) to confirm that an
optimized (not debug built) Python is installed.

```bash
# install python
uv python install 3.12.3

# check build type
uv run python -c "import sysconfig;print(sysconfig.get_config_var('Py_DEBUG'))"
0
```
2024-07-03 10:58:04 -05:00
Charlie Marsh
d858fb8901
Make in-flight part of shared state struct (#4778)
## Summary

Now that we don't need to re-initialize it, this seems simpler.
2024-07-03 15:51:51 +00:00
Charlie Marsh
b6575fe487
Avoid resetting dispatch and in-flight state with reinstalls (#4771)
## Summary

This used to be necessary because we purged the cache in the
`InstallPlan` if the user passed `--reinstall`. _However_, we later
changed the cache to be append-only.

## Test Plan

I ran through the test plan in https://github.com/astral-sh/uv/pull/933,
which includes an integration test and running `uv pip install
--reinstall` with:

```text
setuptools
devpi @ e334eb4dc9/devpi-2.2.0.tar.gz
```
2024-07-03 10:31:51 -04:00
konsti
dcdf26eead
Make path_with_trailing_space_gives_proper_error language independent (#4767)
The test currently fails on windows machines with non-english locale.
2024-07-03 12:46:30 +00:00
Zanie Blue
dd7da6af5f
Change "toolchain" to "python" (#4735)
Whew this is a lot.

The user-facing changes are:

- `uv toolchain` to `uv python` e.g. `uv python find`, `uv python
install`, ...
- `UV_TOOLCHAIN_DIR` to` UV_PYTHON_INSTALL_DIR`
- `<UV_STATE_DIR>/toolchains` to `<UV_STATE_DIR>/python` (with
[automatic
migration](https://github.com/astral-sh/uv/pull/4735/files#r1663029330))
- User-facing messages no longer refer to toolchains, instead using
"Python", "Python versions" or "Python installations"

The internal changes are:

- `uv-toolchain` crate to `uv-python`
- `Toolchain` no longer referenced in type names
- Dropped unused `SystemPython` type (previously replaced)
- Clarified the type names for "managed Python installations"
- (more little things)
2024-07-03 07:44:29 -05:00
pppp56
174414c5da
Add entrypoints to tool list (#4661)
<!--
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?
-->
Closes #4654 
## Summary

The purpose of this is to show the entrypoints of each tool when running
`uv tool list` as below:

```
$ uv tool list
black
    black
    blackd

```

I used the proposed formatting as it was written in #4653 by @blueraft.
I had to use spaces instead of tabs in order to make the test
successful. Indeed in the test we are using a raw string and I did not
manage to make the test pass when escaping the tab in the list.rs file
so I used spaces everywhere.

I had a deeper look into #4653 as well but it is more difficult as we
need to get the version of the tool in the Tool object, I will continue
on this next one later.

Please tell me if anything else is needed I tried to follow the
contribution guidelines but I might have forgotten something.
Have a great day!


## Test Plan

`cargo clippy`

then by using the local version of uv as described in the Readme.md. 


```
my-computer :~/mypath/uv$ cargo run -- tool list
   Compiling uv-cli v0.0.1 (/mypath/uv/crates/uv-cli)
   Compiling uv v0.2.18 (/mypath/uv/crates/uv)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 18.69s
     Running `target/debug/uv tool list`
warning: `uv tool list` is experimental and may change without warning.
black
  black
  blackd
isort
  isort
  isort-identify-imports

```

and 

`cargo test tool_list`

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-07-02 23:54:19 -05:00
Zanie Blue
ebfe6d8fcc
Bump version to 0.2.21 (#4757) 2024-07-03 04:27:00 +00:00
David Poznik
7bb9b96dc3
Differentiate freeze and list help text (#4751)
`uv pip freeze` and `uv pip list` had identical help text. This PR
differentiates them.
2024-07-02 23:44:57 +00:00
Charlie Marsh
75731452d8
Replace tool environments on updated Python request (#4746)
## Summary

Closes https://github.com/astral-sh/uv/issues/4741.
2024-07-02 23:07:55 +00:00
Zanie Blue
e88e1373e6
Bump version to 0.2.20 (#4745) 2024-07-02 22:30:43 +00:00
Zanie Blue
c5bf64abeb
Bump version to 0.2.19 (#4738) 2024-07-02 21:15:58 +00:00
Charlie Marsh
676d550410
Remove dangling environments in tool uninstall (#4740)
## Summary

It seems useful that `tool uninstall` guarantees the tool is gone (e.g.,
if the receipt and environment get out-of-sync somehow).
2024-07-02 21:03:39 +00:00
Charlie Marsh
32dc9bef59
Respect tool upgrades in uv tool install (#4736)
## Summary

For now the semantics are such that if the requested requirements from
the command line don't match the receipt (or if any `--reinstall` or
`--upgrade` is requested), we proceed with an install, passing the
`--reinstall` and `--upgrade` to the underlying Python environment.

This may lead to some unintuitive behaviors, but it's simplest for now.
For example:

- `uv tool install black<24` followed by `uv tool install black
--upgrade` will install the latest version of `black`, removing the
`<24` constraint.
- `uv tool install black --with black-plugin` followed by `uv tool
install black` will remove `black-plugin`.

Closes https://github.com/astral-sh/uv/issues/4659.
2024-07-02 16:46:31 -04:00
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
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