Commit graph

2855 commits

Author SHA1 Message Date
Jo
2c214e7585
Use install_only python archive (#4843)
## Summary

Resolves #4834

## Test Plan

```sh
# 3.12.3 is a `install_only` archive
$ cargo run -- python install --preview --force 3.12.3

# 3.9.4 has only `full` archive
$ cargo run -- python install --preview --force 3.9.4
```
2024-07-06 21:43:55 -05:00
konsti
7117359ca9
Update trampolines (#4850)
Follow-up to https://github.com/astral-sh/uv/pull/4722
2024-07-06 21:06:48 +00:00
samypr100
eee90a340c
feat: re-enable std in uv-trampoline (#4722)
## Summary

Partially closes #1917

This PR picks up on some of the great work from #1864 and opted to keep
`panic_immediate_abort` (for size reasons). I split the PR in different
isolated commits in case we want to separate/cherry-pick them out.

1. The first commit ports mostly all std changes from that PR into this
PR. Binary sizes stayed the same ~16kb.
2. The second commit migrates our existing usage of windows-sys to
windows for a safer ffi calls with Results!. It also changes all large
unsafe blocks to be isolated to the actual unsafe calls, and switches
some areas to use std such as getenv port ( which seemed buggy! ) from
launcher.c. In addition, this also adds more error checking in order to
match some missing assertions from distlib's launcher.c. Note, due to
the additional .text data, the binary sizes increased to ~20.5kb, but we
can cut back on some of the added error msgs as needed.
3. The third commit switches to using xwin for building on all 3
supported trampoline targets for sanity, and adds a CI bloat check for
core::fmt and panic as a precaution. Sadly, this will invalidate the
xwin cache on the first run.

## Test Plan

Most changes were tested on a couple of local GUI apps and console apps,
also tested some of the error states manually by using SetLastError at
different points in the code and/or passing in invalid handles.

I'm not sure how far we can get with migrating some of the other calls
without increasing binary size substantially. An initial attempt at
using std::path didn't seem so bad size wise when I tried it (~1k). On
other cases, such as std::process::exit added ~10k to the total binary
size.

---------

Co-authored-by: konstin <konstin@mailbox.org>
2024-07-06 20:38:45 +00:00
Ahmed Ilyas
6c8ce1d013
uv cache prune removes all cached environments (#4845)
## Summary

Resolves #4802

## Test Plan
- `cargo test`
```sh
❯ cargo run -- cache prune -v
Pruning cache at: /Users/ahmedilyas/Library/Caches/uv
No unused entries found
❯ cargo run -- tool run cowsay
warning: `uv tool run` is experimental and may change without warning.
Resolved 1 package in 182ms
Installed 1 package in 20ms
 + cowsay==6.1
usage: Cowsay [-h] [-c CHARACTER] -t TEXT [-v]
Cowsay: error: the following arguments are required: -t/--text
❯ cargo run -- cache prune -v
Pruning cache at: /Users/ahmedilyas/Library/Caches/uv
    0.793440s DEBUG uv_cache Removing dangling cache entry: /Users/ahmedilyas/Library/Caches/uv/environments-v1/095cd7c4c298a0d8
Removed 41 files (143.5KiB)
```
2024-07-06 19:37:15 +00:00
Charlie Marsh
798ec373c0
Create empty environment for uv run --isolated (#4849)
## Summary

If you pass `--isolated` but no `--with`, at present, we don't create
any environment (so `--python` isn't respected and `python` will fail
entirely if it wasn't already in your path). Now, we create a base
environment in `--isolated` even if `with` wasn't provided.

Closes https://github.com/astral-sh/uv/issues/4846.
Closes https://github.com/astral-sh/uv/issues/4776.
2024-07-06 19:22:19 +00:00
Jo
1f454f3a67
Revert uninstall deduplication changes from #4841 (#4842)
`matching_installations` is BTreeSet already, no need to deduplicate it.

https://github.com/astral-sh/uv/pull/4841#discussion_r1667241722
2024-07-06 14:16:52 -05:00
Jo
bcb2568f47
Deduplicate when install or uninstall python (#4841)
When specifying the same argument multiple times, the same version will
be downloaded multiple times:

```sh

$ cargo run -- python install --preview --force 3.12.3 cpython-3.12 3.12.3 3.12
Looking for installation Python 3.12.3 (any-3.12.3-any-any-any)
Looking for installation cpython-3.12-any-any-any (cpython-3.12-any-any-any)
Looking for installation Python 3.12.3 (any-3.12.3-any-any-any)
Looking for installation Python 3.12 (any-3.12-any-any-any)
Found 4/4 versions requiring installation
Downloading cpython-3.12.3-windows-x86_64-none
Downloading cpython-3.12.3-windows-x86_64-none
Downloading cpython-3.12.3-windows-x86_64-none
Downloading cpython-3.12.3-windows-x86_64-none
```

This PR deduplicates the `ManagedPythonDownload` before `install` or
`uninstall`:

```sh
$ cargo run -q -- python install --preview --force 3.12.3 cpython-3.12 3.12.3 3.12
Looking for installation Python 3.12 (any-3.12-any-any-any)
Looking for installation Python 3.12.3 (any-3.12.3-any-any-any)
Looking for installation cpython-3.12-any-any-any (cpython-3.12-any-any-any)
Downloading cpython-3.12.3-windows-x86_64-none
Installed Python 3.12.3 to C:\Users\nigel\AppData\Roaming\uv\data\python\cpython-3.12.3-windows-x86_64-none
Installed 1 version in 6s

$ cargo run -q -- python uninstall --preview  3.12.3 cpython-3.12 3.12.3 3.12
Looking for Python installations matching Python 3.12 (any-3.12-any-any-any)
Found installation `cpython-3.12.3-windows-x86_64-none` that matches Python 3.12
Looking for Python installations matching Python 3.12.3 (any-3.12.3-any-any-any)
Looking for Python installations matching cpython-3.12-any-any-any (cpython-3.12-any-any-any)
Uninstalled `cpython-3.12.3-windows-x86_64-none`
Removed 1 Python installation
```
2024-07-05 22:05:17 -05:00
Charlie Marsh
1bd73a7346
Bold durations in CLI messages (#4818)
I guess the `.bold()` on the preceding text causes the `.dimmed()` to...
stop?

But you can compare before and after:

![Screenshot 2024-07-04 at 2 06
41 PM](b8298cce-5c7f-4a65-8279-93f1c777344c)

Closes #4817.
2024-07-05 16:58:33 -05:00
Charlie Marsh
32ea636585
Preserve verbatim URLs for --find-links (#4838)
Also gets rid of a lot of duplicated logic for `--find-links`.

Closes https://github.com/astral-sh/uv/issues/4797
2024-07-05 16:57:40 -05:00
Zanie Blue
c0ca0b02b8
Fill Python requests with platform information during automatic fetches (#4810)
Closes https://github.com/astral-sh/uv/issues/4800

We do this during `install` — it's an important step to ensure the
request has the platform information in it.
2024-07-05 21:13:57 +00:00
Charlie Marsh
77b1bb77b5
Fix some ephemeral-to-cached comments (#4837) 2024-07-05 21:11:19 +00:00
Charlie Marsh
f450b45780
Add UV_OVERRIDE environment variable for --override (#4836)
Closes https://github.com/astral-sh/uv/issues/4827
2024-07-05 16:03:17 -05:00
Charlie Marsh
3fa09a3972
Require at least one target for toolchain uninstalls (#4820)
Closes https://github.com/astral-sh/uv/issues/4816.
2024-07-04 18:31:40 -04:00
Charlie Marsh
a13ab43a0d
Tweak installation language in toolchain install (#4811)
## Summary

Like https://github.com/astral-sh/uv/pull/4808 but with a few more
changes. I suspect this will require some bikeshedding but I find the
use of "installation" and "installed" in the same sentence to be kind of
a lot.
2024-07-04 17:05:31 -04:00
Charlie Marsh
b588054dfb
Always use release-only comparisons for requires-python (#4794)
## Summary

There are a few ideas at play here:

1. pip always strips versions to the release when evaluating against a
`Requires-Python`, so we now do the same. That means, e.g., using
`3.13.0b0` will be accepted by a project with `Requires-Python: >=
3.13`, which does _not_ adhere to PEP 440 semantics but is somewhat
intuitive.
2. Because we know we'll only be evaluating against release-only
versions, we can use different semantics in PubGrub that let us collapse
ranges. For example, `python_version >= '3.10' or python_version <
'3.10'` can be collapsed to the truthy marker.

Closes https://github.com/astral-sh/uv/issues/4714.
Closes https://github.com/astral-sh/uv/issues/4272.
Closes https://github.com/astral-sh/uv/issues/4719.
2024-07-04 20:06:52 +00:00
konsti
11cb0059c1
Remove incompatible wheels from uv.lock (#4799)
Remove wheels from the lockfile that don't match the required python
version. For example, we remove
`charset_normalizer-3.3.2-cp311-cp311-win_amd64.whl` when we have
`requires-python = ">=3.12"`.

Our snapshots barely show changes since we avoid the large binaries for
which matters. Here are 3 real world `uv.lock` before/after comparisons
to show the large difference:
*
[warehouse](https://gist.github.com/konstin/9a1ed6a32b410e250fcf4c6ea8c536a5)
(5677 -> 4214)
*
[transformers](https://gist.github.com/konstin/5636281b5226f64aa44ce3244d5230cd)
(6484 -> 5816)
*
[github-wikidata-bot](https://gist.github.com/konstin/ebbd7b9474523aaa61d9a8945bc02071)
(793 -> 454)

We only remove wheels we are certain don't match the python version and
still keep those with unknown tags. We could remove even more wheels by
also considering other markers, e.g. removing linux wheels for a
windows-only dep, but we would trade complex, easy-to-get-wrong logic
for diminishing returns.
2024-07-04 14:03:54 -04:00
Jo
dac3161f90
Check hash of downloaded python toolchain (#4806)
## Summary

Check the sha256 checksum when downloading a managed python toolchain.

## Test Plan

```sh
$ cargo run -- python install 3.12

warning: `uv python install` is experimental and may change without warning.
Looking for installation Python 3.12.3 (any-3.12.3-any-any-any)
Downloading cpython-3.12.3-windows-x86_64-none
Installed Python 3.12.3 to C:\Users\jo\AppData\Roaming\uv\data\python\cpython-3.12.3-windows-x86_64-none
Installed 1 installation in 6s

$ cargo run -- python uninstall 3.12

$ # manually change the hash in `crates/uv-python/src/downloads.inc`

$ cargo run -- python install 3.12

warning: `uv python install` is experimental and may change without warning.
Looking for installation Python 3.12 (any-3.12-any-any-any)
Downloading cpython-3.12.3-windows-x86_64-none
error: Hash mismatch for `cpython-3.12.3-windows-x86_64-none`

Expected:
xx

Computed:
776568c92c5f3b47dbf5f17c1c58578f70d75a32654419a158aa8bdc6f95b09a
```
2024-07-04 17:49:12 +00:00
Charlie Marsh
445d45b82c
Always use base interpreter for cached environments (#4805)
Closes #4801.
2024-07-04 17:38:53 +00:00
Charlie Marsh
6a27135a65
Use cached environments in PEP 723 execution (#4789)
## Summary

This seems like another good candidate for environment caching. If you
run a script repeatedly, we can just use the existing cached
environment.
2024-07-04 17:23:13 +00:00
konsti
892106fef0
Box clap args some more for uv init (#4796)
Fixes stack overflows in tests for
https://github.com/astral-sh/uv/pull/4791
2024-07-04 13:22:24 -04:00
Danny
35afcfd053
Enable Registry Client Builder to be created from Base Client Builder (#4729)
<!--
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? -->
Addresses https://github.com/astral-sh/uv/issues/4330, to reduce
duplication in the client creation logic.
## Test Plan

<!-- How was it tested? -->
https://github.com/astral-sh/uv/pull/4729#issuecomment-2204681655
2024-07-04 15:53:05 +00:00
Jo
0a336dacab
Remove installed python for force installation (#4807)
## Summary

Currently `uv python install` does not respect `--force` reinstallation,
the downloading process is just skipped if the installation existed.

```
$ uv python install 3.12

Looking for installation Python 3.12 (any-3.12-any-any-any)
Downloading cpython-3.12.3-windows-x86_64-none
Installed Python 3.12.3 to C:\Users\jo\AppData\Roaming\uv\data\python\cpython-3.12.3-windows-x86_64-none
Installed 1 installation in 6s

$ uv python install --force 3.12

Looking for installation Python 3.12 (any-3.12-any-any-any)
Found installed installation `cpython-3.12.3-windows-x86_64-none` that satisfies Python 3.12
Downloading cpython-3.12.3-windows-x86_64-none
Installed 1 installation in 0s
```

## Test Plan


```
$ uv python install 3.12

Looking for installation Python 3.12 (any-3.12-any-any-any)
Downloading cpython-3.12.3-windows-x86_64-none
Installed Python 3.12.3 to C:\Users\jo\AppData\Roaming\uv\data\python\cpython-3.12.3-windows-x86_64-none
Installed 1 installation in 6s

$ uv python install --force 3.12

Looking for installation Python 3.12 (any-3.12-any-any-any)
Found installed installation `cpython-3.12.3-windows-x86_64-none` that satisfies Python 3.12
Removing installed installation `cpython-3.12.3-windows-x86_64-none`
Downloading cpython-3.12.3-windows-x86_64-none
Installed Python 3.12.3 to C:\Users\jo\AppData\Roaming\uv\data\python\cpython-3.12.3-windows-x86_64-none
Installed 1 installation in 7s
```
2024-07-04 11:13:14 -04:00
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
1e8f5926e6
Upgrade to cargo-dist v0.18.0 (#4792)
## Summary

This enables us to get rid of `allow-dirty`!
2024-07-03 22:39:51 +00: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
Di-Is
60fd98a5e4
Include uvx binary to docker image. (#4764)
Fix #4763

## Summary

Modify the Dockerfile to include the uvx binary in the docker image
`ghcr.io/astral-sh/uv`.

## Test Plan

I have verified that the uvx binary is included in the Docker image
built with the following command and can be executed.

```bash
# cd repository root
docker build -t uv:add_uvx .
docker run --rm --entrypoint /uvx uv -V

uv-tool-run 0.2.21
```
2024-07-03 07:51:55 -04:00
konsti
42415997b1
Reactivate python 3.13 in CI (#4761)
https://github.com/actions/setup-python/issues/888#issuecomment-2205466950
2024-07-03 11:28:45 +02: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
samypr100
f43a8bbd6f
Upgrade to Rust 1.79 (#4754)
## Summary

Updates default toolchain to
[1.79](https://blog.rust-lang.org/2024/06/13/Rust-1.79.0.html).
There didn't seem to be any breaking changes besides xwin now requiring
lld llvm linker.

## Test Plan

Existing tests.
2024-07-02 23:50:47 -05:00
Zanie Blue
ebfe6d8fcc
Bump version to 0.2.21 (#4757) 2024-07-03 04:27:00 +00:00
Zanie Blue
88c2a8e30f
Add uvx.exe binary to Windows artifacts (#4756)
Closes https://github.com/astral-sh/uv/issues/4755
2024-07-02 23:16:20 -05: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