Commit Graph

2820 Commits

Author SHA1 Message Date
Charlie Marsh e3f345ce09
Validate lockfile (rather than re-resolve) in `uv lock` (#6091)
## Summary

Historically, in order to "resolve from a lockfile", we've taken the
lockfile, used it to pre-populate the in-memory metadata index, then run
a resolution. If the resolution didn't match our existing resolution, we
re-resolved from scratch.

This was an appealing approach because (in theory) it didn't require any
dedicated logic beyond pre-populating the index. However, it's proven to
be _really_ hard to get right, because it's a stricter requirement than
we need. We just need the current lockfile to _satisfy_ the requirements
provided by the user. We don't actually need a second resolution to
produce the exact same result. And it's not uncommon that this second
resolution differs, because we seed it with preferences, which
fundamentally changes its course. We've worked hard to minimize those
"instabilities", but they're still present.

The approach here is intended to be much simpler. Instead of resolving
from the lockfile, we just check if the current resolution satisfies the
state of the workspace. Specifically, we check if the lockfile (1)
contains all the relevant members, and (2) matches the metadata for all
dependencies, recursively. (We skip registry dependencies, assuming that
they're immutable.)

This may actually be too conservative, since we can have resolutions
that satisfy the requirements, even if the requirements have changed
slightly. But we want to bias towards correctness for now.

My hope is that this scheme will be more performant, simpler, and more
robust.

Closes https://github.com/astral-sh/uv/issues/6063.
2024-08-14 20:00:15 -04:00
Zanie Blue 359f39ca0f
Avoid displaying "failed to download" on build failures for local source distributions (#6075)
Especially with workspace members (e.g., [this new test
case](https://github.com/astral-sh/uv/pull/6073/files#diff-273076013b4f5a8139defd5dcd24f5d1eb91c0266dceb4448fdeddceb79f7738R1377-R1379)),
I find it very confusing that we say we failed to download these
distributions.
2024-08-14 17:27:55 -05:00
Zanie Blue dc67023677
Fix loading of cached metadata for git distributions with subdirectories (#6094)
Applies the same fix as https://github.com/astral-sh/uv/issues/5944 to
cache loads

Closes https://github.com/astral-sh/uv/issues/6093
2024-08-14 21:19:30 +00:00
Zanie Blue 981b7ca5ec
Add test cases for unsat dependencies in workspace members (#6073)
Adding some test cases to help inform the work in #6066
2024-08-14 10:50:59 -05:00
github-actions[bot] d6c858b0d3
Update Pythons to include Python 3.12.5 (#6087) 2024-08-14 15:18:01 +00:00
Charlie Marsh 9de3c945f6
Remove `same-graph` merging in resolver (#6077)
## Summary

This was added in https://github.com/astral-sh/uv/pull/5405 but is now
the cause of an instability in `github_wikidata_bot`. Specifically, on
the initial run, we fork in `pydantic==2.8.2`, via:

```
Requires-Dist: typing-extensions>=4.12.2; python_version >= '3.13'
Requires-Dist: typing-extensions>=4.6.1; python_version < '3.13'
```

In the end, we resolve a single version of `typing-extensions`
(`4.12.2`)... But we don't recognize the two resolutions as the "same
graph", because we propagate the fork markers, and so the "edges" have
different markers on them...

In the second run through, when we have the forks in advance, we don't
split on Pydantic... We just try to solve from the root with the current
forks. This is fundamentally different and I fear it will be the cause
of many instabilities. But removing this graph check fixes the proximate
issue.

I don't really understand why this was added since there was no test
coverage in the PR.
2024-08-14 14:06:18 +00:00
Charlie Marsh 4a902a7ca1
Propagate fork markers to extras (#6065)
## Summary

When constructing the `Resolution`, we only propagated the fork markers
to the package node, but not the extras node. This led to cases in which
an extra could be included unconditionally or otherwise diverge from the
base package version.

Closes https://github.com/astral-sh/uv/issues/6062.
2024-08-14 09:55:39 -04:00
Charlie Marsh 8c8f723005
Store `environment-markers` in solve order (#6078)
## Summary

Right now, we store the environment markers in a `BTreeSet` -- so
they're sorted, but the sort doesn't really tell us anything. I think we
should instead store them in the order in which we solved. I thought
this might fix an instability (it didn't), but I think it's still good
to ensure we solve in the same order.

I also changed from `Option<Vec>` to just `Vec`, since there was no
distinction between `None` and empty.
2024-08-14 09:20:12 -04:00
Charlie Marsh 8fac63d4ce
Redact Git credentials from `pyproject.toml` (#6074)
## Summary

We retain them if you use `--raw-sources`, but otherwise they're
removed. We still respect them in the subsequent `uv.lock` via an
in-process store.

Closes #6056.
2024-08-14 01:30:02 +00:00
Charlie Marsh 92263108cc
Redact Git credentials in lockfile (#6070)
## Summary

Closes https://github.com/astral-sh/uv/issues/6055.
2024-08-13 19:48:59 -04:00
Charlie Marsh 1bbb05dca7
Invalidate `uv.lock` if registry sources are removed (#6026)
## Summary

Now, if you resolve against a registry, then swap it out for another, we
won't reuse the lockfile. (If you don't provide any registry
configuration, then we won't enforce this, so that `uv lock --index-url
foo` and `uv lock` is stable.)

Closes https://github.com/astral-sh/uv/issues/5920.
2024-08-13 23:42:04 +00:00
Andrew Gallant 34ac8cb53f uv/tests: add an unresolvable test case involving overlapping markers
This example came up in discussion and it was initially unclear whether
we should try to support it. Specifically, by automatically assuming
that the `datasets < 2.19` dependency had a marker corresponding to the
negation of the conjunction of the other sibling markers for that same
package. But this was deemed, I think, a little too magical.

This in turn implies that whenever there are sibling dependencies with
overlapping marker expressions, their version constraints also need to
be overlapping. Otherwise, for any marker environment that matches both
marker expressions, it would be impossible to select a single version.
2024-08-13 10:14:48 -07:00
Zanie Blue 8d66718077
Bump version to 0.2.36 (#6060) 2024-08-13 12:05:11 -05:00
eth3lbert ef948619ee
Hide python options in `uv tool list` help (#6003)
## Summary

Closes #5982 .

## Test Plan

```
cargo run tool list --help
```

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-08-13 11:21:44 -05:00
Andrew Gallant b3e3fd1aeb uv/tests: update ecosystem snapshot for 'transformers' 2024-08-13 08:35:46 -07:00
Andrew Gallant 90bcd9f48c uv/tests: only consider dependency specification for fork matching marker
The test in this case has this comment:

```
/// If a dependency requests a prerelease version with an overlapping marker expression,
/// we should prefer the prerelease version in both forks.
```

With this setup:

```
    let pyproject_toml = context.temp_dir.child("pyproject.toml");
    pyproject_toml.write_str(indoc! {r#"
        [project]
        name = "example"
        version = "0.0.0"
        dependencies = [
            "cffi >= 1.17.0rc1 ; os_name == 'Linux'"
        ]
        requires-python = ">=3.11"
    "#})?;

    let requirements_in = context.temp_dir.child("requirements.in");
    requirements_in.write_str(indoc! {"
        cffi
        .
    "})?;
```

The change in this commit _seems_ more correct that what we had,
although it does seem to contradict the comment. Namely, in the `os_name
!= "Linux"` fork, we don't prefer the pre-release version since the
`cffi >= 1.17.0rc1` bound doesn't apply.

It's not quite clear what to do in this instance.
2024-08-13 08:35:46 -07:00
Andrew Gallant 65be566846 uv/tests: update test that expects to find a resolution
Fixes #4640
2024-08-13 08:35:46 -07:00
Andrew Gallant 4d57e5deb8 uv/tests: "mundane" updates to snapshots
I believe these are all changes that aren't necessarily
expected, but also seem harmless. Like the order in which
fork markers are written to the lock file. (Although one
wonders if we should fix that once and for all by defining
a complete sort function for forks.)
2024-08-13 08:35:46 -07:00
Andrew Gallant 04b7cf894a uv-resolver: rewrite forking to be based on overlapping markers
Closes #4732
2024-08-13 08:35:46 -07:00
Andrew Gallant 8dbf43c85d
uv/tests: add new 'ecosystem' integration tests (#5970)
At a high level, this PR adds a smattering of new tests that
effectively snapshot the output of `uv lock` for a selection of
"ecosystem" projects. That is, real Python projects for which we expect
`uv` to work well with.

The main idea with these tests is to get a better idea of how changes
in `uv` impact the lock files of real world projects. For example,
we're hoping that these tests will help give us data for how #5733
differs from #5887.

This has already revealed some bugs. Namely, re-running `uv lock` for a
second time will produce a different lock file for some projects. So to
prioritize getting the tests added, for those projects, we don't do the
deterministic checking.
2024-08-13 09:48:00 -04:00
Charlie Marsh 9c8a549b3d
Add tests for mixed sources and versions in lock (#6051)
## Summary

Related to https://github.com/astral-sh/uv/issues/3943.
2024-08-12 23:49:36 +00:00
Charlie Marsh 02e4086a30
Add test coverage for transitive and cross-workspace extras (#6050)
## Summary

Related to https://github.com/astral-sh/uv/issues/3943.
2024-08-12 23:36:43 +00:00
Charlie Marsh 4be8301935
Use simplified paths in lockfile (#6049)
## Summary

Closes https://github.com/astral-sh/uv/issues/6048.
2024-08-12 19:34:29 -04:00
Charlie Marsh e71bb0afb8
Add test coverage for mixed editables in `tool.uv.sources` (#6047)
## Summary

Related to https://github.com/astral-sh/uv/issues/3943.
2024-08-12 23:27:11 +00:00
Charlie Marsh 73e32f4eb9
Add test coverage for direct URLs with sources (#6046)
## Summary

Ensures that we don't respect `tool.uv.sources` for (eg.) direct URL
requirements, as intended.

Related to https://github.com/astral-sh/uv/issues/3943.

Closes https://github.com/astral-sh/uv/issues/6048.
2024-08-12 23:14:08 +00:00
Charlie Marsh 0fdadf6ba2
Resolve relative `tool.uv.sources` relative to containing project (#6045)
## Summary

Related to https://github.com/astral-sh/uv/issues/3943.

Closes https://github.com/astral-sh/uv/issues/6044.
2024-08-12 17:14:13 -04:00
Charlie Marsh ae7a8d7f33
Colocate Python install cache with destination directory (#6043)
## Summary

Closes https://github.com/astral-sh/uv/issues/6036.
2024-08-12 16:15:30 -04:00
Charlie Marsh e27a1fce60
Add more tests for uv lock (#6040)
## Summary

Misc. cases we're missing vis-a-vis pip install.
2024-08-12 15:56:01 -04:00
Zanie Blue f6f1bd2f14
Improve top-level help for `uv tool` commands (#5983)
More work needs to be done for all of the options
2024-08-12 17:35:50 +00:00
Ibraheem Ahmed fb5c3bb918
Remove uses of `Option<MarkerTree>` in `ResolutionGraph` (#6035)
## Summary

Missed this one in https://github.com/astral-sh/uv/pull/5978.

Resolves https://github.com/astral-sh/uv/issues/5902.
2024-08-12 10:31:07 -04:00
Charlie Marsh b911a108b9
Filter mixed sources from `--find-links` entries in lockfile (#6025)
## Summary

Our current handling of `--find-links` merges the entries in each index.
As a result, we can end up with `AnnotatedDist` entries that reference
distributions across indexes.

I'd like to change `--find-links` such that each `--find-links` entry is
just treated as its own index (so, e.g., if `requests` exists in the
first `--find-links` entry, we don't even check the registry by
default), which would _also_ fix this problem automatically. But that's
a behavior change... So for now, in the lockfile, we filter
distributions that don't match the source index URL.

There are two cases to consider:

- There's a source distribution. Then, for the ID to reference the
`--find-links` registry, the source distribution _must_ have come from
the `--find-links` entry, so it's fine to discard any wheels from the
"wrong" registry without breaking any compatibility guarantees.
- There's no source distribution. Then the best wheel must come from the
`--find-links` registry. We might lose some platform coverage by
discarding the other wheels, but it shouldn't break any of the
"guarantees", since we have at least one wheel that fits in the version
range.

Closes https://github.com/astral-sh/uv/issues/6015.
2024-08-12 08:54:09 -04:00
Charlie Marsh e941bb6623
Treat local indexes as registry sources in lockfile (#6016)
## Summary

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

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

Adds test coverage for https://github.com/astral-sh/uv/issues/6015.
2024-08-11 22:02:39 -04:00
renovate[bot] 5d4ff4341e
Update Rust crate dunce to v1.0.5 (#6019) 2024-08-12 01:25:55 +00:00
renovate[bot] 8cd624f26e
Update Rust crate assert_cmd to v2.0.16 (#6017) 2024-08-12 01:23:46 +00:00
Alexander Gherm 798cc7bf3c
Make more informative warning message when failed to parse pyproject.toml (#6009)
## Summary

Added the actual error message to the warning when uv fails to parse
`pyproject.toml`.

Resolves https://github.com/astral-sh/uv/issues/5934

## Test Plan

Took the case from the issue:
- have `pyproject.toml` which contains
```
[tool.uv]
foobar = false
```
- 
```
$ uv venv --preview -v
```
- Expect the message that contains the actual problem in the
`pyproject.toml` like:
```
warning: Failed to parse `pyproject.toml` during settings discovery: unknown field `foobar`; skipping...
```
2024-08-11 21:13:14 +00:00
Charlie Marsh 5c44937742
Misc. edits to script parsing (#5999) 2024-08-10 22:07:05 -04:00
Ahmed Ilyas 2d53e35e39
Support PEP 723 scripts in `uv add` and `uv remove` (#5995)
## Summary

Resolves https://github.com/astral-sh/uv/issues/4667

## Test Plan

`cargo test`
2024-08-11 01:40:59 +00:00
Charlie Marsh 9b8c07bf18
Avoid replacing executables on no-op upgrades (#5998)
## Summary

Also introduces a "changelog" concept that enables callers to introspect
the modifications that were made to a virtual environment.
2024-08-11 00:34:06 +00:00
Charlie Marsh ec8248ff93
Use upgrade-specific output for tool upgrade (#5997)
## Summary

Closes https://github.com/astral-sh/uv/issues/5949.
2024-08-10 20:24:49 -04:00
Ibraheem Ahmed f5110f7b5e
Remove uses of `Option<MarkerTree>` (#5978)
## Summary

Follow up to https://github.com/astral-sh/uv/pull/5898. This should fix
some of the failures in https://github.com/astral-sh/uv/pull/5887 where
`uv lock --locked` is failing due to `Some(true)` and `None` markers not
comparing equal.
2024-08-10 13:23:29 -04:00
Charlie Marsh 4eced1bd0c
Add better `tool upgrade` tests (#5996)
## Summary

A lot of the existing tests were no-ops. For convenience, we now use the
trick of: install from Test PyPI (to get an outdated "latest"), then
upgrade from PyPI.
2024-08-10 16:56:58 +00:00
Charlie Marsh 2822dde8cb
Add resolver error context to `run` and `tool run` (#5991)
## Summary

Closes https://github.com/astral-sh/uv/issues/5530.
2024-08-10 03:21:56 +00:00
Charlie Marsh f10c28225c
Support `tool.uv` in PEP 723 scripts (#5990)
## Summary

This includes both _settings_ and _sources.

Closes https://github.com/astral-sh/uv/issues/5855.
2024-08-09 23:11:10 -04:00
Charlie Marsh 19ac9af167
Use consistent canonicalization for URLs (#5980)
Right now, the URL gets out-of-sync with the install path, since the
install path is canonicalized. This leads to a subtle error on Windows
(in CI) in which we don't preserve caching across resolution and
installation.
2024-08-09 21:43:36 -04:00
Charlie Marsh cd0171a2ed
Remove `editable: false` support (#5987)
## Summary

This doesn't actually work yet. We'll re-add it in the future.

Closes #5958.
2024-08-09 20:59:23 -04:00
Zanie Blue e097f948c9
Bump version to 0.2.35 (#5984) 2024-08-09 19:21:06 -05:00
Charlie Marsh a3b1a4b8da
Warn when project-specific settings are passed to non-project `uv run` commands (#5977)
## Summary

Closes https://github.com/astral-sh/uv/issues/5856.
2024-08-09 23:10:33 +00:00
konsti fcbee9ce25
Support relative path wheels (#5969)
Surprisingly, this is a lockfile schema change: We can't store relative
paths in urls, so we have to store a `filename` entry instead of the
whole url.

Fixes #4355
2024-08-09 21:57:16 +00:00
Charlie Marsh dd32087842
Remove unnecessary optional from `uv run` (#5976)
## Summary

This is always `Some` now.
2024-08-09 20:13:47 +00:00
Zanie Blue 921050d747
Improve the `uv sync` CLI documentation (#5930) 2024-08-09 14:46:32 -05:00