Commit graph

3176 commits

Author SHA1 Message Date
Charlie Marsh
4f2349119c
Add support for dynamic cache keys (#7136)
## Summary

This PR adds a more flexible cache invalidation abstraction for uv, and
uses that new abstraction to improve support for dynamic metadata.

Specifically, instead of relying solely on a timestamp, we now pass
around a `CacheInfo` struct which (as of now) contains
`Option<Timestamp>` and `Option<Commit>`. The `CacheInfo` is saved in
`dist-info` as `uv_cache.json`, so we can test already-installed
distributions for cache validity (along with testing _cached_
distributions for cache validity).

Beyond the defaults (`pyproject.toml`, `setup.py`, and `setup.cfg`
changes), users can also specify additional cache keys, and it's easy
for us to extend support in the future. Right now, cache keys can either
be instructions to include the current commit (for `setuptools_scm` and
similar) or file paths (for `hatch-requirements-txt` and similar):

```toml
[tool.uv]
cache-keys = [{ file = "requirements.txt" }, { git = true }]
```

This change should be fully backwards compatible.

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

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

Closes https://github.com/astral-sh/uv/issues/6860.
2024-09-09 20:19:15 +00:00
Charlie Marsh
9a7262c360
Avoid batch prefetching for un-optimized registries (#7226)
## Summary

We now track the discovered `IndexCapabilities` for each `IndexUrl`. If
we learn that an index doesn't support range requests, we avoid doing
any batch prefetching.

Closes https://github.com/astral-sh/uv/issues/7221.
2024-09-09 15:46:19 -04:00
Charlie Marsh
970bd1aa0c
Respect exclusion when collecting workspace members (#7175)
## Summary

We were only applying exclusions when discovering the root, apparently.

Our logic now matches the original intent, which is...

- `exclude` always post-filters `members`.
- We don't treat globs any differently than non-globs.

The one confusing setup that falls out of this is that given:

```toml
members = ["foo/bar/baz"]
exclude = ["foo/bar"]
```

`foo/bar/baz` **would** be included. To exclude it, you would need:

```toml
members = ["foo/bar/baz"]
exclude = ["foo/bar/*"]
```

Closes https://github.com/astral-sh/uv/issues/7071.
2024-09-09 12:08:06 -04:00
Charlie Marsh
d9cd2829fa
Fix typo in name normalization (#7217) 2024-09-09 14:29:28 +00:00
Charlie Marsh
dcbaa1f486
Avoid iteration for singleton selections (#7195)
## Summary

If we have a singleton `Range`, we don't need to iterate over the map of
available ranges; instead, we can just get the singleton directly.

Closes #6131.
2024-09-09 13:43:57 +00:00
Charlie Marsh
dafa3596c5
Avoid distribution clones in requirements.txt graph (#7210) 2024-09-09 13:31:13 +00:00
Charlie Marsh
b738b35910
Prune unreachable packages from --universal output (#7209)
## Summary

Closes https://github.com/astral-sh/uv/issues/7196.
2024-09-09 09:20:25 -04:00
bluss
fdde92b539
Use path file instead of sitecustomize.py (#7161)
## Summary

Use a path file (`.pth`) instead of `sitecustomize.py` for configuring
path in emphemeral virtualenvs, overlaying the ephemeral venv on top of
the base `.venv`.

`sitecustomize.py` is a module in the python installation and as such a
unique resource - homebrew pythons on macos already install such a file
and thus uv's `sitecustomize.py`, placed in the ephemeral env, did not
have any effect.

I don't find any documentation explicitly saying that addsitedir is
valid in `.pth` files but from trial it seems to be - and there is the
precedent of the existing _virtualenv.pth _virtualenv.py pair that do
nontrivial operations.

## Test Plan

- Testing on ephemeral venv, resolving to base venv including editable
install in base: done (py3.7, 3.12)
- Testing on homebrew python/macos: done (py3.11)
- tests: run_editable

Fixes #7152
2024-09-09 09:19:55 -04:00
Charlie Marsh
947619657c
Allow .dist-info names with dashes for post releases (#7208)
## Summary

Closes https://github.com/astral-sh/uv/issues/7155.
2024-09-09 09:12:53 -04:00
Soof Golan
14ebc393fc
treat .tgz the same as .tar.gz (#7201)
## Summary

Fixes #7081 

Treats source distribution `.tgz` the same as `.tar.gz` plans

## Test Plan

Quick Version

```bash
cd $(mktemp -d)
uv init
uv add --dev build
.venv/bin/python -m build -s .
mv -v dist/*tar.gz dist/"$(basename dist/*.tar.gz .tar.gz)".tgz
uv pip install dist/*.tgz
```

Can add a proper test to the branch if requested
2024-09-08 23:09:39 +00:00
Charlie Marsh
64e03ad56c
Direct users towards uv venv to create a virtual environment (#7188)
## Summary

Closes https://github.com/astral-sh/uv/issues/7123.
2024-09-08 22:33:34 +00:00
Shantanu
022e41327a
Improve error message for uv init already init-ed (#7198)
Someone in
1282411049
found this confusing

Could maybe improve further, e.g. what the user should do next might
depend if there are [project] or [tool.uv] sections

---------

Co-authored-by: Charlie Marsh <crmarsh416@gmail.com>
2024-09-08 18:28:27 -04:00
Charlie Marsh
4466402214
DRY up exclusion checks in selector (#7194) 2024-09-08 17:42:41 +00:00
Charlie Marsh
f11eebd735
Bump Rust toolchain to 1.81 (#7187) 2024-09-08 15:09:49 +00:00
konsti
aca01f80ef
Clearer registry Python sort (#7178)
Change the registry Python sorting implementation to be easier to
follow, making it clearer what it does and that it is a total order. No
functional changes.
2024-09-07 15:57:01 -04:00
Mathieu Kniewallner
8341d810b2
docs: list supported sdist formats (#7168)
## Summary

Explicitly list the formats and extensions that uv supports, based on
[this
list](86ee8d2c01/crates/distribution-filename/src/extension.rs (L70-L77)).
Not a huge fan of adding the section in `concepts/resolution.md`, but I
did not find a better place. Alternatively we could maybe add a
dedicated page that shortly explains Python package types (wheels,
sdists), where such a section could live?

## Test Plan

Local run of the documentation.
2024-09-07 19:16:12 +00:00
Charlie Marsh
e8a26a43f5
Avoid extra newlines in debug logging for source builds (#7174)
## Summary

@henryiii brought this up and I noticed it too:

![Screenshot 2024-09-06 at 4 09
32 PM](https://github.com/user-attachments/assets/a2849a0e-0515-4856-a9fe-14c713ed9b75)

## Test Plan

`uv build`:

![Screenshot 2024-09-07 at 2 08
39 PM](https://github.com/user-attachments/assets/841db9b7-1fd1-4964-aa57-58b479a255ff)

`uv pip install -e . --verbose`:

![Screenshot 2024-09-07 at 2 08
52 PM](https://github.com/user-attachments/assets/30b2817a-d4a3-4437-b47d-2bc037f5afa4)
2024-09-07 14:34:00 -04:00
Andrew Gallant
f6bc701ac3 uv-resolver: use new simplify/complexify marker routines
This finally gets rid of our hack for working around "hidden"
state. We no longer do a roundtrip marker serialization and
deserialization just to avoid the hidden state.
2024-09-07 13:46:02 -04:00
Andrew Gallant
2c139d6fca pep508: implement marker simplification/complexification
This adds new routines to `MarkerTree` for "simplifying" and
"complexifying" a tree with respect to lower and upper Python version
bounds.

In effect, "simplifying" a marker is what you do when you write it to a
lock file. Namely, since `uv.lock` includes a `requires-python` bound at
the top, one can say that it acts as a bound on the supported Python
versions. That is, it establishes a context in which one can assume that
bound is true. Therefore, the markers we write can be simplified using
this assumption.

The reverse is "complexifying" a marker, and it's what you do when you
read a marker from the lock file. Namely, once a marker is read, it can
be very difficult in code to keep the corresponding requires-python
context from the lock file. If you lose track of it and decide to
operate on the "simplified" marker, then it's trivial for that to
produce an incorrect result.
2024-09-07 13:46:02 -04:00
Andrew Gallant
8bb0a55ff5 pep508: remove hidden state from MarkerTree
I split this change into its own commit because I'm hoping it
crystalizes what it means when we say "a `MarkerTree` has hidden state."
That is, it isn't so much that there is some explicit member of a
`MarkerTree` that is omitted, but rather, the lower and upper version
bounds on `python_full_version` are are rewritten as "unbounded" when
traversing the ADD for display.

We will actually retain this functionality, but rejigger it so that it's
explicit when we do this. In particular, this simplification has been
problematic for us because it fundamentally changes the truth tables of
a marker expression *unless* you are extremely careful to interpret it
only under the original context in which it was simplified. This is
quite difficult to do generally, and in prior work in #6268, we
completed a refactor where we worked around this type of simplification
and moved it to the edges of uv.

In subsequent commits, we'll re-implement this form of simplification as
a more explicit step.
2024-09-07 13:46:02 -04:00
Charlie Marsh
a3e9610a54
Add build isolation logging to build operations (#7169)
## Summary

Closes https://github.com/astral-sh/uv/issues/7154.
2024-09-07 14:32:25 +00:00
Charlie Marsh
a178051e81
Bump version to v0.4.7 (#7150) 2024-09-07 02:18:15 +00:00
Charlie Marsh
6179b65e37
Avoid removing entries during read_dir (#7151)
I think this is the source of the test flakiness.
2024-09-07 02:10:28 +00:00
Charlie Marsh
7d49fbc753
Skip metadata fetch for --no-deps and pip sync (#7127)
## Summary

I think a better tradeoff here is to skip fetching metadata, even though
we can't validate the extras.

It will help with situations like
https://github.com/astral-sh/uv/issues/5073#issuecomment-2334235588 in
which, otherwise, we have to download the wheels twice.
2024-09-06 21:26:28 -04:00
Janosh Riebesell
e96eb946f9
Fix typo aaarch64->aarch64 (#7141)
copy pasted `--python-platform aaarch64-unknown-linux-gnu` [from the
docs](https://docs.astral.sh/uv/reference/cli/#uv-pip-compile) and got

> error: invalid value 'aaarch64-unknown-linux-gnu' for
'--python-platform <PYTHON_PLATFORM>'
> [possible values: windows, linux, macos, x86_64-pc-windows-msvc,
i686-pc-windows-msvc, x86_64-unknown-linux-gnu, aarch64-apple-darwin,
x86_64-apple-darwin, aarch64-unknown-linux-gnu,
aarch64-unknown-linux-musl, x86_64-unknown-linux-musl,
x86_64-manylinux_2_17, x86_64-manylinux_2_28, x86_64-manylinux_2_31,
aarch64-manylinux_2_17, aarch64-manylinux_2_28, aarch64-manylinux_2_31]
> 
>   tip: a similar value exists: 'aarch64-unknown-linux-gnu'
2024-09-06 23:25:46 +00:00
Zanie Blue
8eff8aab0b
Avoid panicking when encountering an invalid Python version during uv python list (#7131)
Closes https://github.com/astral-sh/uv/issues/7129

Not entirely sure about the best approach yet.
2024-09-06 19:23:16 -04:00
Charlie Marsh
8a0e1fde33
Write trailing newline to .python-version files (#7140)
## Summary

Closes https://github.com/astral-sh/uv/issues/7135.
2024-09-06 18:03:52 -04:00
Amos Wenger
5e1b9b1964
chore: Remove dep on derivative (#7133)
(This is part of #5711)

## Summary

@BurntSushi and I spotted that the `derivative` crate is only used for
one enum in the entire codebase — however, it's a proc macro, and we pay
for the cost of (re)compiling it in many different contexts.

This replaces it with a private `Inner` core which uses the regular std
derive macros — inlining and optimizations should make this equivalent
to the other implementation, and not too hard to maintain hopefully
(versus a manual impl of `PartialEq` and `Hash` which have to be kept in
sync.)

## Test Plan

Trust CI?
2024-09-06 17:46:56 -04:00
Ibraheem Ahmed
22c0be6664 pep508: add graph debug representation for MarkerTree
This PR revives #6129, but is less bold:

* It doesn't rename anything. (I think the rename is probably right
  though.)
* It doesn't change the _default_ `Debug` impl. Instead, it offers this
  as a new `MarkerTree::debug_graph` method.

I found this pretty useful for debugging since it gives a display format
that is more faithful to the internal representation of a `MarkerTree`.
So I think it's worth having around. But making it available in `Debug`
is perhaps a bridge too far since it isn't as familiar as the typical
PEP 508 representation and isn't as succinct.

I did consider printing this when using `{:#?}` (i.e., the "alternate"
debug representation), but too many things use that (like `insta` I
think) to make it practical.

Closes #6129
2024-09-06 16:47:51 -04:00
Charlie Marsh
72b73a506b
Add distinctive logging for cache prune phases (#7114) 2024-09-05 23:09:29 -04:00
Charlie Marsh
93fe3e83be
Prune unused source distributions from the cache (#7112)
## Summary

This has bothered me for a while and should be fairly impactful for
users. It requires a weird implementation, since the
distribution-building crate depends on the cache, and so the prune
operation can't live in the cache, since it needs to access internals of
the distribution-building crate.

Closes https://github.com/astral-sh/uv/issues/7096.
2024-09-05 21:40:51 -04:00
Zanie Blue
1422e18674
Fixup comment for export --output-file (#7111) 2024-09-05 20:18:39 -05:00
Charlie Marsh
6ae005b0d0
Add --no-emit-project and friends to uv export (#7110)
## Summary

Like `uv sync`, you can omit the current project (`--no-emit-project`),
a specific package (`--no-emit-package`), or the entire workspace
(`--no-emit-workspace`).

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

Closes #6995.
2024-09-06 01:01:46 +00:00
Charlie Marsh
d0f9016eda
Add --output-file to uv export (#7109)
## Summary

Closes https://github.com/astral-sh/uv/issues/7058.
2024-09-05 20:53:53 -04:00
Charlie Marsh
c494f6912c
Take intersection of constraint and requirements hashes (#7108)
## Summary

Small follow-up to #7093.
2024-09-05 20:22:34 -04:00
Zanie Blue
84f25e8cf8
Bump version to 0.4.6 (#7103) 2024-09-05 17:39:53 -05:00
Charlie Marsh
58b25b560c
Invalidate lockfile when member versions change (#7102)
## Summary

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

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-09-05 17:14:57 -05:00
Charlie Marsh
29f53c3c63
Support --no-build and --no-binary in uv sync et al (#7100)
## Summary

This option already existed, but `--no-binary` always errored.

Closes https://github.com/astral-sh/uv/issues/7099.
2024-09-05 21:45:42 +00:00
Charlie Marsh
f2309bfd1e
Remove timestamp exact vs. approximate enum (#7098) 2024-09-05 20:49:20 +00:00
Charlie Marsh
5b89734c85
Add --require-hashes and --verify-hashes to uv build (#7094) 2024-09-05 15:22:03 -04:00
Charlie Marsh
80f51cee06
Accept --build-constraints in uv build (#7085)
## Summary

Closes #7082.

Closes #7065.
2024-09-05 18:46:36 +00:00
Charlie Marsh
bb61513952
Respect hashes in constraints files (#7093)
## Summary

Like pip, if hashes are present on both the requirement and the
constraint, we prefer the requirement.

Closes #7089.
2024-09-05 14:30:10 -04:00
konsti
750e8b1e2f
Remove propagate_markers (#7076)
Follow-up to #6959 and #6961: Use the reachability computation instead
of `propagate_markers` everywhere.

With `marker_reachability`, we have a function that computes for each
node the markers under which it is (`requirements.txt`, no markers
provided on installation) or can be (`uv.lock`, depending on the markers
provided on installation) included in the installation. Put differently:
If the marker computed by `marker_reachability` is not fulfilled for the
current platform, the package is never required on the current platform.

We compute the markers for each package in the graph, this includes the
virtual extra packages and the base packages. Since we know that each
virtual extra package depends on its base package (`foo[bar]` implied
`foo`), we only retain the base package marker in the `requirements.txt`
graph.

In #6959/#6961 we were only using it for pruning packages in `uv.lock`,
now we're also using it for the markers in `requirements.txt`.

I think this closes #4645, CC @bluss.
2024-09-05 16:52:21 +00:00
konsti
d5eb6eb12c
Move reachability function (#7091)
Split out from #7076
2024-09-05 16:44:21 +00:00
Charlie Marsh
d91f7ddf5f
Don't include registry hashes for URL distributions (#7086)
The opposite _can_ be true.
2024-09-05 11:42:07 -04:00
Ahmed Ilyas
567e213cbb
Accept vec of packages in uv tool uninstall (#7077)
## Summary

Follow up
https://github.com/astral-sh/uv/pull/7037#discussion_r1744515370

## Test Plan

`cargo test`
2024-09-05 08:24:13 -04:00
konsti
316f683071
Update packse (#7002)
Add additional tests for https://github.com/astral-sh/uv/pull/6959 and
https://github.com/astral-sh/uv/pull/6961
2024-09-05 08:14:34 +00:00
Alex Gaynor
6648a9b940
fix inverted log message (#7063) 2024-09-05 02:42:08 +00:00
eth3lbert
e7a7a813fb
Implement --show-version-specifiers for tool list (#7050)
## Summary

Closes #6747 .

## Test Plan

```
cargo test --test tool_list
```
2024-09-05 02:15:18 +00:00
Charlie Marsh
a20fecedaa
Strip fragments from direct source URLs in lockfile (#7061)
## Summary

In resolving https://github.com/astral-sh/uv/issues/7059, I noticed that
we left the fragment on the `source = { url = "..." }`.
2024-09-05 02:05:39 +00:00