Commit graph

1530 commits

Author SHA1 Message Date
Zanie Blue
906c1ca71d
Fixups to release.sh and sync_scenarios.sh (#2790)
I missed a few things, sorry!
2024-04-03 01:59:58 +00:00
Zander
4b2e67955f
fixed uv can't create .venv for cpython-x86 on Windows (#2707)
Adaptation to the win32 platform is added.

https://docs.python.org/3/library/sysconfig.html#sysconfig.get_platform


## Summary

fixed uv can't create .venv for cpython-x86 on Windows 

[uv can't create .venv for cpython-x86 on Windows
](https://github.com/astral-sh/rye/issues/952)

---------

Co-authored-by: Nashan <34827878+zhuang1234@users.noreply.github.com>
2024-04-02 20:45:53 -05:00
Charlie Marsh
684f790d5d
Preserve .git suffixes and casing in Git dependencies (#2789)
## Summary

I noticed in #2769 that I was now stripping `.git` suffixes from Git
URLs after resolving to a precise commit. This PR cleans up the internal
caching to use a better canonical representation: a `RepositoryUrl`
along with a `GitReference`, instead of a `GitUrl` which can contain
non-canonical data. This gives us both better fidelity (preserving the
`.git`, along with any casing that the user provided when defining the
URL) and is overall cleaner and more robust.
2024-04-03 00:24:29 +00:00
Charlie Marsh
c30a65ee0c
Allow conflicting Git URLs that refer to the same commit SHA (#2769)
## Summary

This PR leverages our lookahead direct URL resolution to significantly
improve the range of Git URLs that we can accept (e.g., if a user
provides the same requirement, once as a direct dependency, and once as
a tag). We did some of this in #2285, but the solution here is more
general and works for arbitrary transitive URLs.

Closes https://github.com/astral-sh/uv/issues/2614.
2024-04-02 23:36:35 +00:00
Zanie Blue
20d4762776
Move scenario sync script to top-level scripts (#2788)
Same idea as https://github.com/astral-sh/uv/pull/2787
2024-04-02 23:27:05 +00:00
Zanie Blue
4838c4da0a
Move bump.sh to scripts/release.sh (#2787)
I find this more discoverable and since we're putting files in the
top-level `scripts/` folder now this seems okay.
2024-04-02 23:25:27 +00:00
Zanie Blue
4c3e5f0f7d
Use cargo update -p uv for release instead of cargo check (#2786)
This is faster and accomplishes what we want
2024-04-02 18:12:47 -05:00
Zanie Blue
0046a0d596
Bump version to 0.1.28 (#2785) 2024-04-02 21:39:35 +00:00
Charlie Marsh
0382abee70
Bump cargo-dist to 0.13.0-prerelease.3 (#2783)
Closes #2770.
2024-04-02 21:23:55 +00:00
Charlie Marsh
03b709a0e7
Detect Fish via FISH_VERSION (#2781)
## Summary

Apparently `SHELL` isn't always set to Fish:
https://github.com/fish-shell/fish-shell/issues/374.

## Test Plan

`uv venv` after running `fish` in macOS.
2024-04-02 19:50:48 +00:00
Zanie Blue
1ac9672b95
Resolve non-determistic behavior in preferences due to site-packages ordering (#2780)
Originally a regression test for #2779 but we found out that there's
some weird behavior where different `anyio` versions were preferred
based on the platform.
2024-04-02 13:48:33 -05:00
Zanie Blue
119d753cfe
Exclude installed distributions with multiple versions from consideration in the resolver (#2779)
Addresses panic introduced in #2596 and reported in
https://github.com/astral-sh/uv/issues/2763#issuecomment-2030674936

When there are multiple versions of a package available, we remove the
existing packages before installing the resolved version to "fix" the
environment. We must remove all of the package versions and reinstall
because removing _any_ of the package versions could break the others.
Since reinstalls require a pull from the remote, this broke a contract
between the resolver and the planner which must always agree on which
packages should come from the remote. This further demonstrates that we
should be constructing the install plan with more concrete knowledge
from the resolver (i.e. `ResolvedDist` instead of `Requirement`) to
avoid having to manually ensure logic matches.

## Test plan

Fails on `main` with panic succeeds on branch

```
uv venv --seed
source .venv/bin/activate
pip install anyio==3.7.0 --ignore-installed
pip install anyio==4.0.0 --ignore-installed
cargo run -- pip install anyio black -v
```
2024-04-02 12:10:52 -05:00
Charlie Marsh
b73cfbb0de
Use user_display for source tree error (#2768) 2024-04-02 00:42:11 +00:00
Charlie Marsh
ccd457a37e
Use distribution database and index for all pre-resolution phases (#2766)
## Summary

Ensures that if we resolve any distributions before the resolver, we
cache the metadata in-memory.

_Also_ ensures that we lock (important!) when resolving Git
distributions.
2024-04-02 00:34:13 +00:00
Charlie Marsh
dfdcce68fd
Split get_or_build_wheel_metadata into distinct methods (#2765)
## Summary

Internal refactor which makes `DistributionDatabase` for unnamed
requirements (or, at least, source distributions).
2024-04-01 23:52:21 +00:00
Charlie Marsh
f2c9e88f3e
Populate the in-memory index when resolving lookahead URLs (#2761)
## Summary

Just ensures that we don't have to go back to the cache when resolving.
2024-04-01 22:07:54 +00:00
Charlie Marsh
999d653404
Use canonical URL to key redirect map (#2764)
## Summary

This fixes a potential bug that revealed itself in
https://github.com/astral-sh/uv/pull/2761. We don't run into this now
because we always use "allowed URLs", stores the "last" compatible URL
in the map. But the use of the "raw" URL (rather than the "canonical"
URL) means that other writers have to follow that same assumption and
iterate over dependencies in-order.
2024-04-01 17:57:13 -04:00
Charlie Marsh
d2bbc07b76
Rename resolver.rs to unnamed.rs in uv-requirements (#2762)
## Summary

We have a few different "resolvers" in here now so the name is
confusing.
2024-04-01 21:40:03 +00:00
Charlie Marsh
a48bcaecb1
Recursively resolve direct URL references upfront (#2684)
## Summary

This PR would enable us to support transitive URL requirements. The key
idea is to leverage the fact that...

- URL requirements can only come from URL requirements.
- URL requirements identify a _specific_ version, and so don't require
backtracking.

Prior to running the "real" resolver, we recursively resolve any URL
requirements, and collect all the known URLs upfront, then pass those to
the resolver as "lookahead" requirements. This means the resolver knows
upfront that if a given package is included, it _must_ use the provided
URL.

Closes https://github.com/astral-sh/uv/issues/1808.
2024-04-01 21:16:20 +00:00
Charlie Marsh
f60e7495ca
Bump version to v0.1.27 (#2758) 2024-04-01 14:54:50 -04:00
Zanie Blue
ba1e9ef182
Add Homebrew system check test (#2736)
Following #2735 adds a system check that uses Homebrew. I think we were
never were actually using Homebrew's Python in the past, we were mislead
or something changed in the runners recently that broke it.
2024-04-01 14:50:45 +00:00
konsti
05ed7ac64b
Don't use exclude newer manually in test functions (#2697)
With this change, all usages of `EXCLUDE_NEWER` are now in command
wrappers, not in the test functions themselves.

For the venv test, i refactored them into the same kind of test context
abstraction that the other test modules have in the second commit.

The third commit makes`"INSTA_FILTERS` "private", removing the last
remaining individual usage.

Pending windows CI 🤞
2024-04-01 16:07:25 +02:00
renovate[bot]
9df6e33b85
Update Rust crate clap to v4.5.4 (#2754) 2024-04-01 09:12:52 +01:00
renovate[bot]
35aa80c149
Update Rust crate chrono to v0.4.37 (#2753) 2024-04-01 08:27:11 +01:00
Charlie Marsh
e68cdb1049
Rename to SourceDistributionBuilder (#2750)
## Summary

This is more consistent with `DistributionDatabase`. The order of the
arguments is also now consistent between the two structs.
2024-04-01 02:37:43 +00:00
Charlie Marsh
8596ff3470
Remove Cache argument from DistributionDatabase (#2749)
## Summary

We can access cache from `BuildContext`. This mirrors
`SourceDistCachedBuilder`, which doesn't accept `Cache` as an argument
and always accesses it through `BuildContext`.
2024-03-31 22:22:25 -04:00
renovate[bot]
0c13eaabe0
Update Rust crate cargo-util to v0.2.10 (#2748) 2024-04-01 02:14:30 +00:00
renovate[bot]
ca2a6bb728
Update Rust crate async-trait to v0.1.79 (#2747) 2024-04-01 02:13:23 +00:00
Charlie Marsh
ffdb283ec9
Add pyproject.toml et al to list of prompted packages (#2746)
## Summary

If the user provides `uv pip install pyproject.toml`, we now prompt them
to confirm that they meant the `pyproject-toml` package (as opposed to
`uv pip install -r pyproject.toml`).
2024-04-01 02:02:06 +00:00
Charlie Marsh
c669542a9e
Respect overrides in all direct-dependency iterators (#2742)
## Summary

We iterate over the project "requirements" directly in a variety of
places. However, it's not always the case that an input "requirement" on
its own will _actually_ be part of the resolution, since we support
"overrides".

Historically, then, overrides haven't worked as expected for _direct_
dependencies (and we have some tests that demonstrate the current,
"wrong" behavior). This is just a bug, but it's not really one that
comes up in practice, since it's rare to apply an override to your _own_
dependency.

However, we're now considering expanding the lookahead concept to
include local transitive dependencies. In this case, it's more and more
important that overrides and constraints are handled consistently.

This PR modifies all the locations in which we iterate over requirements
directly, and modifies them to respect overrides (and constraints, where
necessary).
2024-03-31 14:03:49 -04:00
eth3lbert
f65f013066
Add --exclude-editable support to pip-freeze (#2740)
## Summary

Closes #2738
2024-03-31 17:59:30 +00:00
Charlie Marsh
6d5b5ae9a2
Use distinct Constraints and Overrides types more widely (#2741)
## Summary

No functional changes.
2024-03-31 13:46:37 -04:00
Zanie Blue
472d302ef0
Fix extra CI checks on macOS (#2735)
Alternative to https://github.com/astral-sh/uv/pull/2729 since we're
having problems with the Homebrew Python.
2024-03-30 14:55:34 +00:00
Zanie Blue
0ae285d4b8
Use standard pip instead of pipx (#2733)
An attempt to solve macOS CI failures e.g.
2325653817
2024-03-30 14:12:17 +00:00
Charlie Marsh
ff6aea3f5c
Respect subdirectories when reading static metadata (#2728)
## Summary

This was just an oversight (and a lack of test coverage).

Closes https://github.com/astral-sh/uv/issues/2727.
2024-03-29 22:36:10 -04:00
Charlie Marsh
1f31350d46
Recursively allow URL requirements for local dependencies (#2702)
## Summary

This is a trimmed-down version of
https://github.com/astral-sh/uv/pull/2684 that only applies to local
source trees for now, which enables workspace-like workflows (whereby
local packages can depend on other local packages at arbitrary depth).

Closes #2699.

## Test Plan

Added new tests.

Also cloned this MRE that was shared with me
(https://github.com/timothyjlaurent/uv-poetry-monorepo-mre), and
verified that it was installed without error:

```
❯ cargo run pip install ./uv-poetry-monorepo-mre/app --no-cache
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/uv pip install ./uv-poetry-monorepo-mre/app --no-cache`
Resolved 4 packages in 1.28s
   Built app @ file:///Users/crmarsh/workspace/uv/uv-poetry-monorepo-mre/app
   Built lib1 @ file:///Users/crmarsh/workspace/uv/uv-poetry-monorepo-mre/lib1
   Built lib2 @ file:///Users/crmarsh/workspace/uv/uv-poetry-monorepo-mre/lib2                                        Downloaded 4 packages in 457ms
Installed 4 packages in 2ms
 + app==0.1.0 (from file:///Users/crmarsh/workspace/uv/uv-poetry-monorepo-mre/app)
 + lib1==0.1.0 (from file:///Users/crmarsh/workspace/uv/uv-poetry-monorepo-mre/lib1)
 + lib2==0.1.0 (from file:///Users/crmarsh/workspace/uv/uv-poetry-monorepo-mre/lib2)
 + ruff==0.3.4
```
2024-03-28 22:53:57 +00:00
Charlie Marsh
ce5df77ecb
Add UV_RESOLUTION environment variable for --resolution (#2720)
Closes https://github.com/astral-sh/uv/issues/2710.
2024-03-28 17:08:16 -04:00
Zanie Blue
27b96211a2
Filter flake message for install_git_public_https_missing_commit on win32 (#2717) 2024-03-28 13:52:17 -05:00
Zanie Blue
b36f5d8d48
Test cache against latest release in CI (#2714)
Detect cache incompatibility issues like #2711 by testing against the
last version of uv continuously
2024-03-28 18:49:54 +00:00
Zanie Blue
e1878c8359
Consider installed packages during resolution (#2596)
Previously, we did not consider installed distributions as candidates
while performing resolution. Here, we update the resolver to use
installed distributions that satisfy requirements instead of pulling new
distributions from the registry.

The implementation details are as follows:

- We now provide `SitePackages` to the `CandidateSelector`
- If an installed distribution satisfies the requirement, we prefer it
over remote distributions
- We do not want to allow installed distributions in some cases, i.e.,
upgrade and reinstall
- We address this by introducing an `Exclusions` type which tracks
installed packages to ignore during selection
- There's a new `ResolvedDist` wrapper with `Installed(InstalledDist)`
and `Installable(Dist)` variants
- This lets us pass already installed distributions throughout the
resolver

The user-facing behavior is thoroughly covered in the tests, but
briefly:

- Installing a package that depends on an already-installed package
prefers the local version over the index
- Installing a package with a name that matches an already-installed URL
package does not reinstall from the index
- Reinstalling (--reinstall) a package by name _will_ pull from the
index even if an already-installed URL package is present
- To reinstall the URL package, you must specify the URL in the request

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

Addresses:

- https://github.com/astral-sh/uv/issues/1476
- https://github.com/astral-sh/uv/issues/1856
- https://github.com/astral-sh/uv/issues/2093
- https://github.com/astral-sh/uv/issues/2282
- https://github.com/astral-sh/uv/issues/2383
- https://github.com/astral-sh/uv/issues/2560

## Test plan

- [x] Reproduction at `charlesnicholson/uv-pep420-bug` passes
- [x] Unit test for editable package
([#1476](https://github.com/astral-sh/uv/issues/1476))
- [x] Unit test for previously installed package with empty registry
- [x] Unit test for local non-editable package
- [x] Unit test for new version available locally but not in registry
([#2093](https://github.com/astral-sh/uv/issues/2093))
- ~[ ] Unit test for wheel not available in registry but already
installed locally
([#2282](https://github.com/astral-sh/uv/issues/2282))~ (seems
complicated and not worthwhile)
- [x] Unit test for install from URL dependency then with matching
version ([#2383](https://github.com/astral-sh/uv/issues/2383))
- [x] Unit test for install of new package that depends on installed
package does not change version
([#2560](https://github.com/astral-sh/uv/issues/2560))
- [x] Unit test that `pip compile` does _not_ consider installed
packages
2024-03-28 13:49:17 -05:00
Andrew Gallant
7b685a8158
uv-cache: bump built-wheels cache version (#2715)
It turns out that #2712 did _not_ fix #2711. After I put up #2712, I
started trying to track down the specific change that caused the
failure. I had assumed at first that it was related to one of our `rkyv`
types, but it actually ended up being one of our msgpack caches. I think
the failure mode is still fundamentally the same idea: the cached data
changed in a way that is still valid msgpack, but got interpreted
differently after deserializing.

The specific change that caused this was the [removal of a field] from
our
metadata type.

Ideally we would just undo the change and add the field back. But that
change has already been shipped out to users. So I believe the only
plausible choice at this point is to bump the `built-wheels` cache. This
will unfortunately mean that `uv` will need to re-build wheels.

Fixes #2711

[removal of a field]:
365c292525 (diff-e42586829f9c2cdbb909bedc5cf95691cc415247f2cbc2ebeb80d887020457bbL29)
2024-03-28 13:24:47 -05:00
Zanie Blue
ffa1b01176
Bump version to 0.1.26 (#2713) 2024-03-28 12:55:36 -05:00
Andrew Gallant
c72d3d73d5
uv-cache: bump simple cache version (#2712)
It seems likely that we forgot to bump the version of the "simple" cache
in the 0.1.25 release. I'm still working on confirming it, but I figured
I'd get this bump up first.

The main problem here is that our "simple" cache is represented by
`rkyv`, and that in turn is tightly coupled to the representation of a
selection of data types in `uv`. Changing those data types without
bumping the cache version can result in cache deserialization errors
like this, or in the worst case, silent logic errors.

One possibility here is that the representation changed in a way that
permitted it to pass `rkyv` validation, but changed how the data itself
is interpreted. Our cache is robust with respect to `rkyv` validation
(if it fails, the cache will invalidate the entry and self-heal), but
being robust to higher level logical errors in interpretation of the
data is a much more significant challenge. Our best bet there is perhaps
some kind of checksum that we could do on top of `rkyv` validation (or
instead of it), and thus convert silent logical changes in how the data
is interpreted into failure modes that we're already robust to.

Fixes #2711
2024-03-28 12:29:29 -05:00
Zanie Blue
4e59bfd16e
Bump version to 0.1.25 (#2709)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-03-28 10:17:52 -05:00
Charlie Marsh
f8f7f848f5
Remove Tags from tracing (#2704)
Oops, these show in `tracing` now, and they're huge.
2024-03-28 02:18:54 +00:00
Charlie Marsh
4cc91cc6bb
Add convenience methods to Manifest to iterate over requirements (#2701)
## Summary

These are repeated a bunch. It's nice to DRY them up and ensure the
ordering is consistent.
2024-03-28 01:03:44 +00:00
Charlie Marsh
b6ab919945
Make tags non-required for fetching wheel metadata (#2700)
## Summary

This looks like a big change but it really isn't. Rather, I just split
`get_or_build_wheel` into separate `get_wheel` and `build_wheel` methods
internally, which made `get_or_build_wheel_metadata` capable of _not_
relying on `Tags`, which in turn makes it easier for us to use the
`DistributionDatabase` in various places without having it coupled to an
interpreter or environment (something we already did for
`SourceDistributionBuilder`).
2024-03-28 00:06:25 +00:00
Charlie Marsh
cf30932831
Allow prereleases, locals, and URLs in non-editable path requirements (#2671)
## Summary

This PR enables the resolver to "accept" URLs, prereleases, and local
version specifiers for direct dependencies of path dependencies. As a
result, `uv pip install .` and `uv pip install -e .` now behave
identically, in that neither has a restriction on URL dependencies and
the like.

Closes https://github.com/astral-sh/uv/issues/2643.
Closes https://github.com/astral-sh/uv/issues/1853.
2024-03-27 22:17:09 +00:00
Charlie Marsh
4b69ad4281
Remove some unused dependencies (#2698) 2024-03-27 17:50:55 -04:00
Charlie Marsh
f8fa887c0b
Use Resolver in pip sync (#2696)
## Summary

This PR removes the custom `DistFinder` that we use in `pip sync`. This
originally existed because `VersionMap` wasn't lazy, and so we saved a
lot of time in `DistFinder` by reading distribution data lazily. But
now, AFAICT, there's really no benefit. Maintaining `DistFinder` means
we effectively have to maintain two resolvers, and end up fixing bugs in
`DistFinder` that don't exist in the `Resolver` (like #2688.

Closes #2694.

Closes #2443.

## Test Plan

I ran this benchmark a bunch. It's basically a wash. Sometimes one is
faster than the other.

```
❯ python -m scripts.bench \
        --uv-path ./target/release/main \
        --uv-path ./target/release/uv \
        scripts/requirements/compiled/trio.txt --min-runs 50 --benchmark install-warm --warmup 25
Benchmark 1: ./target/release/main (install-warm)
  Time (mean ± σ):      54.0 ms ±  10.6 ms    [User: 8.7 ms, System: 98.1 ms]
  Range (min … max):    45.5 ms …  94.3 ms    50 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Benchmark 2: ./target/release/uv (install-warm)
  Time (mean ± σ):      50.7 ms ±   9.2 ms    [User: 8.7 ms, System: 98.6 ms]
  Range (min … max):    44.0 ms …  98.6 ms    50 runs

  Warning: The first benchmarking run for this command was significantly slower than the rest (77.6 ms). This could be caused by (filesystem) caches that were not filled until after the first run. You should consider using the '--warmup' option to fill those caches before the actual benchmark. Alternatively, use the '--prepare' option to clear the caches before each timing run.

Summary
  './target/release/uv (install-warm)' ran
    1.06 ± 0.29 times faster than './target/release/main (install-warm)'
```
2024-03-27 17:36:38 -04:00