Commit graph

2887 commits

Author SHA1 Message Date
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
Charlie Marsh
b9d661012d
Initialize all --prefix subdirectories (#4895)
## Summary

We need to initialize the same directories that we create in `bare.rs`,
since the installer expects them to exist.

Closes #4892.
2024-07-08 14:15:25 +00:00
Charlie Marsh
2d651fe264
Add some text decoration to toolchain CLI (#4882)
## Summary

Attempts to make the CLI output a little more consistent with the `pip`
interface. I opted to make the Python versions, requests, and filenames
blue, and the keys green, but open to opinions on that. (We use blue for
filenames elsewhere.)

Closes #4813.
Closes https://github.com/astral-sh/uv/issues/4814.

![Screenshot 2024-07-07 at 9 18
48 PM](8518b559-196b-4cd0-bc16-8e79e66460bb)
2024-07-08 10:03:38 -04:00
konsti
57cfe1e229
Small forking log improvements (#4894)
I found the current messages insufficient when tracking down a bug.
2024-07-08 13:56:57 +00:00
Charlie Marsh
4f340580c7
Show user-facing warning when falling back to copy installs (#4880)
## Summary

This has come up a few times including in a recent email to me.
2024-07-08 13:35:58 +00:00
Charlie Marsh
947cfa13a8
Add some decoration to tool CLI (#4865)
Mostly small things. I added entrypoint counts and bolded the executable
names.

Closes https://github.com/astral-sh/uv/issues/4815.
2024-07-08 09:21:05 -04:00
Andrew Gallant
fb19372a00 uv/tests: fix tool_install_home test
This test was, I believe, relying on the XDG_DATA_HOME environment
variable not being set. When it is set, as is the case in my
environment, `uv tool run` will respect it and install `black` for this
particular test into my actual XDG_DATA_HOME directory. We fix this by
setting `XDG_DATA_HOME` explicitly.
2024-07-08 06:12:53 -07:00
Charlie Marsh
ffcc05240e
Add user-facing output to indicate PEP 723 script (#4881) 2024-07-08 02:05:13 +00:00
Charlie Marsh
ae242c3b8f
Ensure Pythons are aligned in uv python list (#4884)
## Summary

The existing tab input sometimes leads to misalignment on my machine, I
think it has to do with breakpoints?

![Screenshot 2024-07-07 at 9 22
43 PM](c95c5d26-3acb-48a6-8cce-d76f219f5afe)

This PR computes the width explicitly, and then pads each line. I also
added some colors to the RHS. I think it makes it easier to scan, but
don't feel strongly.

![Screenshot 2024-07-07 at 9 36
56 PM](1c89c83b-9562-4597-a892-021573c48f8d)
2024-07-07 21:52:30 -04:00
Charlie Marsh
98a720ec08
Skip installing --with requirements if present in base environment (#4879)
## Summary

Closes #4547.
2024-07-08 01:23:59 +00:00
konsti
a76d04b159
Box::pin(run()) and 2MB test stack (#4851)
By using `Box::pin(run())` we can reduce the artificial stack size for
running tests on windows in debug mode from 8MB to 2MB. I've checked and
1MB/no custom stack size still fail tests, e.g.
`add_workspace_editable`.
2024-07-07 20:50:36 -04:00
renovate[bot]
b21f3226a6
Update pre-commit dependencies (#4876) 2024-07-08 00:31:24 +00:00
renovate[bot]
889f4efd21
Update Rust crate syn to v2.0.69 (#4875) 2024-07-08 00:26:58 +00:00
renovate[bot]
7a914b900c
Update Rust crate serde_json to v1.0.120 (#4874) 2024-07-07 20:25:18 -04:00
renovate[bot]
621e0e9df8
Update Rust crate serde to v1.0.204 (#4873) 2024-07-07 20:25:13 -04:00
renovate[bot]
f07f1006d9
Update Rust crate reflink-copy to v0.1.19 (#4872) 2024-07-07 20:25:08 -04:00
renovate[bot]
08c544ddd5
Update Rust crate hyper-util to v0.1.6 (#4871) 2024-07-07 20:25:00 -04:00
renovate[bot]
28e71eba99
Update Rust crate axoupdater to v0.6.8 (#4870) 2024-07-07 20:24:52 -04:00
renovate[bot]
12a922261f
Update Rust crate async-trait to v0.1.81 (#4869) 2024-07-07 20:24:46 -04:00
konsti
1a31938626
Update windows binaries, again (#4864)
https://github.com/astral-sh/uv/pull/4850#issuecomment-2212557050
2024-07-07 18:58:22 -04:00
Charlie Marsh
389582a37e
Avoid creating cache directories in tool directory (#4868)
Closes https://github.com/astral-sh/uv/issues/4867.
2024-07-07 21:19:07 +00:00
Charlie Marsh
a302d704c5
Fix always-plural message in uv python install (#4866) 2024-07-07 20:29:19 +00:00
Jo
f4c4b69cc7
Add progress bar when downloading python (#4840)
## Summary

Resolves #4825 

## Test Plan

```sh
$ cargo run -- python install --force --preview
$ cargo run -- venv -p 3.12 --python-preference only-managed
$ cargo run -- tool install --preview -p 3.12 --python-preference only-managed --force black
````

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-07-07 20:01:35 +00:00
konsti
9e50864508
Ignore compile_invalid_pyc_invalidation_mode on all platforms (#4863)
This test is failing most times for me when running nextest locally,
failing the overall test run, so i'm deactivating it for now. I'm still
not sure what the root cause here is. It seems to have something to do
with python stdin not being ready immediately after we spawn the process
and us being too fast.
2024-07-07 19:46:41 +00:00
Charlie Marsh
f5e84bbbab
Bump version to v0.2.22 (#4862) 2024-07-07 19:23:38 +00:00
konsti
d787e69f7c
Rename Workspace.root to Workspace.install_path (#4859)
Renaming in preparation of #4833, which adds a `Workspace.lock_path`. No
functional changes.
2024-07-07 18:35:41 +00:00
konsti
91e4d880a9
Remove dead code from tests (#4856)
Looks like an oversight
2024-07-07 11:48:34 -05:00
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