Commit graph

4903 commits

Author SHA1 Message Date
Andrew Gallant
7772e6249f
add basic "install from lock file" operation (#3340)
This PR principally adds a routine for converting a `Lock` to a
`Resolution`, where a `Resolution` is a map of package names pinned to
a specific version.

I'm not sure that a `Resolution` is ultimately what we want here (we
might need more stuff), but this was the quickest route I could find to
plug a `Lock` into our existing `uv pip install` infrastructure.

This commit also does a little refactoring of the `Lock` types. The
main thing is to permit extra state on some of the types (like a
`by_id` map on `Lock` for quick lookups of distributions) that aren't
included in the serialization format of a `Lock`. We achieve this
by defining separate `Wire` types that are automatically converted
to-and-from via `serde`.

Note that like with the lock file format types themselves, we leave a
few `todo!()` expressions around. The main idea is to get something
minimally working without spending too much effort here. (A fair bit
of refactoring will be required to generate a lock file, and it's
not clear how much this code will wind up needing to change anyway.)
In particular, we only handle the case of installing wheels from a
registry.

A demonstration of the full flow:

```
$ requirements.in
anyio
$ cargo run -p uv -- pip compile -p3.10 requirements.in --unstable-uv-lock-file
$ uv venv
$ cargo run -p uv -- pip install --unstable-uv-lock-file anyio -r requirements.in
Installed 5 packages in 7ms
 + anyio==4.3.0
 + exceptiongroup==1.2.1
 + idna==3.7
 + sniffio==1.3.1
 + typing-extensions==4.11.0
```

