uv icon indicating copy to clipboard operation
uv copied to clipboard

Should `uv sync` remove extraneous packages?

Open ibraheemdev opened this issue 1 year ago • 5 comments

It currently does not, while uv pip sync does. This would also affect whether uv remove removes all extraneous packages, or has to do extra work to only remove the affected packages.

ibraheemdev avatar Jun 17 '24 15:06 ibraheemdev

In brief, I think we should:

  1. Change sync to always remove extraneous packages. This is the common understanding on sync.
  2. Implement an opt-out option for removal during sync, e.g. --allow-extra-packages
  3. Update uv remove to allow extraneous packages by default, only removing the relevant dependency tree

zanieb avatar Jun 17 '24 17:06 zanieb

uv sync now removes extraneous packages by default, which you can opt-out with --no-clean.

Currently uv add and uv run do not ever remove from the environment, and so uv remove should, for consistency, only remove the affected packages. An alternative approach to 3 is to have all project commands, uv run, uv add, and uv remove, always clean the virtual environment, which would simplify things and doesn't seem necessarily problematic.

ibraheemdev avatar Jun 19 '24 18:06 ibraheemdev

I don't think they should always clean the virtual environment. I think it's too common for people to manually manage packages in Python and without an explicit sync it seems excessive for us to purge extraneous packages. Changing remove to be more clearly scoped by default seems like a more intuitive user experience.

zanieb avatar Jun 19 '24 20:06 zanieb

Update uv remove to allow extraneous packages by default, only removing the relevant dependency tree

Does this mean: uv remove foo uninstalls foo, or uninstalls foo and its dependencies?

charliermarsh avatar Jun 23 '24 15:06 charliermarsh

My current vote is that it uses the same semantics as uv run, and we add an --exact argument to enable exact syncing. But I would also be okay shipping with the current behavior.

charliermarsh avatar Aug 10 '24 18:08 charliermarsh

I think it's too common for people to manually manage packages in Python and without an explicit sync it seems excessive for us to purge extraneous packages.

IIUC, uv's top level commands do some automations to keep your workspace in sync between lockfile, pyproject.toml and venv. I think who wants manually manage packages could use low level commands, i.e. uv pip uninstall in this case.

T-256 avatar Sep 19 '24 10:09 T-256

I think we made a decision on this — we have a toggle now.

zanieb avatar Sep 19 '24 11:09 zanieb

For anyone coming here after not finding the switch when looking at --help: It is called --inexact.

aberres avatar Oct 11 '24 12:10 aberres