Commit graph

2794 commits

Author SHA1 Message Date
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
Zanie Blue
d6c587c21c
Improve the uv python CLI documentation (#5961) 2024-08-09 14:46:21 -05:00
Zanie Blue
e6d76dbf35
Add hint for long help to uvx (#5971) 2024-08-09 18:24:38 +00:00
Charlie Marsh
f89403f4f6
Retain and respect settings in tool upgrades (#5937)
## Summary

We now persist the `ResolverInstallerOptions` when writing out a tool
receipt. When upgrading, we grab the saved options, and merge with the
command-line arguments and user-level filesystem settings (CLI > receipt
> filesystem).
2024-08-09 18:21:49 +00:00
Zanie Blue
4df0fe9a01
Update the interface for declaring Python download preferences (#5936)
The loose consensus is that "fetch" doesn't have much meaning and that a
boolean flag makes more sense from the command line.

1. Adds `--allow-python-downloads` (hidden, default) and
`--no-python-downloads` to the CLI to quickly enable or disable
downloads
2. Deprecates `--python-fetch` in favor of the options from (1)
3. Removes  `python-fetch` in favor of a `python-downloads` setting
5. Adds a `never` variant to the enum, allowing even explicit installs
to be disabled via the configuration file

## Test plan

I tested this with various `pyproject.toml`-level settings and `uv venv
--preview --python 3.12.2` and `uv python install 3.12.2` with and
without the new CLI flags.
2024-08-09 13:10:19 -05:00
konsti
a129cf7d7e
Warn when there are missing bounds on transitive deps in lowest (#5953)
Warn when there are missing bounds on transitive dependencies with
`--resolution lowest`.

Implemented as a lazy resolution graph check. Dev deps are odd because
they are missing the edge from the root that extras have (they are
currently orphans in the resolution graph), but this is more complex to
solve properly because we can put dev dep information in a `Requirement`
so i special cased them here.

Closes #2797
Should help with #1718

---------

Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2024-08-09 17:55:17 +00:00
Ibraheem Ahmed
ffd18cc75d
Implement marker trees using algebraic decision diagrams (#5898)
## Summary

This PR rewrites the `MarkerTree` type to use algebraic decision
diagrams (ADD). This has many benefits:
- The diagram is canonical for a given marker function. It is impossible
to create two functionally equivalent marker trees that don't refer to
the same underlying ADD. This also means that any trivially true or
unsatisfiable markers are represented by the same constants.
- The diagram can handle complex operations (conjunction/disjunction) in
polynomial time, as well as constant-time negation.
- The diagram can be converted to a simplified DNF form for user-facing
output.

The new representation gives us a lot more confidence in our marker
operations and simplification, which is proving to be very important
(see https://github.com/astral-sh/uv/pull/5733 and
https://github.com/astral-sh/uv/pull/5163).

Unfortunately, it is not easy to split this PR into multiple commits
because it is a large rewrite of the `marker` module. I'd suggest
reading through the `marker/algebra.rs`, `marker/simplify.rs`, and
`marker/tree.rs` files for the new implementation, as well as the
updated snapshots to verify how the new simplification rules work in
practice. However, a few other things were changed:
- [We now use release-only comparisons for `python_full_version`, where
we previously only did for
`python_version`](https://github.com/astral-sh/uv/blob/ibraheem/canonical-markers/crates/pep508-rs/src/marker/algebra.rs#L522).
I'm unsure how marker operations should work in the presence of
pre-release versions if we decide that this is incorrect.
- [Meaningless marker expressions are now
ignored](https://github.com/astral-sh/uv/blob/ibraheem/canonical-markers/crates/pep508-rs/src/marker/parse.rs#L502).
This means that a marker such as `'x' == 'x'` will always evaluate to
`true` (as if the expression did not exist), whereas we previously
treated this as always `false`. It's negation however, remains `false`.
- [Unsatisfiable markers are written as `python_version <
'0'`](https://github.com/astral-sh/uv/blob/ibraheem/canonical-markers/crates/pep508-rs/src/marker/tree.rs#L1329).
- The `PubGrubSpecifier` type has been moved to the new `uv-pubgrub`
crate, shared by `pep508-rs` and `uv-resolver`. `pep508-rs` also depends
on the `pubgrub` crate for the `Range` type, we probably want to move
`pubgrub::Range` into a separate crate to break this, but I don't think
that should block this PR (cc @konstin).

There is still some remaining work here that I decided to leave for now
for the sake of unblocking some of the related work on the resolver.
- We still use `Option<MarkerTree>` throughout uv, which is unnecessary
now that `MarkerTree::TRUE` is canonical.
- The `MarkerTree` type is now interned globally and can potentially
implement `Copy`. However, it's unclear if we want to add more
information to marker trees that would make it `!Copy`. For example, we
may wish to attach extra and requires-python environment information to
avoid simplifying after construction.
- We don't currently combine `python_full_version` and `python_version`
markers.
- I also have not spent too much time investigating performance and
there is probably some low-hanging fruit. Many of the test cases I did
run actually saw large performance improvements due to the markers being
simplified internally, reducing the stress on the old `normalize`
routine, especially for the extremely large markers seen in
`transformers` and other projects.

Resolves https://github.com/astral-sh/uv/issues/5660,
https://github.com/astral-sh/uv/issues/5179.
2024-08-09 13:40:02 -04:00
Zanie Blue
3228fc5f35
Improve the uv venv CLI documentation (#5963)
This was actually in pretty good shape already!
2024-08-09 12:15:22 -05:00
Ibraheem Ahmed
ddb82a01c8
Add basic universal benchmarks to CI (#5938)
## Summary

Resolves https://github.com/astral-sh/uv/issues/4921.
2024-08-09 12:52:28 -04:00
Zanie Blue
7fdb878fd0
Display portable paths in posix venv activation commands (#5956)
Closes #5950
2024-08-09 11:28:00 -05:00
Zanie Blue
4330f9718b
Improve the uv lock CLI documentation (#5932) 2024-08-09 08:51:03 -05:00
Charlie Marsh
cac1e7bcfc
Add update alias for uv tool upgrade (#5948)
## Summary

I always get this wrong with `brew`, it'd be nice for it to "just work"
either way.
2024-08-09 09:37:03 -04:00
konsti
eed23be1bd
Discard forks when using --upgrade (#5905)
Fixes #5817

Needs https://github.com/astral-sh/packse/pull/213 for the test to pass.
2024-08-09 09:13:38 +00:00
konsti
1e6b021506
Update packse to 0.3.34 (#5954)
Preparation for #5905
2024-08-09 09:04:17 +00:00
Chan Kang
441d57fa29
use exclude newer env var instead of the flag (#5946)
## Summary
resolves https://github.com/astral-sh/uv/issues/5879
<!-- What's the purpose of the change? What does it do, and why? -->
2024-08-09 09:53:06 +02:00
Charlie Marsh
21408c1f35
Enforce extension validity at parse time (#5888)
## Summary

This PR adds a `DistExtension` field to some of our distribution types,
which requires that we validate that the file type is known and
supported when parsing (rather than when attempting to unzip). It
removes a bunch of extension parsing from the code too, in favor of
doing it once upfront.

Closes https://github.com/astral-sh/uv/issues/5858.
2024-08-08 21:39:47 -04:00
Charlie Marsh
ba7c09edd0
Respect subdirectories when locating Git workspaces (#5944)
## Summary

We were discovering the workspace from the Git repository root, so
attempting to build any subdirectories would fail.

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

## Test Plan

```
cargo run pip install \
	git+https://github.com/flyteorg/flytekit.git@master#subdirectory=plugins/flytekit-flyteinteractive
```
2024-08-08 20:13:17 -04:00
Charlie Marsh
fd1d508108
Make --upgrade imply --refresh (#5943)
## Summary

I think this seems reasonable... Otherwise, we might not go back to PyPI
to revalidate the list of available versions despite the user passing
`--upgrade`.
2024-08-08 20:11:31 -04:00
Charlie Marsh
3701b60f61
Respect --upgrade-package in tool install (#5941)
## Summary

`--upgrade-package` is useful as you can set a constraint. `--upgrade`
will just warn for now.
2024-08-08 19:22:14 -04:00
Charlie Marsh
a5ccc3288c
Add conversion to fill default settings (#5933)
## Summary

This paves the way for some future work around the installer receipt. No
behavior changes intended.
2024-08-08 21:05:38 +00:00
Charlie Marsh
88ece8b791
Search beyond workspace root when discovering configuration (#5931)
## Summary

Previously, we wouldn't respect configuration files in directories
_above_ a workspace root. But this is somewhat problematic, because any
`pyproject.toml` will define a workspace root...

Instead, I think we should _start_ the search at the workspace root, but
go above it if necessary.

Closes: #5929.

See: https://github.com/astral-sh/uv/pull/4295.
2024-08-08 17:05:02 -04:00
Ahmed Ilyas
cbc3274848
Add uv tool upgrade command (#5197)
## Summary

Resolves #5188. Most of the changes involve creating a new function in
`tool/common.rs` to contain the common functionality previously found in
`tool/install.rs`.

## Test Plan

`cargo test`

```console
❯ ./target/debug/uv tool upgrade black
warning: `uv tool upgrade` is experimental and may change without warning.
Resolved 6 packages in 25ms
Uninstalled 1 package in 3ms
Installed 1 package in 19ms
 - black==23.1.0
 + black==24.4.2
Installed 2 executables: black, blackd
```
2024-08-08 16:48:14 -04:00
Zanie Blue
bf0497e652
Add CLI flags to reference documentation (#5926)
Oopsies, options are only arguments that take values in Clap-land

Closes https://github.com/astral-sh/uv/issues/5924
2024-08-08 18:51:27 +00:00
Zanie Blue
0d21ff8b5f
Deprecate --system and --no-system in uv venv (#5925)
e.g.

```
❯ cargo run -- venv --no-system
    Blocking waiting for file lock on build directory
   Compiling uv v0.2.34 (/Users/zb/workspace/uv/crates/uv)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 19.85s
     Running `target/debug/uv venv --no-system`
warning: The `--no-system` flag has no effect, a system Python interpreter is always used in `uv venv`
Using Python 3.12.4 interpreter at: /opt/homebrew/opt/python@3.12/bin/python3.12
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate

❯ cargo run -- venv --system
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/uv venv --system`
warning: The `--system` flag has no effect, a system Python interpreter is always used in `uv venv`
Using Python 3.12.4 interpreter at: /opt/homebrew/opt/python@3.12/bin/python3.12
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate
```
2024-08-08 18:32:00 +00:00
Charlie Marsh
dd1bcf8ab9
Ignore local configuration in tool commands (#5923)
## Summary

If you're running a user-level command, we shouldn't respect the local
`pyproject.toml` or `uv.toml`.
2024-08-08 14:25:12 -04:00
Zanie Blue
f4576fe4a7
Improve the uv tree CLI documentation (#5917)
Some small follow-ups.
2024-08-08 18:21:46 +00:00
Zanie Blue
d2681320d3
Improve the CLI documentation for uv remove (#5916)
Also, renames a `requirements` variable to `packages` for clarity and
fixes the definition of `frozen` for `uv add`.
2024-08-08 13:12:49 -05:00