Commit graph

2490 commits

Author SHA1 Message Date
Charlie Marsh
a0173760f1
Remove unused PEP 621 error (#4057) 2024-06-05 17:45:42 +00:00
Charlie Marsh
c97427d530
Reduce visibility of lowering (#4055)
## Summary

This makes `lowering.rs` internal to the metadata package.
2024-06-05 13:39:37 -04:00
Charlie Marsh
34f847bb68
Remove unused Requirements struct (#4054) 2024-06-05 17:14:57 +00:00
Zanie Blue
db3c36dbcc
Use PythonEnvironment API in uv venv (#4029)
There's no reason to be reaching into the lower-level `find_interpreter`
manually here.
2024-06-05 11:49:29 -05:00
konsti
b05a39c735
Store explicit project on workspace member (#4048)
We know that `[project]` must exist for each workspace member, so we can
store it directly and avoid going through the `.and_then()` when we need
to access it. This requires cloning the struct due to lack of
self-referential structs. An alternative would taking the `Project` from
`PyProjectToml` instead, but this could be confusing when passing the
`PyProjectToml` around.
2024-06-05 12:48:19 -04:00
Charlie Marsh
ae9610104a
Avoid dropping pip sync requirements with markers (#4051)
## Summary

Thankfully this is pretty rare since `pip sync` is usually run on `pip
compile` output, and `pip compile` never outputs markers.

Closes https://github.com/astral-sh/uv/issues/4044
2024-06-05 16:05:46 +00:00
Zanie Blue
b0d1fc85a9
Use standard path filters for uv venv tests (#4046)
Over in #4045 the existing filters were insufficient. We should use the
same strategy we use for our standard `TestContext` instead.
2024-06-05 10:25:10 -05:00
Zanie Blue
f2dc08b242
Drop git dependency from pip_entrypoints test (#4049)
There's a release with the changes we want test coverage for now
2024-06-05 17:22:32 +02:00
Zanie Blue
91c5ac44ac
Add ProvidedPath to interpreter sources considered when UV_TEST_PYTHON_PATH is set (#4027)
Just a theory, but I presume this would close
https://github.com/astral-sh/uv/issues/4023.

I'm not sure how else we'd end up in this case.
2024-06-05 09:52:28 -05:00
Zanie Blue
5db7f7b3ac
Move uv-interpreter::managed::* modules into crate top-level (#4020)
Should be no functional changes, just some file renames in preparation
for exposing toolchain management.
2024-06-05 07:27:30 -05:00
Zanie Blue
2be93c0b2c
Display selected interpreter sources during not selected error (#4026)
This should help us narrow down the weird error in
https://github.com/astral-sh/uv/issues/4023
2024-06-05 07:26:56 -05:00
konsti
054fffe05e
Mute nightly lint fix to mute stable warning (#4042) 2024-06-05 11:05:19 +00:00
Charlie Marsh
6d148da0ab
Preserve fragments when applying verbatim redirects (#4038)
## Summary

`echo
"git+https://github.com/pypa/sample-namespace-packages.git#subdirectory=pkg_resources/pkg_a"
| cargo run pip compile -` now resolves to a compliant URL.

Closes https://github.com/astral-sh/uv/issues/4037.
2024-06-05 03:53:23 +00:00
Charlie Marsh
27e5bfe397
Remove unnecessary requirements conversions (#4035) 2024-06-05 01:52:16 +00:00
Charlie Marsh
8de3e38b94
Read all extras directly from lockfile (#4033)
## Summary
We now pass `ExtrasSpecification` to the lock routine.
2024-06-05 01:03:55 +00:00
samypr100
1b3200b2af
feat: support NO_COLOR and FORCE_COLOR env vars (#3979)
## Summary

Closes #3955

Adds explicit support to `NO_COLOR` and `FORCE_COLOR` via
GlobalSettings.

The order, per specs is now `NO_COLOR` > `FORCE_COLOR` > `color`.

This PR is a backup plan pending rust-cli/anstyle#192.

## Test Plan

Tested all cases locally for now; I didn't see existing tests for
GlobalSettings parsing.
2024-06-04 17:00:42 -04:00
Charlie Marsh
57ea55d218
Add a hint for Requires-Python (#4021)
## Summary

As requested in the originating PR.
2024-06-04 16:52:15 -04:00
Charlie Marsh
8eea470d49
Bias towards local directories for bare editable requirements (#3995)
## Summary

Given `install -e dagster`, we need to assume that the user meant
`install -e ./dagster`, even though `install dagster` should _not_ be
treated as `install ./dagster`. I suspect pip will change this in the
future (since `pip install dagster` does _not_ meant `pip install
./dagster`) but for now it's what users expect.

Closes https://github.com/astral-sh/uv/issues/3994.
2024-06-04 19:37:05 +00:00
Charlie Marsh
420333a40e
Avoid 'are incompatible' for singular bounded versions (#4003)
## Summary

Not sure if this is worth the complexity, but it does read better.
2024-06-04 19:17:36 +00:00
Andrew Gallant
365ca637c7 uv/tests: add new universal tests
This updates to packse 0.3.17. There are a few incidental changes in
places, but the main addition here are the tests for universal
resolutions.
2024-06-04 14:24:59 -04:00
Andrew Gallant
42b584c668 scripts/scenarios: update packse to 0.3.17 2024-06-04 14:24:59 -04:00
Andrew Gallant
7b736fc238 scripts/scenarios: update 'generate.py' to handle universal tests
This commit adds a template and does some light surgery on `generate.py`
to make use of that template. In particular, the universal tests require
using the "workspace"-aware version of `uv`, so we can't use the
existing `uv pip {compile,install}` tests.
2024-06-04 14:24:59 -04:00
Andrew Gallant
459966a132
uv/tests: update packse tests (#4015)
This is just the result of running

    ./scripts/sync_scenarios.sh

From the root of the `uv` repository.

When I initially ran this, it produced some tests with snapshots that
weren't being updated. It turned out this was because the tests weren't
running, as they were gated behind the `python-patch` feature. In this
commit, we add `python-patch` to our `cargo insta` command, which should
update all relevant snapshots.

There are still some superfluous updates as a result of a spell checker
being run on generated files, but
2024-06-04 13:56:20 -04:00
Andrew Gallant
5c30b39fe3
uv-resolver: normalize marker expressions (#4017)
This is a quick fix for some flaky tests where the output in the lock
file isn't stable because marker expressions can be combined in a
non-deterministic order.

I believe there is ongoing work to simplify marker expressions which
will help here, but I think some kind of normalization is still
ultimately needed to guarantee consistent output.

I first noticed the flaky test in:
https://github.com/astral-sh/uv/pull/4015
2024-06-04 13:45:54 -04:00
Ibraheem Ahmed
3b8f3a7f0d
Avoid work-stealing in bytecode compilation (#4004)
## Summary

Avoid using work-stealing Tokio workers for bytecode compilation,
favoring instead dedicated threads. Tokio's work-stealing does not
really benefit us because we're spawning Python workers and scheduling
tasks ourselves — we don't want Tokio to re-balance our workers. Because
we're doing scheduling ourselves and compilation is a primarily
compute-bound task, we can also create dedicated runtimes for each
worker and avoid some synchronization overhead.

This is part of a general desire to avoid relying on Tokio's
work-stealing scheduler and be smarter about our workload. In this case
we already had the custom scheduler in place, Tokio was just getting in
the way (though the overhead is very minor).

## Test Plan

This improves performance by ~5% on my machine.

```
$ hyperfine --warmup 1 --prepare "target/profiling/uv-dev clear-compile .venv" "target/profiling/uv-dev compile .venv" "target/profiling/uv-dev-dedicated compile .venv"
Benchmark 1: target/profiling/uv-dev compile .venv
  Time (mean ± σ):      1.279 s ±  0.011 s    [User: 13.803 s, System: 2.998 s]
  Range (min … max):    1.261 s …  1.296 s    10 runs
 
Benchmark 2: target/profiling/uv-dev-dedicated compile .venv
  Time (mean ± σ):      1.220 s ±  0.021 s    [User: 13.997 s, System: 3.330 s]
  Range (min … max):    1.198 s …  1.272 s    10 runs

Summary
  target/profiling/uv-dev-dedicated compile .venv ran
    1.05 ± 0.02 times faster than target/profiling/uv-dev compile .venv

$ hyperfine --warmup 1 --prepare "target/profiling/uv-dev clear-compile .venv" "target/profiling/uv-dev compile .venv" "target/profiling/uv-dev-dedicated compile .venv"
Benchmark 1: target/profiling/uv-dev compile .venv
  Time (mean ± σ):      3.631 s ±  0.078 s    [User: 47.205 s, System: 4.996 s]
  Range (min … max):    3.564 s …  3.832 s    10 runs
 
Benchmark 2: target/profiling/uv-dev-dedicated compile .venv
  Time (mean ± σ):      3.521 s ±  0.024 s    [User: 48.201 s, System: 5.392 s]
  Range (min … max):    3.484 s …  3.566 s    10 runs
 
Summary
  target/profiling/uv-dev-dedicated compile .venv ran
    1.03 ± 0.02 times faster than target/profiling/uv-dev compile .venv
```
2024-06-04 10:48:23 -04:00
Charlie Marsh
6afb659c9a
Respect Requires-Python in universal resolution (#3998)
## Summary

Closes #3982.
2024-06-04 13:56:08 +00:00
konsti
63c84ed4a6
Log transient network request failures (#3933)
We retry several kinds of network request failures, but it's often
unclear whether a request was retried or not
(https://github.com/astral-sh/uv/issues/3514#issuecomment-2105485773).
This PR adds a small intermediary layer that logs all transient request
failures, adding the `DEBUG Transient request failure` lines:

```
DEBUG Searching for Python interpreter in virtual environments
DEBUG Found CPython 3.12.3 at `/home/konsti/projects/uv/.venv/bin/python3` (active virtual environment)
DEBUG Using Python 3.12.3 environment at .venv/bin/python3
DEBUG Acquired lock for `.venv`
DEBUG At least one requirement is not satisfied: tqdm
DEBUG Using registry request timeout of 30s
DEBUG Solving with target Python version 3.12.3
DEBUG Adding direct dependency: tqdm*
DEBUG No cache entry for: https://pypi.org/simple/tqdm/
DEBUG Transient request failure for https://pypi.org/simple/tqdm/, retrying: Request error: error sending request for url (https://pypi.org/simple/tqdm/)
  Caused by: error sending request for url (https://pypi.org/simple/tqdm/)
  Caused by: client error (Connect)
  Caused by: dns error: failed to lookup address information: Name or service not known
  Caused by: failed to lookup address information: Name or service not known
DEBUG Transient request failure for https://pypi.org/simple/tqdm/, retrying: Request error: error sending request for url (https://pypi.org/simple/tqdm/)
  Caused by: error sending request for url (https://pypi.org/simple/tqdm/)
  Caused by: client error (Connect)
  Caused by: dns error: failed to lookup address information: Name or service not known
  Caused by: failed to lookup address information: Name or service not known
DEBUG Transient request failure for https://pypi.org/simple/tqdm/, retrying: Request error: error sending request for url (https://pypi.org/simple/tqdm/)
  Caused by: error sending request for url (https://pypi.org/simple/tqdm/)
  Caused by: client error (Connect)
  Caused by: dns error: failed to lookup address information: Name or service not known
  Caused by: failed to lookup address information: Name or service not known
DEBUG Transient request failure for https://pypi.org/simple/tqdm/, retrying: Request error: error sending request for url (https://pypi.org/simple/tqdm/)
  Caused by: error sending request for url (https://pypi.org/simple/tqdm/)
  Caused by: client error (Connect)
  Caused by: dns error: failed to lookup address information: Name or service not known
  Caused by: failed to lookup address information: Name or service not known
error: Could not connect, are you offline?
  Caused by: error sending request for url (https://pypi.org/simple/tqdm/)
  Caused by: client error (Connect)
  Caused by: dns error: failed to lookup address information: Name or service not known
  Caused by: failed to lookup address information: Name or service not known
```

I decided for multi-line logging to show the complete error trace since
only `Transient request failure for https://pypi.org/simple/tqdm/,
retrying: Request error: error sending request for url
(https://pypi.org/simple/tqdm/)` doesn't tell you the actual problem (a
dns error).

Note that running with `-v` will not show messages about retry backoff
timing, but running with `RUST_LOG=debug` now shows a complete picture:

```
DEBUG starting new connection: https://pypi.org/
DEBUG resolving host="pypi.org"
DEBUG Transient request failure for https://pypi.org/simple/tqdm/, retrying: Request error: error sending request for url (https://pypi.org/simple/tqdm/)
  Caused by: error sending request for url (https://pypi.org/simple/tqdm/)
  Caused by: client error (Connect)
  Caused by: dns error: failed to lookup address information: Name or service not known
  Caused by: failed to lookup address information: Name or service not known
WARN Retry attempt #2. Sleeping 528.728192ms before the next attempt
```

Fixes #3572
2024-06-04 15:39:16 +02:00
Di-Is
41ec302557
Fix a bug where no warning is output when parsing of workspace settings fails. (#4014)
## Summary

See #4013

`uv pip ...` command loads workspace settings from pyproject.toml and
uv.toml.

Although a warning is implemented to output a warning when parsing
fails, it is not actually output.


https://github.com/astral-sh/uv/blob/main/crates/uv-workspace/src/workspace.rs#L38-L61

The reason is that the flag to display warnings is enabled after loading
the workspace settings.

This PR turns on the warning output flag before loading the workspace.

## Test Plan

pyproject.toml for test

```toml
[project]
name = "sample"
version = "0.0.0"
dependencies = ["ruff"]

[tool.uv.pip]
# originally string type.
index-url = 1
```

command output (before modification)
```bash
uv pip compile pyproject.toml 

Resolved 1 package in 383ms
# This file was autogenerated by uv via the following command:
#    uv pip compile pyproject.toml
ruff==0.4.7
    # via sample (pyproject.toml)
```

command output (after modification)

```bash
uv pip compile pyproject.toml

warning: Failed to parse `pyproject.toml`: TOML parse error at line 7, column 13
  |
7 | index-url = true
  |             ^^^^
invalid type: boolean `true`, expected a string

Resolved 1 package in 107ms
# This file was autogenerated by uv via the following command:
#    uv pip compile pyproject.toml
ruff==0.4.7
    # via sample (pyproject.toml)
```
2024-06-04 09:21:19 -04:00
konsti
da7d5549a3
Don't copy gitignored files in workspace tests (#4012)
The workspace test directories can be used both in tests and directly
for developing/debugging. In the latter, we shouldn't copy the venv and
the lockfile when running tests. Using the ignore crate over manual
recursion we exclude those files.
2024-06-04 12:58:07 +00:00
konsti
36f7fa3917
impl TryFrom<&VersionSpecifiers> for PubGrubSpecifier (#4010)
Add a missing utility conversion method from PEP 440 versions specifiers
to a pubgrub range.
2024-06-04 08:00:07 +00:00
Charlie Marsh
40e0dddd00
Run cargo update (#4005) 2024-06-04 01:05:45 +00:00
Charlie Marsh
77e93157fb
Make target Python version an optional field (#4000)
## Summary

Instead of checking if the target and installed version are the same, we
model the data such that the target version is only present if it was
specified by the user. This also means that we correctly say "requested
version" even if the two happen to be the same.
2024-06-03 22:37:15 +00:00
Charlie Marsh
037e7e345c
Remove unused dummy method (#4001) 2024-06-03 22:28:45 +00:00
Charlie Marsh
b27d36baee
Remove some unnecessary Interpreter clones (#3999) 2024-06-03 22:09:42 +00:00
Charlie Marsh
ef43bcb233
Remove Python from available versions (#3996)
## Summary

I believe this is no longer necessary. Part of the problem here is that
we can't _know_ the full set of available Python versions, especially
once we start resolving against a `Requires-Python` rather than a fixed
set of two versions.
2024-06-03 20:11:45 +00:00
Charlie Marsh
10cd6b94c9
Normalize extras in lockfile (#3958)
## Summary

Previously, when we locked something like `flask[dotenv]`, we created
two separate distributions in the lockfile: one for `flask`, which
included the base dependencies, and one for `flask[dotenv]`, which
included the base dependencies _and_ the `dotenv` dependencies. This was
easy to implement, but it meant that we were duplicating all of the
distribution files for every extra, and duplicating all of the base
dependencies for every extra.

This PR normalizes the data such that we now have one entry per
distribution (i.e., `ExtraName` was removed from `DistributionId`), with
an optional dependencies table with an entry per extra, like:

```toml
[[distribution]]
name = "project"
version = "0.1.0"
source = "editable+file://[TEMP_DIR]/"
sdist = { url = "file://[TEMP_DIR]/" }

[[distribution.dependencies]]
name = "anyio"
version = "3.7.0"
source = "registry+https://pypi.org/simple"

[distribution.optional-dependencies]

[[distribution.optional-dependencies.test]]
name = "iniconfig"
version = "2.0.0"
source = "registry+https://pypi.org/simple"
```

This requires a bit more work upfront, because we now need to merge
multiple packages from the `PetGraph` representation when creating the
lockfile.

Closes https://github.com/astral-sh/uv/issues/3916.
2024-06-03 19:00:35 +00:00
Charlie Marsh
362b00cc12
Remove need to return Python version in get_dependencies (#3993)
## Summary

Once we use a _range_ rather than a precise version, it won't actually
make sense to return a version here. It's no longer required, so I'm
removing it.
2024-06-03 18:42:38 +00:00
Charlie Marsh
1a60368ce4
Use PubGrubPython type in Python incompatibility reporting (#3992)
## Summary

Rather than re-testing compatibility, I think we can just rely on the
types directly.
2024-06-03 14:32:22 -04:00
Charlie Marsh
a589ad5066
Bump version to v0.2.6 (#3991) 2024-06-03 17:40:28 +00:00
Ibraheem Ahmed
1ffe18d861
Avoid race condition in OnceMap (#3987)
## Summary

Fixes a race condition in `OnceMap::wait_blocking` where the inserted
value could potentially be missed, leading to a deadlock. Fairly certain
this will resolve https://github.com/astral-sh/uv/issues/3724.
2024-06-03 12:25:58 -04:00
Charlie Marsh
29ea5d5d9a
Fix reference to --python-version patch behavior (#3989)
## Summary

We changed this at some point but didn't update the documentation.
2024-06-03 15:34:12 +00:00
konsti
8c3a8bf026
Update pubgrub to d4795a31be17669aba11eb741b4a9086acc3eb11 (#3988)
I trimmed down the diff of our pubgrub fork with upstream and
[d4795a31be17669aba11eb741b4a9086acc3eb11](d4795a31be)
(diff:
https://github.com/pubgrub-rs/pubgrub/compare/dev...astral-sh:pubgrub:perma-35)
is the result.
2024-06-03 15:33:34 +00:00
Charlie Marsh
650638fa52
Remove unstable uv lock from pip interface (#3970)
## Summary

I think we can start using `uv lock` and `uv sync` to test this instead.
2024-06-03 15:14:11 +00:00
Andrew Gallant
fbf562d5a8
uv {lock,sync}: propagate index URLs to registry client (#3986)
Otherwise the `uv lock` command wasn't respecting the index URL option.

This is a follow-up to #3984, and I believe should now allow #3970 to be
merged.
2024-06-03 14:38:36 +00:00
Charlie Marsh
a4c73fd07e
Extract index arguments into their own Clap group (#3985)
## Summary

Just removes a lot of repeated documentation. We can expand this
strategy in the future.
2024-06-03 14:27:35 +00:00
Charlie Marsh
da1782808a
Add index URL parameters to Project CLI (#3984)
## Summary

For now, this exists to facilitate testing. We may remove it in the
future in favor of other APIs.
2024-06-03 10:17:41 -04:00
Tim de Jager
1b1600c40e
feat: add back the use of extra env vars to the build dispatch (#3981)
Seems like a recent Pull removed this, couldn't directly find out which.
I'm adding it back as we rely on this API, and I do not see another way
of accessing this, or am I mistaken?

Thanks!
2024-06-03 09:13:44 -04:00
Di-Is
5c776939d2
Add override namespace to pyproject.toml/uv.toml (#3839)
<!--
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

See #3834 .

This PR adds a new namespace, `override-dependencies`, to
pyproject.toml/uv.toml.
This namespace assumes that the dependencies you want to override are
written in the form of `requirements.txt`.


a example of pyproject.toml
```toml
[project]
name = "example"
version = "0.0.0"
dependencies = [
  "flask==3.0.0"
]

[tool.uv]
override-dependencies = [
  "werkzeug==2.3.0"
]
```

This will improve usability by allowing you to override dependencies
without having to specify the --override option when running `uv pip
compile/install`.

## Test Plan

added test to `crates/uv/tests/pip_compile.rs`.

---------

Co-authored-by: konstin <konstin@mailbox.org>
2024-06-03 12:15:51 +02:00
T-256
1b769b054c
Windows: Statically linked C runtime (#3966) 2024-06-03 09:18:07 +02:00
renovate[bot]
314cdbb15b
Update Rust crate axoupdater to v0.6.5 (#3972) 2024-06-02 21:52:35 -04:00