Commit graph

6006 commits

Author SHA1 Message Date
konstin
d0e84cfb03 Add test 2025-03-05 18:11:03 +01:00
konstin
c23bc77e8a Re-query the interpreter for new venvs
Co-authored-by: Pradyun Gedam <pgedam@bloomberg.net>

When a venv is created, values such as `sys.path` and `site.getsitepackages()` are different from the base interpreter, which we query from the interpreter directly instead of trying to do the transformation ourselves.
2025-03-05 18:04:25 +01:00
konstin
cd7a1dbe07 Discover packages through site.getsitepackages() entries
Previously, uv was discovering packages only in purelib/platlib, which excluded system site packages if activated.

`site.getsitepackages()` is more stable than `sys.path`. `sys.path` can change in a number of ways such as `.pth` files and runtime modification, while `site.getsitepackages()` is generally stable for a Python environment. Using the `site`, we get the same paths that Python itself uses for `sys.path`.
2025-03-05 18:04:25 +01:00
konstin
2146d44a6f Handle package duplication and shadowing
This behavior was originally written for supporting `sys.path` instead of `site.getsitepackages()`: It's currently not load-bearing, but it is correct deduplication if we need to add more paths to the package discovery in the future.

With this change the behavior of `uv pip list` mirrors the behavior of `pip list`: It shows only the first package in `sys.path`, which is the package that Python will load, and ignores the others.

In the JSON output, we show all packages, but tagged with a `shadowed` bool. The exception is `--outdated`, in which case we only check if the main packages are outdated (updating shadowed packages is ineffective). The consumer is responsible for filtering on `shadowed` if applicable.

We show a hint (stderr, not stdout like the main output), if shadowed packages exist.

