astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
24.45k stars 708 forks source link

Remember previous lock options when running `uv sync` #6001

Open nikhilweee opened 2 months ago

nikhilweee commented 2 months ago

Problem Description

uv sync, by itself, does not install optional dependencies. Which is fine, I believe it's how it should be.

But let's say I am running uv sync for the first time. I wish to include two extras, extra1 and extra2. I run the following:

uv sync --extra extra1 --extra extra2

Great. Now I have the package with extras installed. But what about subsequent syncs?

Suggestion

One argument is to remember the two extras (and other lock options) from before, and use them as the new defaults. In other words, subsequent syncs should imply --extra extra1 --extra extra2. If an extra argument is provided explicitly during sync, these new extras should override the defaults. I believe this is how it currently works in rye and pdm. Those tools store lock options in their lockfiles.

The PDM lockfile has a metadata section which stores these implicit extras

[metadata]
groups = ["extra1", "extra2"]

Similarly, Rye stores these implicit extras in its lockfile

# last locked with the following flags:
#   features: ["extra1", "extra2"]

AFAIK I don't think UV stores lock options in its lockfile. Should we think about remembering previous lock options?

Related

I am aware that that PEP-751 is under discussion and from a brief glance I'm not sure if package managers will be able to store any kind of metadata in there. That said, it's still a draft and maybe we can bring this up.

zanieb commented 2 months ago

The discussion at https://github.com/astral-sh/uv/issues/4730 may be helpful

nikhilweee commented 2 months ago

Thanks for the pointer @zanieb, I think the following comment comes close to capturing the gist of this issue.

https://github.com/astral-sh/uv/issues/4730#issuecomment-2203338364

The huge drawback here: Modulo default-{packages,extras,command}, you have to specify all arguments in every uv run every time.

I'd also like to add that remembering lockfile options would make it easy for users switching from other package managers.

charliermarsh commented 2 months ago

To clarify one thing, the extras have no impact on the lockfile -- we lock for all extras at once. uv lock doesn't even accept extras as an argument :) The extras only impact the installation phase (which subset of packages should we install), not the locking phase (which packages should we include when resolving). This is different from Rye which can't produce a lockfile that supports switching out extras at install-time, so has to encode them like that.

nikhilweee commented 2 months ago

Ah, sorry my understanding of uv internals is not the best. That said, the spirit of this issue is to remember previous lock options when running uv install. If this is something of interest, I'm sure the implementation details can be discussed further.