pypa / pipx

Install and Run Python Applications in Isolated Environments
https://pipx.pypa.io
MIT License
9.94k stars 399 forks source link

BUG: pipx upgrade doesn't understand extra dependencies #925

Open neutrinoceros opened 1 year ago

neutrinoceros commented 1 year ago

Describe the bug

This works correctly

pipx install "mycli[extras]"

but this doesn't

pipx install "mycli[extras]"
pipx upgrade "mycli[extras]"

and it fails with

Package is not installed. Expected to find /path/to/pipx/venvs/mycli[isolated], but it does not exist.

How to reproduce For reproduction, I suggest

pipx install "coverage[toml]"
pipx upgrade "coverage[toml]"

Expected behavior I'm not 100% sure what should happen actually, but the current error message seems broken (of course a directory with [ and ] in its name wasn't found). I think the upgrade should go through wether or not the extra targets match the ones I used (or didn't use) the first time I installed the CLI (here coverage).

I'd be happy to contribute a patch, but I'd appreciate some guidance regarding what the expected behaviour should be.

dukecat0 commented 1 year ago

You can simply run pipx upgrade mycli and you don't need to pass extra dependencies since it's installed. But I think we can improve the error message to make it more clearly.

uranusjr commented 1 year ago

Does pipx upgrade mycli upgrade dependencies that are only pulled in by the extra? I’m under the impression it only tries to upgrade the specified package (i.e. mycli here); if so we would actually need to add some additional logic for the extra-ed case.

dukecat0 commented 1 year ago

Does pipx upgrade mycli upgrade dependencies that are only pulled in by the extra?

Not really, unless --pip-args='--upgrade-strategy eager' is passed. This is probably related to #254.

uranusjr commented 1 year ago

Even if we change the strategy, dependencies in the extra would still not be upgraded (because from pip’s perspective those packages are unrelated unless you pass in the extra). So for now pipx upgrade does not have a difference in behaviour whether you pass in the extra or not, but would if we change the default upgrade strategy. I’d say the current behaviour is OK (barring a better error message), but we should probably change the strategy (or have a flag to control it), which would requite us to also fix how extras are passed to upgrade.

gaborbernat commented 8 months ago

PR welcome.

layday commented 5 months ago

[...] which would requite us to also fix how extras are passed to upgrade.

This might've been fixed since? It looks like if I pipx install nox[uv] then pipx upgrade nox correctly issues pip --no-input install --upgrade nox[uv]. Therefore, the only change required is to pass --upgrade-strategy=eager.

cjolowicz commented 5 months ago

What should pipx do if the main app's version didn't change? Should it still upgrade dependencies?

(IMO it should. This will let users benefit from bugfixes and security updates to the app's dependency tree. It will also help with the more exotic case of nox[uv] where uv has a much faster release cycle than Nox.)