Commit Graph

4406 Commits

Author SHA1 Message Date
Charlie Marsh f1840c77b6
Guard against concurrent cache writes on Windows (#11007)
## Summary

On Windows, we have a lot of issues with atomic replacement and such.
There are a bunch of different failure modes, but they generally
involve: trying to persist a fail to a path at which the file already
exists, trying to replace or remove a file while someone else is reading
it, etc.

This PR adds locks to all of the relevant database paths. We already use
these advisory locks when building source distributions; now we use them
when unzipping wheels, storing metadata, etc.

Closes #11002.

## Test Plan

I ran the following script:

```shell
# Define the cache directory path
$cacheDir = "C:\Users\crmar\workspace\uv\cache"

# Clear the cache directory if it exists
if (Test-Path $cacheDir) {
    Remove-Item -Recurse -Force $cacheDir
}

# Create the cache directory again
New-Item -ItemType Directory -Force -Path $cacheDir

# Define the command to run with --cache-dir flag
$command = {
    param ($venvPath)

    # Create a virtual environment in the specified path with --python
    uv venv $venvPath

    # Run the pip install command with --cache-dir flag
    C:\Users\crmar\workspace\uv\target\profiling\uv.exe pip install flask==1.0.4 --no-binary flask --cache-dir C:\Users\crmar\workspace\uv\cache -v --python $venvPath
}

# Define the paths for the different virtual environments
$venv1 = "C:\Users\crmar\workspace\uv\venv1"
$venv2 = "C:\Users\crmar\workspace\uv\venv2"
$venv3 = "C:\Users\crmar\workspace\uv\venv3"
$venv4 = "C:\Users\crmar\workspace\uv\venv4"
$venv5 = "C:\Users\crmar\workspace\uv\venv5"

# Start the command in parallel five times using Start-Job, each with a different venv
$job1 = Start-Job -ScriptBlock $command -ArgumentList $venv1
$job2 = Start-Job -ScriptBlock $command -ArgumentList $venv2
$job3 = Start-Job -ScriptBlock $command -ArgumentList $venv3
$job4 = Start-Job -ScriptBlock $command -ArgumentList $venv4
$job5 = Start-Job -ScriptBlock $command -ArgumentList $venv5

# Wait for all jobs to complete
$jobs = @($job1, $job2, $job3, $job4, $job5)
$jobs | ForEach-Object { Wait-Job $_ }

# Retrieve the results (optional)
$jobs | ForEach-Object { Receive-Job -Job $_ }

# Clean up the jobs
$jobs | ForEach-Object { Remove-Job -Job $_ }
```

And ensured it succeeded in five straight invocations (whereas on
`main`, it consistently fails with a variety of different traces).
2025-01-28 15:33:49 -05:00
Zanie Blue fe6126a92b
Improve SIGINT handling in `uv run` (#11009)
There should be two functional changes here:

- If we receive SIGINT twice, forward it to the child process
- If the `uv run` child process changes its PGID, then forward SIGINT

Previously, we never forwarded SIGINT to a child process. Instead, we
relied on shell to do so.

On Windows, we still do nothing but eat the Ctrl-C events we receive.
I cannot see an easy way to send them to the child.

The motivation for these changes should be explained in the comments.

Closes https://github.com/astral-sh/uv/issues/10952 (in which Ray
changes its PGID)
Replaces the (much simpler) #10989 with a more comprehensive approach.

See https://github.com/astral-sh/uv/pull/6738#issuecomment-2315451358
for some previous context.
2025-01-28 14:00:38 -06:00
Zanie Blue e26affd27c
Fix best-interpreter lookups when there is an invalid interpreter in the PATH (#11030)
Closes https://github.com/astral-sh/uv/issues/10978

The root cause is the same as #10908 — I should have been more careful
with the original change.
2025-01-28 13:44:32 -06:00
Zanie Blue 4b8e157ba7
Add upper bound constraints to (more) test cases that use pytorch index (#11034)
Closes https://github.com/astral-sh/uv/issues/11025
2025-01-28 19:28:54 +00:00
Zanie Blue 0ae3fce599
Add test coverage for #10978 (#11029) 2025-01-28 19:15:15 +00:00
Zanie Blue 7949672cab
Add upper bounds to `lock_pytorch_cpu` torch versions (#11033)
Presumably this is a better alternative to
https://github.com/astral-sh/uv/pull/11031
2025-01-28 18:52:58 +00:00
Andrew Gallant 2c7b14da70
tests: update snapshots again (#11026)
It looks like an sdist got uploaded after-the-fact for `MarkupSafe
2.1.5` and this has changed some of our lock files.
2025-01-28 17:48:23 +00:00
Andrew Gallant 4a735461b5
tests: update snapshots (#11023)
I'm getting these updates locally, and wondering if they specific to my
local setup or if there was a recent release. So let's see what CI says.
2025-01-28 11:29:05 -06:00
micolous 52870c587c
Fix incorrect error message when specifying `tool.uv.sources.(package).workspace` with other options (#11013)
## Summary

When a `pyproject.toml` `[tool.uv.sources.(package)]` section specifies
`workspace` and one or more of (`index`, `git`, `url`, `path`, `rev`,
`tag`, `branch`, `editable`), running `uv` to build or sync the package
gives the error:

```
cannot specify both `index` and `(parameter name)`
```

The error should actually say:

```
cannot specify both `workspace` and `(parameter name)`
```

## Test Plan

I ran `cargo test`, and all tests still passed.
2025-01-28 09:25:33 -05:00
Aria Desires a2db48d649
fix async windows file persist retries (#11008)
The previous two versions of the code were bugged and would always
produce None when you retried (producing a hard LostState error).
2025-01-27 18:51:36 -05:00
konsti c1a2ef12d2
Respect `--no-sources` for `uv pip install` workspace discovery (#11003) 2025-01-28 00:10:27 +01:00
Charlie Marsh bbba2c7bce
Remove unnecessary distribution clone (#11004) 2025-01-27 18:07:13 -05:00
Charlie Marsh a00f6f5d3d
Reject `--editable` flag on non-directory requirements (#10994)
## Summary

Closes https://github.com/astral-sh/uv/issues/10992.
2025-01-27 19:37:23 +00:00
Charlie Marsh c88a4baaac
Update `compile_enumerate_no_versions ` snapshot (#10998)
## Summary

I think the "available versions" may not filter on `--exclude-newer`,
since it's marked as an incompatibility? In which case, this error
message can change as versions are published.
2025-01-27 14:18:15 -05:00
Charlie Marsh f1c02182b7
Reference workspaces in `--no-sources` documentation (#10995)
## Summary

See:
https://github.com/astral-sh/uv/issues/10991#issuecomment-2616543018
2025-01-27 13:33:14 -05:00
Charlie Marsh 86ec6c86dd
Prefer preferences with greater package versions (#10963)
## Summary

Closes https://github.com/astral-sh/uv/issues/10957.
2025-01-25 16:37:25 -05:00
Charlie Marsh a681905e12
Allow optional `=` for editables in `requirements.txt` (#10954)
## Summary

We allow this for all other argument flags; seems like an oversight.

Closes https://github.com/astral-sh/uv/issues/10941.
2025-01-24 21:55:51 -05:00
Zanie Blue eeab865194
Update `riscv64` Python downloads to allow install on `riscv64gc` (#10937)
Closes https://github.com/astral-sh/uv/issues/10883
2025-01-24 09:33:29 -06:00
konsti f645499dbd
Child exit with signal n returns 128+n (#10781) 2025-01-24 16:20:32 +01:00
吴小白 57a2740d90
Allow installation of manylinux wheels on loongarch64 (#10927) 2025-01-24 14:36:03 +01:00
Zanie Blue 42fae925c4
Bump version to 0.5.24 (#10922) 2025-01-23 17:26:59 -06:00
Zanie Blue cbf6d5af9e
Allow fallback to Python download on non-critical discovery errors (#10908)
Closes https://github.com/astral-sh/uv/issues/10898

In #10716, I broke fallback to downloading Python versions by throwing a
different error kind.
2025-01-23 22:37:02 +00:00
Zanie Blue 2a0fa8a8ee
Add test case for automatic installs (#10913) 2025-01-23 22:21:21 +00:00
Zanie Blue fd5131cb7c
Require tests to opt-in to managed Python installation (#10912)
First of all, I want to test automatic managed installs (see #10913) and
need to set that up. Second of all, some tests were _implicitly_
downloading interpreters instead of using the one from their context —
which is unexpected and naughty and very slow.
2025-01-23 15:24:40 -06:00
Aria Desires c05aca61db
temporarily disable new uv pip dependency-group flags (#10909)
We'll probably end up shipping but we were moving ahead with this on the
basis that pip may not even ship this, so let's play it safe and wait
for a bit.
2025-01-23 14:43:07 -06:00
Aria Desires 86f2f16d05
make test filter permissive of bdist.win32 (#10911)
I swear a few days ago there were way more of this filter but now
there's only one so *shrug*.
2025-01-23 14:13:00 -05:00
Zanie Blue 0f1987b8ed
Update `overlapping_resolution_markers` (#10910)
Updating the snapshot to unblock `main`, but this needs to be
deterministic or it will break downstream packagers too.
2025-01-23 18:29:01 +00:00
Zanie Blue bf700f8b10
Add test coverage for `uv pip install <dir> --group <name>` (#10907) 2025-01-23 11:43:38 -06:00
Zanie Blue f303c4abe0
Fix test snapshot for `--only-group` changes (#10906) 2025-01-23 17:24:59 +00:00
konsti 349c0b6fc8
Disable the progress bar with `RUST_LOG` (#10901) 2025-01-23 18:03:15 +01:00
Zanie Blue 61556fe7ae
Add a `uv pip install --group` test case with `default-groups` (#10899) 2025-01-23 10:44:32 -06:00
Aria Desires 214494149c
fix `--only-group` in `uv pip` interface (#10902)
This was an oversight in the implementation, thankfully it appears to be
a simple fix? (My only hesitation is this implementation essentially
claims that --only-group is defacto incompatible with --extra and I
*think* that's the case but I'm not certain.)
2025-01-23 11:35:47 -05:00
konsti 8ce0736f9e
All (virtual) packages must have a priority (#10853)
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2025-01-23 16:09:47 +00:00
Zanie Blue a0620bcf92
Add test coverage for use of `git` without feature flag (#10874)
Shoves a broken `git` executable onto the front of the `PATH` in the
test context when the `git` feature is disabled so they fail if they're
missing the feature-gate.
2025-01-23 09:55:06 -06:00
Charlie Marsh b2dac9979d
Use Hashbrown's raw entry API to reduce hashes and clone in priority (#10881)
## Summary

I'm open to not merging this -- I was kind of just interested in what
the API looked like. But the idea is: we can avoid hashing values twice
and unnecessarily cloning within the priority map by using the raw entry
API.
2025-01-23 09:34:37 -05:00
konsti db4ab9dc8a
Install and remove managed Python to and from the Windows Registry (PEP 514) (#10634)
## Summary

In preview mode on windows, register und un-register the managed python build standalone installations in the Windows registry following PEP 514.

We write the values defined in the PEP plus the download URL and hash. We add an entry when installing a version, remove an entry when uninstalling and removing all values when uninstalling with `--all`. We update entries only by overwriting existing values, there is no "syncing" involved.

Since they are not official builds, pbs gets a prefix. `py -V:Astral/CPython3.13.1` works, `py -3.13` doesn't.

```
$ py --list-paths                                            
 -V:3.12 *        C:\Users\Konsti\AppData\Local\Programs\Python\Python312\python.exe
 -V:3.11.9        C:\Users\Konsti\.pyenv\pyenv-win\versions\3.11.9\python.exe
 -V:3.11          C:\Users\micro\AppData\Local\Programs\Python\Python311\python.exe
 -V:3.8           C:\Users\micro\AppData\Local\Programs\Python\Python38\python.exe
 -V:Astral/CPython3.13.1 C:\Users\Konsti\AppData\Roaming\uv\data\python\cpython-3.13.1-windows-x86_64-none\python.exe
```

Registry errors are reported but not fatal, except for operations on the company key since it's not bound to any specific python interpreter.

On uninstallation, we prune registry entries that have no matching Python installation (i.e. broken entries).

The code uses the official `windows_registry` crate of the `winreg` crate.

Best reviewed commit-by-commit.

## Test Plan

We're reusing an existing system check to test different (un)installation scenarios.
2025-01-23 14:13:41 +00:00
Jo a497176818
Improve some env var document (#10887) 2025-01-23 09:10:19 -05:00
Aria Desires 53706a1864
Add dependency-group cli flags to `uv pip install` and `uv pip compile` (`--group`, `--no-group`, `--only-group`, `--all-groups`) (#10861)
Ultimately this is a lot of settings plumbing and a couple minor pieces
of Actual Logic (which are so simple I have to assume there's something
missing, but maybe not!).

Note this "needlessly" use DevDependencyGroup since it costs nothing, is
more futureproof, and lets us maintain one primary interface (we just
pass `false` for all the dev arguments).

Fixes #8590
Fixes #8969
2025-01-23 08:47:52 -05:00
Charlie Marsh c3a511716a
Remove dependencies clone in resolver (#10880) 2025-01-23 10:59:24 +01:00
Charlie Marsh ba42467f1b
Bump version to v0.5.23 (#10879) 2025-01-23 00:26:10 +00:00
Charlie Marsh 2df3f0e782
Reduce ambiguity in conflicting extras example (#10877)
## Summary

Closes https://github.com/astral-sh/uv/issues/10378.
2025-01-22 19:09:49 -05:00
Andrew Gallant 4051cff582 uv/tests: update existing test
This is the test we tweaked a few commits back when we first removed the
error checking in the resolver. We now add in some `uv sync` commands,
including one that should fail.
2025-01-22 18:52:05 -05:00
Andrew Gallant a8d23da59c uv-resolver: error during installation for conflicting extras
This collects ALL activated extras while traversing the lock file to
produce a `Resolution` for installation. If any two extras are activated
that are conflicting, then an error is produced.

We add a couple of tests to demonstrate the behavior. One case is
desirable (where we conditionally depend on `package[extra]`) and the
other case is undesirable (where we create an uninstallable lock file).

Fixes #9942, Fixes #10590
2025-01-22 18:52:05 -05:00
Andrew Gallant 1676e63603 uv-resolver: fix propagation of extras
This will make `package[extra]` work even when `extra` is declared as a
conflicting extra.

Note that this isn't relevant for dependency groups since AFAIK those
can actually only be enabled on the CLI. There is no `package:group`
dependency syntax.
2025-01-22 18:52:05 -05:00
Andrew Gallant 18fa48a092 uv/tests: add regression test for installation bug
With the previous commit loosening a restriction in the resolver, it
reveals a bug: a `uv sync` won't install a `package[extra]` dependency.
This occurs because `extra` isn't treated as activated during install,
and thus `package[extra]`'s conflict marker isn't satisfied.

In other words, the way we dealt with conflict markers previously
assumed that conflicting extras could _only_ be activated via
`--extra foo`. And while that used to be true, after the previous
commit, it no longer is.

We'll fix this bug in the next commit. I added this test in a separate
commit to make the problem and resulting fix clearer.
2025-01-22 18:52:05 -05:00
Andrew Gallant ae9c5c849d uv-resolver: remove the conservative checking of unconditional extras
This removes the error that was causing folks problems.

This does result in some snapshot updates that are arguably wrong, or at
least sub-optimal. However, it's actually intended. Because the approach
we're going to take is going to permit the creation of uninstallable
lock files as a side effect. In the future, we will modify this test to
check that, while `uv lock` succeeds, `uv sync` will always fail.
2025-01-22 18:52:05 -05:00
Charlie Marsh 183fe403c6
Disable `.egg-info` tests via `slow-tests` feature on Windows and macOS (#10872)
## Summary

These are super slow on Windows and it's not critical to test them on
that platform. Let's just do the lazy thing.
2025-01-22 21:39:04 +00:00
Charlie Marsh 088c194159
Remove clones from satisfies variants (#10876) 2025-01-22 16:22:07 -05:00
Zanie Blue d09be14679
Add missing `git` feature flag to various tests (#10873) 2025-01-22 14:16:38 -06:00
Ilan Godik b1e4bc779c
[uv-settings]: Correct behavior for relative find-links paths when run from a subdir (#10827)
## One-liner
Relative find-links configuration to local path from a pyproject.toml or
uv.toml is now relative to the config file
## Summary
### Background
One can configure find-links in a `pyproject.toml` or `uv.toml` file,
which are located from the cli arg, system directory, user directory, or
by traversing parent directories until one is encountered.

This PR addresses the following scenario:
- A project directory which includes a `pyproject.toml` or `uv.toml`
file
- The config file includes a `find-links` option. (eg under `[tool.uv]`
for `pyproject.toml`)
- The `find-links` option is configured to point to a local subdirectory
in the project: `packages/`
- There is a subdirectory called `subdir`, which is the current working
directory
- I run `uv run my_script.py`. This will locate the `pyproject.toml` in
the parent directory
### Current Behavior
- uv tries to use the path `subdir/packages/` to find packages, and
fails.
### New Behavior
- uv tries to use the path `packages/` to find the packages, and
succeeds
- Specifically, any relative local find-links path will resolve to be
relative to the configuration file.

### Why is this behavior change OK?
- I believe no one depends on the behavior that a relative find-links
when running in a subdir will refer to different directories each time
- Thus this change only allows a more common use case which didn't work
previously.

## Test Plan
- I re-created the setup mentioned above:
```
UvTest/
├── packages/
│   ├── colorama-0.4.6-py2.py3-none-any.whl
│   └── tqdm-4.67.1-py3-none-any.whl
├── subdir/
│   └── my_script.py
└── pyproject.toml
```
```toml 
# pyproject.toml
[project]
name = "uvtest"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "tqdm>=4.67.1",
]

[tool.uv]
offline = true
no-index = true
find-links = ["packages/"]
```
- With working directory under `subdir`, previously, running `uv sync
--offline` would fail resolving the tdqm package, and after the change
it succeeds.
- Additionally, one can use `uv sync --show-settings` to show the
actually-resolved settings - now having the desired path in
`flat_index.url.path`

## Alternative designs considered
- I considered modifying the `impl Deserialize for IndexUrl` to parse
ahead of time directly with a base directory by having a custom
`Deserializer` with a base dir field, but it seems to contradict the
design of the serde `Deserialize` trait - which should work with all
`Deserializer`s

## Future work
- Support for adjusting all other local-relative paths in `Options`
would be desired, but is out of scope for the current PR.

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2025-01-22 19:44:35 +00:00