Commit Graph

6086 Commits

Author SHA1 Message Date
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
https://github.com/astral-sh/uv/actions/runs/13641331357/job/38131724427
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
renovate[bot] b5237d53d4
Update Rust crate globset to v0.4.16 (#11902) 2025-03-03 02:50:39 +00:00
renovate[bot] 90a8ed933c
Update Rust crate codspeed-criterion-compat to v2.8.1 (#11900)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [codspeed-criterion-compat](https://codspeed.io)
([source](https://redirect.github.com/CodSpeedHQ/codspeed-rust)) |
dependencies | patch | `2.8.0` -> `2.8.1` |

---

### Release Notes

<details>
<summary>CodSpeedHQ/codspeed-rust (codspeed-criterion-compat)</summary>

###
[`v2.8.1`](https://redirect.github.com/CodSpeedHQ/codspeed-rust/releases/tag/v2.8.1)

[Compare
Source](https://redirect.github.com/CodSpeedHQ/codspeed-rust/compare/v2.8.0...v2.8.1)

#### What's Changed

- chore: remove deprecated feature from cargo-codspeed release build by
[@&#8203;GuillaumeLagrange](https://redirect.github.com/GuillaumeLagrange)
in
[https://github.com/CodSpeedHQ/codspeed-rust/pull/76](https://redirect.github.com/CodSpeedHQ/codspeed-rust/pull/76)
- chore(divan_compat): fix readme typo by
[@&#8203;GuillaumeLagrange](https://redirect.github.com/GuillaumeLagrange)
in
[https://github.com/CodSpeedHQ/codspeed-rust/pull/77](https://redirect.github.com/CodSpeedHQ/codspeed-rust/pull/77)
- ci: build musl targets for cargo-codspeed binary artifacts by
[@&#8203;GuillaumeLagrange](https://redirect.github.com/GuillaumeLagrange)
in
[https://github.com/CodSpeedHQ/codspeed-rust/pull/80](https://redirect.github.com/CodSpeedHQ/codspeed-rust/pull/80)
- ci: add targets to moon-repo/setup in binary artifact build by
[@&#8203;GuillaumeLagrange](https://redirect.github.com/GuillaumeLagrange)
in
[https://github.com/CodSpeedHQ/codspeed-rust/pull/81](https://redirect.github.com/CodSpeedHQ/codspeed-rust/pull/81)

**Full Changelog**:
https://github.com/CodSpeedHQ/codspeed-rust/compare/v2.8.0...v2.8.1

</details>

---

### 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>
2025-03-03 02:45:11 +00:00
Charlie Marsh 04f20169db
Avoid silently dropping errors in directory enumeration (#11890)
## Summary

Right now, _all_ errors are dropped here, which seems wrong. We should
only return an empty iterator if the directory doesn't exist.
2025-03-03 02:39:17 +00:00
Charlie Marsh 5ec9be0585
Document our MSRV policy (#11898)
## Summary

Copying https://github.com/astral-sh/ruff/pull/16384 over to uv.
2025-03-02 21:30:17 -05:00
github-actions[bot] b5a0b7b2c3
Add pypy3.10-v7.3.19 to managed Python releases (#11814)
Automated update for Python releases.

Co-authored-by: zanieb <2586601+zanieb@users.noreply.github.com>
2025-03-02 22:48:35 +00:00
Charlie Marsh 461f4d9007
Make interpreter caching robust to OS upgrades (#11875)
## Summary

In. https://github.com/astral-sh/uv/issues/11857, we had a case of a
user that was seeing incorrect resolution results after upgrading to a
newer version of macOS, since we retained cache information about the
interpreter. This PR adds the OS name and version to the cache key for
the interpreter. This seems to be extremely cheap, and it's nice to make
this robust so that users don't run into the same confusion in the
future.

Closes https://github.com/astral-sh/uv/issues/11857.
2025-03-02 01:36:38 +00:00
Charlie Marsh cf76334d79
Avoid error on relative paths in `uv tool uninstall` (#11889)
## Summary

Closes https://github.com/astral-sh/uv/issues/11877.
2025-03-01 20:12:50 -05:00
Charlie Marsh 8dd079f2ad
Suggest `uv tool update-shell` in PowerShell (#11846)
## Summary

We need to decouple the "Is this shell supported by `update-shell`?"
logic from the "Does this shell have known configuration files?" logic,
specifically for Windows, which we can always update but not via
configuration files.

Closes https://github.com/astral-sh/uv/issues/11803.
2025-02-28 22:32:48 -05:00
Charlie Marsh 3398cb1902
Respect `include-system-site-packages` in layered environments (#11873)
## Summary

We use a similar strategy to the ephemeral overlay: set
`include-system-site-packages` in the `pyvenv.cfg`, and clear it
whenever we access a new environment.

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

## Test Plan

Difficult to test because we don't really have support for system
packages in our test infrastructure. But...

```
> uv venv --system-site-packages
> ['', '/Users/crmarsh/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python313.zip', '/Users/crmarsh/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13', '/Users/crmarsh/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13/lib-dynload', '/Users/crmarsh/.cache/uv/archive-v0/AhKcORkaCdbBl31VweRtG/lib/python3.13/site-packages', '/Users/crmarsh/workspace/uv/foo/.venv/lib/python3.13/site-packages', '/Users/crmarsh/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13/site-packages']
```

```
> uv venv
> ['', '/Users/crmarsh/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python313.zip', '/Users/crmarsh/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13', '/Users/crmarsh/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13/lib-dynload', '/Users/crmarsh/.cache/uv/archive-v0/AhKcORkaCdbBl31VweRtG/lib/python3.13/site-packages', '/Users/crmarsh/workspace/uv/foo/.venv/lib/python3.13/site-packages']
```
2025-02-28 22:22:37 -05:00
Charlie Marsh 3017b82ecc
Fix typo in unsatisfiable (#11874) 2025-03-01 03:22:27 +00:00
Aria Desires 7acdbf6414
rework log verbosity (`-vvv`) (#11758)
Reworks how log verbosity flags work.

* `<no argument>` is the same, equivalent to `RUST_LOG=off`
* `-v` is the same, equivalent to `RUST_LOG=uv=debug`
* `-vv` is now equivalent to `RUST_LOG=uv=trace` (previously it only
enabled more log message context)
* `-vvv` is now equivalent to `RUST_LOG=trace` (previously it was
equivalent to `-vv`)

The "more context" that `-vv` had has been moved to an orthogonal
setting via an environment variable. Setting `UV_LOG_CONTEXT=1` will add
the extra context that `-vv` did.

In the future we may make these more granular as we try to use
`info!/warn!` more.

Fixes #1569
2025-02-28 18:49:27 -05:00
konsti dc39d6622b
Fix non-directory in workspace on Windows (#11833)
Fixes #11793

On Windows, trying to read a file inside what is not a directory but
another file results in a not found error, while on Unix we get a not a
directory error. We check explicitly if something included in a
workspace glob is a non-directory to fix the behavior on Windows.
2025-02-28 13:40:19 +01:00
John Mumm 2e7ae19b55
Factor out network settings (#11839)
Three network settings are always passed together (though in random
method parameter orders). I factored these out into a struct to make planned future
changes easier.
2025-02-28 10:05:17 +01:00
Zanie Blue 0631d96717
Create a `.git` directory in the test context root (#11761)
This fixes errors in the test suite when, e.g., `~`, is a Git
repository.
2025-02-28 00:36:41 -06:00
Charlie Marsh c65dae64fe
Fix reference to macOS cache path (#11845)
## Summary

Closes https://github.com/astral-sh/uv/issues/11809.
2025-02-28 02:14:09 +00:00
Charlie Marsh b56a0f8877
Add a test for repeated index in root and member (#11844)
## Summary

A small follow-up to #11824.
2025-02-28 02:12:36 +00:00
KATO So ad86005e9a
Warn when duplicate index names found in single file (#11824)
<!--
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

This pull request introduces validation for unique index names in the
`tool.uv.index` field and adds corresponding tests to ensure the
functionality. The most important changes include adding a custom
deserializer function, updating the `ToolUv` struct to use the new
deserializer, and adding tests to verify the behavior.

Validation and deserialization:

*
[`crates/uv-workspace/src/pyproject.rs`](diffhunk://#diff-e12cd255985adfd45ab06f398cb420d2f543841ccbeea4175ccf827aa9215b9dR283-R311):
Added a custom deserializer function `deserialize_index_vec` to validate
that index names in the `tool.uv.index` field are unique.
*
[`crates/uv-workspace/src/pyproject.rs`](diffhunk://#diff-e12cd255985adfd45ab06f398cb420d2f543841ccbeea4175ccf827aa9215b9dR374):
Updated the `ToolUv` struct to use the `deserialize_index_vec` function
for the `index` field.

Testing:

*
[`crates/uv/tests/it/lock.rs`](diffhunk://#diff-82edd36151736f44055f699a34c8b19a63ffc4cf3c86bf5fb34d69f8ac88a957R15336):
Added a test `lock_repeat_named_index` to verify that duplicate index
names result in an error.
[[1]](diffhunk://#diff-82edd36151736f44055f699a34c8b19a63ffc4cf3c86bf5fb34d69f8ac88a957R15336)
[[2]](diffhunk://#diff-82edd36151736f44055f699a34c8b19a63ffc4cf3c86bf5fb34d69f8ac88a957R15360-R15402)
*
[`crates/uv/tests/it/lock.rs`](diffhunk://#diff-82edd36151736f44055f699a34c8b19a63ffc4cf3c86bf5fb34d69f8ac88a957R15360-R15402):
Added a test `lock_unique_named_index` to verify that unique index names
result in successful lock file generation.

Schema update:

*
[`uv.schema.json`](diffhunk://#diff-c669473b258a19ba6d3557d0369126773b68b27171989f265333a77bc5cb935bR205):
Updated the schema to set the default value of the `index` field to
`null`.

Fixes #11804

## Test Plan
### Steps to reproduce and verify the fix:

1. Clone the repository and checkout the feature branch
   ```bash
   git clone https://github.com/astral-sh/uv.git
   cd uv
   git checkout feature/warn-duplicate-index-names
   ```

2. Build the modified binary
   ```bash
   cargo build
   ```

3. Create a test project using the system installed uv
   ```bash
   uv init uv-test
   cd uv-test
   ```

4. Manually edit pyproject.toml to add duplicate index names
   ```toml
   [[tool.uv.index]]
   name = "alpha_b"
   url = "<omitted>"

   [[tool.uv.index]]
   name = "alpha_b"
   url = "<omitted>"
   ```

5. Try to add a package using the modified binary
   ```bash
   ../target/debug/uv add numpy
   ```

### Results
Before: use release binary
![スクリーンショット 2025-02-27 15 52
28](https://github.com/user-attachments/assets/2823a4b4-b3ba-40aa-aa41-e593d35c3f3b)

After: use self build binary
![スクリーンショット 2025-02-27 15 51
58](https://github.com/user-attachments/assets/9ac773a9-58cd-4d4b-8685-148bf6dc85fb)

Now when attempting to use a pyproject.toml with duplicate index names,
the modified binary correctly detects the issue and produces an error
message:
```
error: Failed to parse: `pyproject.toml`
  Caused by: TOML parse error at line 9, column 1
  |
9 | [[tool.uv.index]]
  | ^^^^^^^^^^^^^^^^^
duplicate index name `alpha_b`
```

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2025-02-27 21:33:57 +00:00
梦飞翔 4d9c861506
Update code page to 65001 before setting environment variables, fix #11828 (#11831)
## Summary

When executing `.venv\Scripts\activate` in `cmd`, the script uses the
local codepage for execution. This causes issues when the file path
contains non-ASCII characters, resulting in corrupted environment
variables such as `VIRTUAL_ENV`.

See #11828.

Code used to fix the issue was adapted from
https://github.com/python/cpython/blob/3.13/Lib/venv/scripts/nt/activate.bat#L3-L9.

## Test Plan

Before:

![image](https://github.com/user-attachments/assets/f8a50675-a688-4b4b-9d1b-0a5d5f736123)

After:

![image](https://github.com/user-attachments/assets/3aed978e-4c9b-40e4-a689-9a602f95b725)
(`chcp` command cleared the history lol)
2025-02-27 16:14:34 -05:00
Ankit Saini ef95d79bfa
Fix version string truncation while generating cache_key (#11830)
<!--
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 up for https://github.com/astral-sh/uv/pull/11738

I missed this while reviewing the truncation changes. 

`format!("{:.N}", value)` only truncates if the `fmt::Display`
implementation supports it (by reading `f.precision()` in trait
implementation).

So in our case `format!("{:.N}", version.to_string())` will work but not
`format!("{:.N}", version)` unless `Version` supports it.

Since we only need it once, I am just truncating after the string is
created.

## Test Plan

<!-- How was it tested? -->
2025-02-27 08:48:43 -05:00
Choudhry Abdullah f9c1684b96
Conditional imports (#11823)
## Summary

Conditionally importing in tests to prevent unused imports warning in
cargo test windows in CI.
2025-02-27 10:08:37 +01:00