The logic includes handling of the fedora lib/lib64 venv split.
2025-03-05 18:04:25 +01:00
Pradyun Gedam
099282f772 Rename SitePackages to InstalledPackages
This better reflects the intended behavior of this object, which is to
serve as a database of InstalledPackages rather than a representation of
the relevant environment/interpreter path.
2025-03-05 18:04:25 +01:00
konstin
76d95fdfdf Fix ManagedPythonInstallations bug 2025-03-05 18:04:25 +01:00
Charlie Marsh
28ff80b639
Respect markers on constraints when validating current environment (#11976)
## Summary

Small omission I noticed last night. This was overly strict (so, didn't
lead to any incorrect behavior; more that we did unnecessary work in
some cases).
2025-03-05 09:25:30 -05:00
Alex Lowe
7340ff72da
Add NO_BUILD and NO_BUILD_PACKAGE environment variables (#11968)
<!--
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? -->
Similar to https://github.com/astral-sh/uv/pull/11399

This adds `UV_NO_BUILD` and `UV_NO_BUILD_PACKAGE` environment variables
for non-pip commands.

## Test Plan

<!-- How was it tested? -->
Tested manually and with snapshot tests.


Fixes #11963

Signed-off-by: Alex Lowe <alex@lowe.dev>
2025-03-04 22:58:19 -06:00
Charlie Marsh
0f5b106dae
Fix empty constraints in satisfies check (#11971)
## Summary

Oversight from my constraints PR in `uv tool run`.
2025-03-05 03:11:20 +00:00
Charlie Marsh
5a3771967f
Remove Serialize implementations from some settings (#11969)
## Summary

We never serialize these (and we may need to transform them prior to
doing so).
2025-03-05 02:55:57 +00:00
Ed Morley
3c81e4121b
Fix include_system_side_packages typo (#11967)
`s/include_system_side_packages/include_system_site_packages/`
2025-03-05 00:49:35 +00:00
github-actions[bot]
f5acd60ac9
Fix PyPy Python version label (#11965)
Closes https://github.com/astral-sh/uv/issues/11863

Co-authored-by: zanieb <2586601+zanieb@users.noreply.github.com>
2025-03-05 00:36:21 +00:00
Charlie Marsh
3a53ec3c5a
Compare major-minor specifiers when filtering interpreters (#11952)
## Summary

If we're looking at (e.g.) `python3.12`, and we have a `requires-python:
">=3.12.7, <3.13"`, then checking if the range includes `3.12` will
return `false`. Instead, we need to look at the lower- and upper-bound
major-minors of the `requires-python`.

Closes https://github.com/astral-sh/uv/issues/11825.
2025-03-04 23:29:39 +00:00
Hugo van Kemenade
6578885a45
Update top-pypi-packages filename (#11959)
<!--
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? -->

To stay within quota, it now has just under 30 days of data, so the
filename has been updated. Both will be available for a while. See
https://github.com/hugovk/top-pypi-packages/pull/46.


## Test Plan

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

```sh
curl https://hugovk.github.io/top-pypi-packages/top-pypi-packages-30-days.min.json | jq -r ❯ 
curl https://hugovk.github.io/top-pypi-packages/top-pypi-packages.min.json | jq -r ".rows | .
diff pypi_8k_downloads_original.txt pypi_8k_downloads_new.txt
```
2025-03-04 18:23:02 -05:00
konsti
a169dbeabe
Fix system site packages detection default (#11956)
See https://docs.python.org/3/library/site.html and
a549f43938/Lib/site.py (L614-L639):
The default is for system site packages is true, they have to be
disabled by setting the key to something that is not true.
2025-03-04 18:22:13 -05:00
Zanie Blue
b7f98f1ff2
Use the Depot Ubuntu runners instead of GitHub for release workflows (#11948)
See

-
https://opensource.axo.dev/cargo-dist/book/reference/config.html#github-custom-runners
- https://github.com/axodotdev/cargo-dist/issues/1760
- #11935
2025-03-04 13:28:14 -06:00
Charlie Marsh
8f8c0e8918
Move LowerBound and UpperBound structs in uv-pep440 (#11950)
## Summary

I want to use these in `uv-python` and there's nothing specific to the
resolver or even to Python in these structs.
2025-03-04 12:35:16 -05:00
konsti
6132d252d6
Remove unused UV_STACK_SIZE env vars (#11957)
These were overlooked in #10479
2025-03-04 16:53:34 +00:00
konsti
12f8d6f2c5
Remove prepended sys.path (#11954)
We prepend the interpreter discovery in a temporary path to `sys.path`,
which we have to strip to avoid the `sys.path` value containing a
then-deleted temp dir.
2025-03-04 16:00:26 +00:00
Zanie Blue
f44aba0a96
Run the Docker build workflow when we touch project or toolchain metadata (#11938)
I noticed that https://github.com/astral-sh/uv/pull/11936 did not run
the Docker builds, nor did #11934

We should run these when the relevant files change so there aren't
surprises at release time!

Updates the `build-binaries` workflow to include toolchain version
changes and `.cargo/config.toml` changes too.
2025-03-04 08:36:20 -06:00
John Mumm
c072c9adca
Return error when running uvx with a .py script (#11623)
If we see `uvx script.py`, we exit early, giving a hint to use `uv run
script.py` if the script exists. If it does not exist, we suggest
running `uv run` with a normalized package name.

This PR includes a snapshot test for each of these scenarios.

An alternative approach would be to wait until we encounter an error,
and then add the hint. But if there happens to be a malicious package
called `script-py`, this would be run unintentionally (a point raised by
@zanieb).
 
Closes #10784

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2025-03-04 14:29:36 +00:00
Lewis Gaul
3b83b48fd2
Fix error message suggesting --user instead of --username (#11947)
<!--
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
Fix error message suggesting `--user` instead of `--username`:
```
   > uv publish --publish-url ... ... --password $(cat ~/.token)
Publishing 1 file to ...
error: Attempted to publish with a password, but no username. Either provide a username with `--user` (`UV_PUBLISH_USERNAME`), or use `--token` (`UV_PUBLISH_TOKEN`) instead of a password.

   > uv publish --publish-url ... ... --user lewis --password $(cat ~/.token)
error: unexpected argument '--user' found

  tip: a similar argument exists: '--username'

Usage: uv publish <FILES|--index <INDEX>|--username <USERNAME>|--password <PASSWORD>|--token <TOKEN>|--trusted-publishing <TRUSTED_PUBLISHING>|--keyring-provider <KEYRING_PROVIDER>|--publish-url <PUBLISH_URL>|--check-url <CHECK_URL>|--skip-existing>

For more information, try '--help'.
```

## Test Plan
I have not tested manually, I'm hoping this isn't necessary and there
will be sufficient CI coverage.
2025-03-04 08:58:08 -05:00
Charlie Marsh
b460e51e19
Allow --constraints and --overrides in uvx (#10207)
## Summary

Closes https://github.com/astral-sh/uv/issues/9813.
2025-03-04 02:18:48 +00:00
Zanie Blue
04db70662d
Explicitly install the rust toolchain before the target during Docker builds (#11936)
Fixes
3813172442
2025-03-03 17:17:56 -06:00
Zanie Blue
f0ec9fd44a
Bump version to 0.6.4 (#11934) 2025-03-03 16:04:11 -06:00
Victorien
e89485ef05
Fix typo in no_default_groups documentation and changelog (#11928)
<!--
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? -->

## Test Plan

<!-- How was it tested? -->
2025-03-03 18:44:12 +00:00
Charlie Marsh
c3d809d276
Migrate to zlib-rs (again) (#11894)
## Summary

I believe `zlib-rs` is now a better choice on ARM and x86, so I'm just
going to assume it's a better choice everywhere. It's much easier to
build (removes our CMake dependency), and in my benchmarking, it's
substantially faster on ARM and faster or ~exactly even on my x86
Windows machine.

We migrated to `zlib-rs` once before (#9184); however, I later reverted
it as I learned that they were only doing compile-time feature
detection, and so `zlib-rs` was meaningfully slower on x86. They now
perform runtime feature detection:
https://trifectatech.org/blog/zlib-rs-is-faster-than-c/.

To benchmark, I wrote a script to create a local Simple API-compliant
registry (see the commit history) for a single package. Then I ran the
`install-cold` benchmark against that registry to install NumPy.

On ARM:

```
❯ uv run resolver --uv-pip-path ../../zlib-ng --uv-pip-path ../../zlib-rs \
        --benchmark install-cold \
        req.txt --warmup 10 --min-runs 30
Benchmark 1: ../../zlib-ng (install-cold)
  Time (mean ± σ):     165.7 ms ±  34.7 ms    [User: 64.4 ms, System: 93.2 ms]
  Range (min … max):   141.8 ms … 293.2 ms    30 runs

Benchmark 2: ../../zlib-rs (install-cold)
  Time (mean ± σ):     150.9 ms ±  16.2 ms    [User: 57.4 ms, System: 86.4 ms]
  Range (min … max):   135.3 ms … 202.4 ms    30 runs

Summary
  ../../zlib-rs (install-cold) ran
    1.10 ± 0.26 times faster than ../../zlib-ng (install-cold)
```

I benchmarked this about 100 times on my Windows machine and found it
difficult to conclude anything beyond "They're nearly the same". Here's
an example:

```
PS C:\Users\crmar\workspace\puffin> hyperfine --prepare "uv venv" "zlib-rs.exe pip sync ./scripts/benchmark/req.txt" "zlib-ng.exe pip sync ./scripts/benchmark/req.txt" "zlib-rs.exe pip sync ./scripts/benchmark/req.txt" "zlib-ng.exe pip sync ./scripts/benchmark/req.txt" --runs 10 --warmup 5
Benchmark 1: zlib-rs.exe pip sync ./scripts/benchmark/req.txt
  Time (mean ± σ):     240.6 ms ±  10.8 ms    [User: 6.1 ms, System: 92.2 ms]
  Range (min … max):   229.4 ms … 267.9 ms    10 runs

Benchmark 2: zlib-ng.exe pip sync ./scripts/benchmark/req.txt
  Time (mean ± σ):     241.3 ms ±   6.2 ms    [User: 7.7 ms, System: 90.6 ms]
  Range (min … max):   233.9 ms … 252.1 ms    10 runs

Benchmark 3: zlib-rs.exe pip sync ./scripts/benchmark/req.txt
  Time (mean ± σ):     242.8 ms ±   7.7 ms    [User: 6.2 ms, System: 23.4 ms]
  Range (min … max):   236.1 ms … 262.8 ms    10 runs

Benchmark 4: zlib-ng.exe pip sync ./scripts/benchmark/req.txt
  Time (mean ± σ):     245.9 ms ±   5.7 ms    [User: 1.5 ms, System: 59.4 ms]
  Range (min … max):   240.9 ms … 257.3 ms    10 runs

Summary
  zlib-rs.exe pip sync ./scripts/benchmark/req.txt ran
    1.00 ± 0.05 times faster than zlib-ng.exe pip sync ./scripts/benchmark/req.txt
    1.01 ± 0.06 times faster than zlib-rs.exe pip sync ./scripts/benchmark/req.txt
    1.02 ± 0.05 times faster than zlib-ng.exe pip sync ./scripts/benchmark/req.txt
```

Closes #11885.
2025-03-03 17:29:31 +00:00
John Mumm
a5fa7fa996
Replace outdated DevGroups* naming (#11921)
At certain points in the code, dependency groups are represented by
`DevGroups*` naming, probably as a historical artifact. This PR updates
the naming.

This includes renaming `uv-configuration/src/dev.rs` to
`uv-configuration/src/dependency_groups.rs`.
2025-03-03 16:39:44 +01:00
Eric Mark Martin
d57bb90499
explicitly handle ctrl-c in confirmation prompt instead of signal handler (#11897)
<!--
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

Follow on to #11706. In the original PR, I tried to solve the issue by
getting rid of the `ctrlc::set_handler` call. Unfortunately, this didn't
work on windows due to an issue with the console crate. console 0.15.11
includes https://github.com/console-rs/console/pull/235, which resolves
the issue, so now we can get rid of the call.

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

This change is not super important but I still think it's worthwhile.
For one, spinning up a background thread to handle `SIGINT`s when we're
going to be raising the `SIGINT` from within the function is more
technical complexity than needed, now that there's an easy way to
explicitly catch the Ctrl-C from the terminal input. Secondly,
`ctrlc::set_handler`'s
[docs](https://docs.rs/ctrlc/3.4.5/ctrlc/fn.set_handler.html) advise
that you set the handler just once, at the beginning of the program, so
this use seems somewhat error prone. In fact, uv already has a second
[callsite](461f4d9007/crates/uv/src/commands/project/add.rs (L596-L611))
for this function (though I'm not sure if the two callsites could
currently ever both occur on the same run of uv)

## Test Plan

I've tested this manually on linux (WSL ubuntu) and windows, though not
on aarch64-apple-darwin as I don't have a machine running that. I would
appreciate if someone would double-check that it works on such machines.

As discussed in the original PR, this change is pretty hard to test due
to the fact that the behavior only occurs if stderr is connected to a
tty. I experimented with using pseudoterminals to test this but it's
still quite tricky due to the lack of x-platform non-blocking reads on
the pty.

<!-- How was it tested? -->
2025-03-03 10:30:48 -05:00
Charlie Marsh
a141818ed8
Avoid string allocation when enumerating tool names (#11910)
## Summary

If it's not ASCII, then it's not a valid package name anyway.
2025-03-03 10:13:54 -05:00
konsti
ceffd7ff80
Discover registry PEP 514 Pythons cross 32/64-bit (#11801)
Fixes #11217

By default, a 64-bit uv does not see a 32-bit global (HKLM) installation
of Python in the registry
(https://github.com/astral-sh/uv/issues/11217). To work around this, we
manually request both 32-bit and 64-bit access using registry access
flags (https://peps.python.org/pep-0514/#sample-code). The flags have no
effect on 32-bit (https://stackoverflow.com/a/12796797/3549270).

This effect is that there is an asymmetry between discovery modes: For
the registry-based discovery using PEP 514, we discover both 32-bit and
64-bit Pythons, while for managed installations, we are stricter and
only discover those matching in bit-ness.

I tested this manually with an additional 32-bit installation of CPython
on a 64-bit machine and windows with 32-bit and 64-bit (x86_64 and i686)
builds of uv.
2025-03-03 14:46:00 +00:00
renovate[bot]
83f1b8b0f1
Update Rust crate reqwest-middleware to v0.4.1 (#11906)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[reqwest-middleware](https://redirect.github.com/TrueLayer/reqwest-middleware)
| workspace.dependencies | patch | `0.4.0` -> `0.4.1` |

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/astral-sh/uv).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xNzYuMiIsInVwZGF0ZWRJblZlciI6IjM5LjE3Ni4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJpbnRlcm5hbCJdfQ==-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: konstin <konstin@mailbox.org>
2025-03-03 14:36:57 +01:00
konsti
d712ff243e
Edition 2024 prep: Escape r#gen and remove redundant ref (#11922)
Three edition 2021 compatible sets of changes in preparation for the
edition 2025 split out from #11724.

In edition 2025, `gen` is a keyword, so we escape it as `r#gen`. `ref`
and `ref mut` are not allowed anymore for `&T` and `&mut T`, so we
remove them. `cargo fmt` now formats inside of macros, which the 2021
formatter doesn't undo.
2025-03-03 11:13:56 +00:00
renovate[bot]
6fdcaa8a4b
Update Rust crate bitflags to v2.9.0 (#11914) 2025-03-03 09:51:13 +00:00
renovate[bot]
a249b16d7c
Update Rust crate owo-colors to v4.2.0 (#11918) 2025-03-03 04:26:23 +00:00
renovate[bot]
5b162c3478
Update Rust crate flate2 to v1.1.0 (#11917) 2025-03-03 04:22:06 +00:00
renovate[bot]
c1991e4106
Update Rust crate etcetera to 0.9.0 (#11916) 2025-03-03 04:16:02 +00:00
renovate[bot]
38acb86397
Update Rust crate either to v1.14.0 (#11915) 2025-03-03 04:11:35 +00:00
renovate[bot]
fe1cd3b0b6
Update Rust crate backon to v1.4.0 (#11913) 2025-03-03 04:07:40 +00:00
renovate[bot]
7c40074c2c
Update pre-commit dependencies (#11912) 2025-03-03 04:04:05 +00:00
1hakusai1
6f7d6c420b
Improve test behavior with custom installation directory (#10048)
## Summary

Testing with `UV_PYTHON_INSTALL_DIR` environment variable has some
problems. This PR fix them.

- `UV_PYTHON_INSTALL_DIR` must be an absolute path.
- Cargo tries to find Python executables from each crates in test. If it
is relative path, cargo searches in different directories for each
tests.
- Skip the test asserting help messages.
- Clap shows the current value of the environment variables. If
`UV_PYTHON_INSTALL_DIR` is set, the test fails.

## Test Plan

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

All tests pass with
`UV_PYTHON_INSTALL_DIR=/path/to/my/home/uv/target/testpython`.
2025-03-02 22:58:50 -05:00
renovate[bot]
fb6d5d8b4b
Update Rust crate wiremock to v0.6.3 (#11909) 2025-03-03 03:35:51 +00:00
Charlie Marsh
a1690203cf
Avoid fallback to PyPI in mixed CPU/CUDA example (#11115)
## Summary

This is roughly equivalent, but gets the non-`+cpu` macOS build from the
PyTorch index rather than PyPI. It seems a bit simpler? Though up for
debate.
2025-03-02 22:35:32 -05:00
renovate[bot]
c8f0753376
Update Rust crate winsafe to 0.0.23 (#11908) 2025-03-03 03:21:44 +00:00
renovate[bot]
a0ad1fda5e
Update Rust crate schemars to v0.8.22 (#11907) 2025-03-03 03:15:21 +00:00
renovate[bot]
a973790a3f
Update Rust crate reflink-copy to v0.1.24 (#11905) 2025-03-03 03:00:45 +00:00
renovate[bot]
4c4c4b72d5
Update Rust crate mailparse to v0.16.1 (#11904) 2025-03-03 02:59:52 +00:00
renovate[bot]
7ce045cc50
Update Rust crate insta to v1.42.2 (#11903) 2025-03-03 02:57:43 +00:00
Alex Ball
43c8cd8b3f
Docs: Clarify that setting cache-keys overrides defaults (#11895)
## Summary

The current wording on the [caching
page](https://docs.astral.sh/uv/concepts/cache/#dynamic-metadata) makes
it sounds like defining `cache-keys` in a project adds to the metadata
considered when caching. However it actually replaces the metadata. So
copying the example using the git commit results in only considering the
git commit, not the pyproject.toml, which is likely not what is
typically desired.

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2025-03-03 02:54:48 +00:00
renovate[bot]
663ae63f2e
Update Rust crate console to v0.15.11 (#11901) 2025-03-03 02:51:13 +00:00