Commit graph

3091 commits

Author SHA1 Message Date
Charlie Marsh
db33497974
Add some test coverage for --offline in uv lock (#6122)
## Summary

This helps document some of the cases in which we expect the resolver to
have to pull new information.
2024-08-15 17:32:15 +00:00
Zanie Blue
0efdbcc95b
Improve display of available package ranges (#6118)
Includes the changes from https://github.com/astral-sh/uv/pull/6071 but
takes them way further.

When we have the set of available versions for a package, we can do a
much better job displaying an error.

For example:

```
❯ uv add 'httpx>999,<9999'
  × No solution found when resolving dependencies:
  ╰─▶ Because only the following versions of httpx are available:
          httpx<=999
          httpx>=9999
      and example==0.1.0 depends on httpx>999,<9999, we can conclude that example==0.1.0 cannot be used.
      And because only example==0.1.0 is available and you require example, we can conclude that the requirements are unsatisfiable.
```

The resolver has demonstrated that the requested range cannot be used
because there are only versions in ranges _outside_ the requested range.
However, the display of the range of available versions is pretty bad!
We say there are versions of httpx available in ranges that definitely
have no versions available.

With this pull request, the error becomes:

```
❯ uv add 'httpx>999,<9999'
  × No solution found when resolving dependencies:
  ╰─▶ Because only httpx<=1.0.0b0 is available and example depends on httpx>999,<9999, we can conclude that example's
      requirements are unsatisfiable.
      And because your workspace requires example, we can conclude that your workspace's requirements are unsatisfiable.
```

We achieve this by:

1. Dropping ranges disjoint with the range of available versions, e.g.,
this removes `httpx>=9999`
2. Replacing ranges that capture the _entire_ range of available
versions with the smaller range, e.g., this replaces `httpx<=999` with
`<=1.0.0b0`.

~Note that when we perform (2), we may include an additional bound that
is not relevant, e.g., we include the lower bound of `>=0.6.7`. This is
a bit extraneous, but I don't think it's confusing. We can consider some
advanced logic to avoid that later.~ (edit: I did this, it wasn't hard)

We also improve error messages when there is _only_ one version
available by showing that version instead of a range.
2024-08-15 17:28:45 +00:00
Charlie Marsh
9d514cbbe0
Return a structured result from Lock::satisfies (#6119)
## Summary

Gives the caller control over how messages are reported back to the
user. Also merges the index-location validation into the lock, since
we're already iterating over the packages.
2024-08-15 13:19:40 -04:00
Zanie Blue
b627c9f5e1
Add test cases for unsat errors in workspaces with extras and development dependencies (#6121)
Adds more test coverage!

Unfortunately the error messages are bad.
2024-08-15 12:02:03 -05:00
Charlie Marsh
592af438b8
Remove requires-python application in lock deserialization (#6115)
## Summary

This is no longer required since we no longer implement `Eq` on `Lock`.
It will also sometimes be "wrong" as of #6076, since we now apply
different `requires-python` filtering to different parts of the tree
during resolution.
2024-08-15 12:54:06 -04:00
Charlie Marsh
3ee865831f
Change debug! back to trace! in filtering (#6117)
## Summary

I changed this for debugging and forgot to revert. Not awful but
probably a little much for `debug!`.
2024-08-15 16:07:02 +00:00
Charlie Marsh
4d13b525ef
Avoid cloning requirement for unchanged markers (#6116)
## Summary

Small optimization.
2024-08-15 15:58:20 +00:00
Charlie Marsh
984346f669
Avoid warning for redundant --no-project (#6111) 2024-08-15 11:51:07 -04:00
Charlie Marsh
fe0b873352
Always narrow markers by Python version (#6076)
## Summary

Using https://github.com/astral-sh/uv/issues/6064 as a motivating
example: at present, on main, we're not properly propagating the
`Requires-Python` simplifications. In that case, for example, we end up
solving for a branch with `python_version < 3.11`, and a branch `>=
3.11`, even though `Requires-Python` is `>=3.11`. Later, when we get to
the graph, we apply version simplification based on `Requires-Python`,
which causes us to _remove_ the `python_version < 3.11` markers
entirely, leaving us with duplicate dependencies for `pylint`.

This PR instead tries to ensure that we always apply this narrowing to
requirements and forks, so that we don't need to apply the same
simplification when constructing the graph at all.

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

Closes #6059.
2024-08-15 11:50:00 -04:00
Zanie Blue
f988e43ebd
Use "your requirements" consistently in resolver error messages (#6113)
Follow-up to
https://github.com/astral-sh/uv/pull/6092#discussion_r1717648821
2024-08-15 10:26:30 -05:00
Charlie Marsh
171c39d365
Remove 'tool' reference on uv run CLI (#6110) 2024-08-15 14:09:02 +00:00
Charlie Marsh
7dbed4bb2d
Treat Git sources as immutable in lockfile (#6109)
## Summary

We don't need to write metadata for Git sources, since we lock a
specific SHA (and so the metadata is immutable).
2024-08-15 09:26:47 -04:00
Charlie Marsh
29179570a1
Use sets rather than vectors for lockfile requirements (#6107)
## Summary

Ensures that `--locked` is robust to reordering and duplicates.
2024-08-15 13:00:35 +00:00
Charlie Marsh
fd0daae969
Add immutable definition to Source struct (#6108)
## Summary

Centralizes the definition of an "immutable" source.
2024-08-15 12:51:41 +00:00
Andrew Gallant
3187dc1a2f uv-resolver: remove code that was intended to be removed
In particular, I added this as a hack to avoid a kinda of
instability that was caused by our marker code not correctly
detecting markers that were always false. But that has since
been fixed.

Removing this code doesn't change any tests. Arguably it
should be possible to come up with a test that failed with
this hack inserted but succeeded without it. In particular,
with this hack, new forks were being prevented from being
added even when they ought to be added, e.g., when preferences
get updated.
2024-08-15 05:25:55 -07:00
Charlie Marsh
6333823236
Change the definition of --locked to require satisfaction check (#6102)
## Summary

This PR changes the definition of `--locked` from:

> Produces the same `Lock`

To:

> Passes `Lock::satisfies`

This is a subtle but important difference. Previous, if
`Lock::satisfies` failed, we would run a resolution, then do
`existing_lock == lock`. If the two weren't equal, and `--locked` was
specified, we'd throw an error.

The equality check is hard to get right. For example, it means that we
can't ship #6076 without changing our marker representation, since the
deserialized lockfile "loses" some of the internal marker state that
gets accumulated during resolution.

The downside of this change is that there could be scenarios in which
`uv lock --locked` fails even though the lockfile would actually work
and the exact TOML would be unchanged. But... I think it's ok if
`--locked` fails after the user modifies something?
2024-08-15 08:17:28 -04:00
Charlie Marsh
7551097a17
Add env var to --link-mode=copy warning (#6103)
## Summary

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

## Test Plan

![Screenshot 2024-08-14 at 9 35
45 PM](https://github.com/user-attachments/assets/f2cf6382-dfc3-4c0f-abc2-776fbdfad01d)
2024-08-15 03:14:53 +00:00
Zanie Blue
76e324857b
Improve resolver error messages for single-project workspaces (#6095)
Extends https://github.com/astral-sh/uv/pull/6092 to improve resolver
error messages for workspaces that have a single member.

As before, this requires a two-step approach of

1. Traversing the derivation tree and collapsing some members. In this
case, we drop the empty root node in favor of the project.
2. Using special-case formatting for packages. In this case, the
workspace package is referred to with "your project" instead of its
name.
2024-08-15 03:08:56 +00:00
Zanie Blue
2e3e6a01aa
Improve resolver error messages referencing workspace members (#6092)
An extension of #6090 that replaces #6066.

In brief, 

1. Workspace member names are passed to the resolver for no solution
errors
2. There is a new derivation tree pre-processing step that trims
`NoVersion` incompatibilities for workspace members from the derivation
tree. This avoids showing redundant clauses like `Because only
bird==0.1.0 is available and bird==0.1.0 depends on anyio==4.3.0, we can
conclude that all versions of bird depend on anyio==4.3.0.`. As a minor
note, we use a custom incompatibility kind to mark these
incompatibilities at resolution-time instead of afterwards.
3. Root dependencies on workspace members say `your workspace requires
bird` rather than `you require bird`
4. Workspace member package display omits the version, e.g., `bird`
instead of `bird==0.1.0`
5. Instead of reporting a workspace member as unusable we note that its
requirements cannot be solved, e.g., `bird's requirements are
unsatisfiable` instead of `bird cannot be used`.
6. Instead of saying `your requirements are unsatisfiable` we say `your
workspace's requirements are unsatisfiable` when in a workspace, since
we're not in a "provide direct requirements" paradigm.

As an annoying but minor implementation detail, `PackageRange` now
requires access to the `PubGrubReportFormatter` so it can determine if
it is formatting a workspace member or not. We could probably improve
the abstractions in the future.

As a follow-up, we should additional special casing for "single project"
workspaces to avoid mention of the workspace concept in simple projects.
However, it looks like this will require additional tree manipulations
so I'm going to keep it separate.
2024-08-15 02:41:31 +00:00
Charlie Marsh
5c4e111a1b
Add a compatibility test for [package.metadata] (#6098) 2024-08-15 00:29:53 +00:00
Charlie Marsh
7b67b5a328
Strip SHA when constructing package source (#6097)
## Summary

Similar to #5805, but applies the normalization earlier so that
`--locked` passes for URLs that contain fragments.
2024-08-14 20:12:32 -04:00
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