pypa / pipx

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

Proposal: Add `--upgrade` argument for install command #1458

Closed jdknight closed 1 week ago

jdknight commented 2 weeks ago

Proposal

The following is a proposal to support an upgrade option with pipx's install command. A practice I use for documenting various Python-based utilities is to have an installation section which has a single command to either install or upgrade a package:

pip install -U example

Now trying to promote the use of pipx over pip, this does not seem to be possible in a single command unless using the --force argument:

pipx install --force example

Using the "force" argument does not feel right, and the intention is not to have packages be re-installed if they are already in a good/upgraded state. Alternatively, I could update documentation to have two paragraphs to identify a method to install and a method to upgrade, but I would rather promote a single command that could do both.

Summary of changes

When installing a package, both pip install and pipx install allow a new package to be installed. If a target package is already installed, no changes are made. Both pip and pipx also support a forced reinstall using --force-reinstall and --force respectively. Another popular installation more for pip is using the --upgrade option, which will only perform a package change if a new version is detected. Such a request is not possible in pipx.

This commit adds support for an upgrade method by adding the --upgrade option and forwarding it to pip when a package has been detected as already installed.

Test plan

Tested by provided unit tests and running:

pipx install black==22.8.0
pipx install black
pipx install --upgrade black
Example output
(venv) [jdknight@devel venv]$ pipx install black==22.8.0
  installed package black 22.8.0, installed using Python 3.12.4
  These apps are now globally available
    - black
    - blackd
done!
(venv) [jdknight@devel venv]$ pipx install black
'black' already seems to be installed. Not modifying existing installation in '.../.local/share/pipx/venvs/black'. Pass '--force' to
force installation.
(venv) [jdknight@devel venv]$ pipx install --upgrade black
  installed package black 24.4.2, installed using Python 3.12.4
  These apps are now globally available
    - black
    - blackd
done!
chrysle commented 2 weeks ago

Thanks, but this has already been proposed once (#953) and we agreed elsewhere on an --install option to the --upgrade command.