In order to install from a lock file, we start from the root and do a
breadth first traversal over its dependencies. We aren't yet filtering
on marker expressions (since they aren't in the lock file yet), but we
should be able to add that in the future. In so doing, the traversal
should select only the subset of distributions relevant for the current
platform.
2024-05-03 08:18:36 -04:00
Zanie Blue
49675558eb
Split virtual environment detection into a dedicated module (#3331)
Split out of https://github.com/astral-sh/uv/pull/3266
2024-05-02 06:58:48 -05:00
Zanie Blue
c28a2806b3
Separate interpreter selectors into implementation and platform modules (#3332)
Split out of #3266

The "selector" concept doesn't seem well enough defined as-is. For
example, `PythonVersion` belongs there but isn't present. Going for
smaller modules instead.
2024-05-02 11:55:01 +00:00
Zanie Blue
5048ccef3a
Update toolchain discovery to avoid runtime panic (#3330)
Split out of https://github.com/astral-sh/uv/pull/3266

If `UV_BOOTSTRAP_DIR` and `CARGO_MANIFEST_DIR` are both unset, we
currently panic. This isn't good once we start to use managed toolchains
in production. We'll need to change this more later once the toolchain
directory is more user-facing.
2024-05-02 06:44:16 -05:00
Zanie Blue
528bed5bed
Move py launcher handling into separate module (#3329)
Split out of #3266 

Mostly an organizational change, with some error handling
simplification.
2024-05-02 06:44:07 -05:00
konsti
2e27abd34a
Remove Into::into (#3337)
Motivated by
https://github.com/astral-sh/uv/pull/3263#discussion_r1585896159

I don't think we can lint againt this since we do want to allow
`.into()`, just not the bare `Into::into` call.
2024-05-02 10:26:42 +00:00
konsti
538a85b827
Add missing optional rkyv feature bound (#3336)
`PackageName` needs to derive the rkyv types.
2024-05-02 10:01:10 +00:00
Charlie Marsh
c6137702a5
Accept --no-upgrade, --no-refresh, etc. on the CLI (#3328)
## Summary

We added `--no-X` variants for all other flags, but omitted these. Seems
more consistent to support them.

Closes https://github.com/astral-sh/uv/issues/1900.
2024-05-01 11:13:33 -07:00
Charlie Marsh
614c07329b
Allow --force to overwrite existing virtualenv (#2548)
## Summary

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

## Test Plan

- `mkdir .venv`
- `touch .venv/foo`
- `cargo run venv` (ensure failure)
- `cargo run venv --force` (ensure success)
- `cargo run venv --force` (ensure success again)
2024-05-01 16:34:52 +00:00
Zanie Blue
630d3fde5c
Merge uv-toolchain and uv-interpreter (#3265)
Moves all of `uv-toolchain` into `uv-interpreter`. We may split these
out in the future, but the refactoring I want to do for interpreter
discovery is easier if I don't have to deal with entanglement. Includes
some restructuring of `uv-interpreter`.

Part of #2386
2024-04-30 17:49:46 +00:00
Ibraheem Ahmed
1d2c57a259
Run resolve/install benchmarks in ci (#3281)
## Summary

Runs resolver benchmarks in CI with CodSpeed.
2024-04-30 13:39:42 -04:00
Zanie Blue
100dbe475c
Quote version parse errors consistently (#3325) 2024-04-30 12:20:14 -05:00
konsti
d57af514d9
Centralize installed dist satisfies requirement check (#3324)
Another split out from https://github.com/astral-sh/uv/pull/3263. This
abstracts the copy&pasted check whether an installed distribution
satisfies a requirement used by both plan.rs and site_packages.rs into a
shared module. It's less useful here than with the new requirement but
helps with reducing https://github.com/astral-sh/uv/pull/3263 diff size.
2024-04-30 18:45:05 +02:00
konsti
66d750b2b9
Log which requirements were or weren't satisfied (#3319)
Previously, a noop `uv pip install` would only show "Audited {}
package(s)" but no details, not even with `-vv`. Now it debug logs which
requirements were met and it also debug logs which requirement was
missing to trigger the full routine, allowing it investigate caching
behaviour.

First `uv pip install -v jupyter`:

```
DEBUG At least one requirement is not satisfied: jupyter
```

Second `uv pip install -v jupyter`:

```
DEBUG Found a virtualenv named .venv at: /home/konsti/projects/uv-main/.venv
DEBUG Cached interpreter info for Python 3.12.1, skipping probing: .venv/bin/python
DEBUG Using Python 3.12.1 environment at .venv/bin/python
DEBUG Trying to lock if free: .venv/.lock
DEBUG Requirement satisfied: anyio
DEBUG Requirement satisfied: anyio>=3.1.0
DEBUG Requirement satisfied: argon2-cffi-bindings
DEBUG Requirement satisfied: argon2-cffi>=21.1
DEBUG Requirement satisfied: arrow>=0.15.0
DEBUG Requirement satisfied: asttokens>=2.1.0
DEBUG Requirement satisfied: async-lru>=1.0.0
DEBUG Requirement satisfied: attrs>=22.2.0
DEBUG Requirement satisfied: babel>=2.10
...
DEBUG Requirement satisfied: webencodings
DEBUG Requirement satisfied: webencodings>=0.4
DEBUG Requirement satisfied: websocket-client>=1.7
DEBUG Requirement satisfied: widgetsnbextension~=4.0.10
DEBUG All editables satisfied: 
Audited 1 package in 12ms
```

This will clash with the `tool.uv.sources` PR, i'll rebase it on top.
2024-04-30 15:39:41 +00:00
konsti
80ce32b3e9
Fix typos (#3323)
Split out from https://github.com/astral-sh/uv/pull/3263
2024-04-30 14:36:36 +00:00
Tim de Jager
9ae116f82b
fix: remove cache generic from builder (#3322)
Just a small fix, remove generic argument that I think was unused.
2024-04-30 08:27:55 -05:00
konsti
71fbd25a09
Refactor Dist constructors (#3320)
Split out from #3263. No functional changes.
2024-04-30 12:02:17 +02:00
Alexander Gherm
f77583e036
Add UV_NO_BUILD_ISOLATION as environment variable (#3318)
## Summary
Hi! Added `UV_NO_BUILD_ISOLATION` as a boolean environment variable for
the `--no-build-isolation` command-line option.

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

## Test Plan

Added new test `respect_no_build_isolation_env_var` to check that the
behaviour is the same as if the ``--no-build-isolation``
command-line-option is set.
2024-04-30 04:18:33 +00:00
Charlie Marsh
cf55c715f8
Expose --python as an environment variable (#3284)
## Summary

This was requested offline, and seems reasonable to me.
2024-04-30 03:32:40 +00:00
Ibraheem Ahmed
c5cd808876
Remove uncondtional serde usage in uv-resolver (#3317)
## Summary

Makes the `serde` implementations added in https://github.com/astral-sh/uv/pull/3314 conditional on uv-resolver's `serde` feature.
2024-04-29 16:31:37 -04:00
Andrew Gallant
d2e7c0554b
uv-resolver: add initial version of universal lock file format (#3314)
This is meant to be a base on which to build. There are some parts
which are implicitly incomplete and others which are explicitly
incomplete. The latter are indicated by TODO comments.

Here is a non-exhaustive list of incomplete things. In many cases, these
are incomplete simply because the data isn't present in a
`ResolutionGraph`. Future work will need to refactor our resolver so
that this data is correctly passed down.

* Not all wheels are included. Only the "selected" wheel for the current
  distribution is included.
* Marker expressions are always absent.
* We don't emit hashes for certainly kinds of distributions (direct
  URLs, git, and path).
* We don't capture git information from a dependency specification.
  Right now, we just always emit "default branch."

There are perhaps also other changes we might want to make to the format
of a more cosmetic nature. Right now, all arrays are encoded using
whatever the `toml` crate decides to do. But we might want to exert more
control over this. For example, by using inline tables or squashing more
things into strings (like I did for `Source` and `Hash`). I think the
main trade-off here is that table arrays are somewhat difficult to read
(especially without indentation), where as squashing things down into a
more condensed format potentially makes future compatible additions
harder.

I also went pretty light on the documentation here than what I would
normally do. That's primarily because I think this code is going to
go through some evolution and I didn't want to spend too much time
documenting something that is likely to change.

Finally, here's an example of the lock file format in TOML for the
`anyio` dependency. I generated it with the following command:

```
cargo run -p uv -- pip compile -p3.10 ~/astral/tmp/reqs/anyio.in --unstable-uv-lock-file
```

And that writes out a `uv.lock` file:

```toml
version = 1

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

[[distribution.wheel]]
url = "2f20c40b45/anyio-4.3.0-py3-none-any.whl"
hash = "sha256:048e05d0f6caeed70d731f3db756d35dcc1f35747c8c403364a8332c630441b8"

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

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

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

[[distribution.dependencies]]
name = "typing-extensions"
version = "4.11.0"
source = "registry+https://pypi.org/simple"

[[distribution]]
name = "exceptiongroup"
version = "1.2.1"
source = "registry+https://pypi.org/simple"

[[distribution.wheel]]
url = "79fe92dd41/exceptiongroup-1.2.1-py3-none-any.whl"
hash = "sha256:5258b9ed329c5bbdd31a309f53cbfb0b155341807f6ff7606a1e801a891b29ad"

[[distribution]]
name = "idna"
version = "3.7"
source = "registry+https://pypi.org/simple"

[[distribution.wheel]]
url = "741d8c8280/idna-3.7-py3-none-any.whl"
hash = "sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0"

[[distribution]]
name = "sniffio"
version = "1.3.1"
source = "registry+https://pypi.org/simple"

[[distribution.wheel]]
url = "75a9c94214/sniffio-1.3.1-py3-none-any.whl"
hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2"

[[distribution]]
name = "typing-extensions"
version = "4.11.0"
source = "registry+https://pypi.org/simple"

[[distribution.wheel]]
url = "936e209267/typing_extensions-4.11.0-py3-none-any.whl"
hash = "sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a"
```
2024-04-29 14:03:17 -04:00
Ahmed Ilyas
a3b61a2644
add UV_LINK_MODE as env variable (#3315)
Resolves https://github.com/astral-sh/uv/issues/3313

## Summary

Add a new env variable `UV_LINK_MODE` as alias for the cli argument
--link-mode.
Updated the README env variables section.

## Test Plan

Tested manually using `UV_LINK_MODE=hardlink cargo run -p uv pip install
flask`.
2024-04-29 17:29:36 +00:00
konsti
cedb8259f7
Avoid panic for file url (#3306)
When using find links with a file url, we shouldn't panic because we
can't remove username/password for a host-less url.

See #3262
2024-04-29 16:39:16 +02:00
konsti
1344cfae4b
Use fs_err for cachedir errors (#3304)
When running

```
set UV_CACHE_DIR=%LOCALAPPDATA%\uv\cache-foo && uv venv venv
```

in windows CMD, the error would be just

```
error: The system cannot find the path specified. (os error 3)
```

The problem is that the first action in the cache dir is adding the tag,
and the `cachedir` crate is using `std::fs` instead of `fs_err`. I've
copied the two functions we use from the crate and changed the import
from `std::fs` to `fs_err`.

The new error is

```
error: failed to open file `C:\Users\Konstantin\AppData\Local\uv\cache-foo \CACHEDIR.TAG`
  Caused by: The system cannot find the path specified. (os error 3)
```

which correctly explains the problem.

Closes #3280
2024-04-29 16:33:10 +02:00
renovate[bot]
22d8619c37
Update Rust crate data-encoding to v2.6.0 (#3302) 2024-04-29 09:31:59 -05:00
renovate[bot]
88f420e840
Update pre-commit dependencies (#3301) 2024-04-29 09:31:16 -05:00
renovate[bot]
f014bb60ce
Update Rust crate zip to v1.1.2 (#3300) 2024-04-29 09:31:06 -05:00
renovate[bot]
f5214a2f73
Update Rust crate unicode-width to v0.1.12 (#3299) 2024-04-29 09:30:35 -05:00
renovate[bot]
d66f5590f6
Update Rust crate serde to v1.0.199 (#3298) 2024-04-29 09:30:01 -05:00
renovate[bot]
e25dbd9cfb
Update Rust crate schemars to v0.8.17 (#3297) 2024-04-29 09:29:45 -05:00
renovate[bot]
4f8017a0c6
Update Rust crate mimalloc to v0.1.41 (#3296) 2024-04-29 09:29:32 -05:00
renovate[bot]
8f3bc97146
Update Rust crate async-compression to v0.4.9 (#3294) 2024-04-29 09:29:15 -05:00
renovate[bot]
af3be68be3
Update Rust crate flate2 to v1.0.30 (#3295) 2024-04-29 09:26:23 -05:00
konsti
f63a1fde42
Fix span recording with install_wheel_rs (#3293)
We would only record spans for `uv` prefixed crates, while the rayon
operations are in `install_wheel_rs`, therefore "disappearing" spans
from rayon.

With these changes, we can profile the parallel installation:


![jupyter](bb3c626a-ba9a-443d-9727-ac1e3bf14a71)
2024-04-28 18:33:40 +00:00
Charlie Marsh
eabefbf8a2
Ignore 401 errors with multiple indexes (#3292)
## Summary

It seems like Azure might return a 401 when you request a package that
doesn't exist (even with valid credentials)? But I admittedly haven't
tested this. (We already skip 403, and this seems similar?)

Closes https://github.com/astral-sh/uv/issues/3291.
2024-04-28 10:06:43 -04:00
Sergey Kolosov
748ed66a4d
Fix documentation on --index-strategy values (#3290)
## Summary

Dropped the `--` prefix from the values of the `--index-strategy` option
mistakenly added to documentation in #3138.

## Test Plan

Verified that actually accepted values of `--index-strategy` don't use a
`--` prefix.
2024-04-27 16:44:26 -04:00
Charlie Marsh
42a44dcfff
Fix serialization of index URLs (#3289)
Closes https://github.com/astral-sh/uv/issues/3288.
2024-04-27 12:52:06 +00:00
Charlie Marsh
028b407411
Bump version to v0.1.39 (#3286) 2024-04-27 07:18:16 -04:00
Charlie Marsh
da89e53090
Fix documentation on --cache-dir CLI (#3285)
## Summary

This looks like a copy-paste error.
2024-04-27 02:28:00 +00:00
Yorick
43181f1933
Implement --index-strategy unsafe-best-match (#3138)
## Summary

This index strategy resolves every package to the latest possible
version across indexes. If a version is in multiple indexes, the first
available index is selected.

Implements #3137 

This closely matches pip.

## Test Plan

Good question. I'm hesitant to use my certifi example here, since that
would inevitably break when torch removes this package. Please comment!
2024-04-27 01:24:54 +00:00
Charlie Marsh
a0e7d9fe87
Add a --isolated mode to ignore on-disk configuration (#3283)
## Summary

We have the same thing in Ruff. Really useful.
2024-04-26 23:33:34 +00:00
Charlie Marsh
845dc3d8d9
Add debug logging for --target (#3282) 2024-04-26 23:31:19 +00:00
konsti
2af80c28a8
Add apache airflow test case (#3278)
I like using airflow as a complex resolution test case. The second
requirement is the missing bound to enforce a successful resolution.
2024-04-26 14:17:09 +00:00
Charlie Marsh
ad99e3af63
Create --target directories lazily (#3274)
## Summary

Based on feedback in
https://github.com/astral-sh/uv/pull/3257#issuecomment-2078560574.
2024-04-26 03:36:56 +00:00
Charlie Marsh
1a4f7de831
Revise compile_index_url_fallback_prefer_primary (#3273)
## Summary

Closes https://github.com/astral-sh/uv/issues/3238.
2024-04-25 23:30:44 +00:00
Charlie Marsh
ed8f6e4556
Add --target support to sync and install (#3257)
## Summary

The approach taken here is to model `--target` as an install scheme in
which all the directories are just subdirectories of the `--target`.
From there, everything else... just works? Like, upgrade, uninstalls,
editables, etc. all "just work".

Closes #1517.
2024-04-25 19:15:39 -04:00
Charlie Marsh
71ffb2eabc
Build a separate ARM wheel for macOS (#3268)
## Summary

See: https://github.com/astral-sh/ruff/pull/11149
2024-04-25 19:13:27 -04:00
Grzegorz Bokota
fab8d858b6
fix platform_machine for macos arm (#3267)
## Summary

based on PEP 508 the `platform_machine` should be same as
`platform.machine()` output:
https://peps.python.org/pep-0508/#environment-markers

From my macOS M2 

```python
In [1]: import platform

In [2]: platform.machine()
Out[2]: 'arm64'
```

I napari we also use `arm64` in requirements and it works as expected: 

9fcf63e69a/pyproject.toml (L120)

## Test Plan

<!-- How was it tested? -->
2024-04-25 18:16:52 +00:00
Charlie Marsh
23bef9a691
Use macos-12 to build release wheels (#3264)
## Summary

GitHub has started to change `macos-latest` to `macos-14`. But
executables built on `macos-14` don't work on macOS 11 (see:
https://github.com/astral-sh/uv/issues/3261). This PR explicitly uses
`macos-12` instead (which is what we _intended_ to be using anyway).

Closes https://github.com/astral-sh/uv/issues/3261.
2024-04-25 12:07:30 -04:00
Charlie Marsh
413859768d
Replace Twisted with an empty bz2 package (#3258)
## Summary

This is just an empty package taken from packse, rezipped with `tar -cjf
bz2-1.0.0.tar.bz2 bz2-1.0.0`.
2024-04-25 03:45:23 +00:00