astral-sh / uv

An extremely fast Python package installer and resolver, written in Rust.
https://astral.sh/
Apache License 2.0
14.72k stars 419 forks source link

`uv run` should only resolve when lockfile is out-of-sync #3892

Open charliermarsh opened 1 month ago

charliermarsh commented 1 month ago

As long as the lockfile satisfies the requirements, we should accept it (even if dependencies are outdated). Updating the lockfile should be done via uv update or uv lock or comparable.

charliermarsh commented 4 weeks ago

I'm looking into this now.

charliermarsh commented 4 weeks ago

There are two parts to this:

  1. Statically extracting the requirements for the workspace.
  2. Comparing the extracted requirements to the lockfile.

I am working on (1). It's not totally trivial, we currently defer that extraction to the resolver.

There are several things that make (2) hard:

  1. The markers might've been normalized when writing to the lockfile, so they may not match the requirements as defined by the user. We could also have multiple requirements from (1) that map to a single requirement in (2), if it's (e.g.) a single requirement repeated with different markers (which would get OR'd when writing to the lockfile).
  2. We have to check workspace dependencies recursively.
  3. We need to ensure that there are no entries in the lockfile that no longer exist as requirements -- otherwise, we'll install too many packages. So it's not just checking that each requirement is present; we also need to check that nothing is present that isn't a requirement. We need to be able to map from requirement to lock entry, but also the other way around.
charliermarsh commented 3 weeks ago

@ibraheemdev and I discussed this in Discord. A summary:

charliermarsh commented 3 weeks ago

There's something confusing in https://github.com/astral-sh/uv/issues/3925 though... In the lockfile, we don't actually store the version constraints, we just store the locked version. That might be fine? But if we translate that back to a requirement, we will have to translate to an == requirement. I haven't thought through the implications of that.

konstin commented 9 hours ago

To add more motivation here: When running uv lock transformers with all extras with a fitting lock, we take 100ms on main, but 60ms with https://github.com/astral-sh/uv/pull/4495.

One thing we lose by doing this is the check for yanked releases, those versions that are part of the lock file but have yanked since.