pypa / pipx

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

`pipx upgrade foo` ignores and overwrites pip args used during install #1441

Open phagara opened 1 month ago

phagara commented 1 month ago

Describe the bug

Custom pip args used during install are not reused when checking for upgrades.

Additionally, even an unsuccessful upgrade overwrites the pip args in pipx metadata (with an empty list, in case the required custom pip args are not explicitly repeated on the pipx upgrade command line).

How to reproduce

  1. pipx install --index-url https://custom-index.example.com --pip-args=--cert=/path/to/custom/ca.pem foo
  2. pipx upgrade --verbose foo
pipx >(setup:1083): pipx version is 1.6.0
pipx >(setup:1084): Default python interpreter is '/opt/homebrew/opt/python@3.12/libexec/bin/python'
pipx >(run_pipx_command:226): Virtual Environment locations are:
- foo : /Users/user/.local/pipx/venvs/foo
pipx >(_upgrade_venv:154): Ignoring --python as not combined with --install
pipx >(run_subprocess:175): running <checking pip's availability>
pipx >(needs_upgrade:83): Time since last upgrade of shared libs, in seconds: 51. Upgrade will be run by pipx if greater than 2592000.
pipx >(run_subprocess:175): running <checking pip's availability>
pipx >(run_subprocess:175): running <checking pip's availability>
pipx >(upgrade:103): Upgrading shared libraries in /Users/user/.local/pipx/shared
upgrading shared libraries...
pipx >(run_subprocess:175): running /Users/user/.local/pipx/shared/bin/python -m pip --no-input --disable-pip-version-check install --upgrade pip >= 23.1
pipx >(_parsed_package_to_package_or_url:139): cleaned package spec: foo
pipx >(upgrade_package:455): Upgrading foo
upgrading foo...
pipx >(run_subprocess:175): running /Users/user/.local/pipx/venvs/foo/bin/python -m pip --no-input install --upgrade foo
pipx >(run_subprocess:175): running <fetch_info_in_venv commands>
pipx >(get_venv_metadata_for_package:349): get_venv_metadata_for_package: 81ms
pipx >(_parsed_package_to_package_or_url:139): cleaned package spec: foo
pipx >(_symlink_package_resource:144): Same path /Users/user/.local/bin/foo and /Users/user/.local/pipx/venvs/foo/bin/foo
foo is already at latest version 1.2.3 (location: /Users/user/.local/pipx/venvs/foo)

Expected behavior

Pipx clearly remembers the original pip args from installation, as can be seen in ~/.local/pipx/venvs/foo/pipx_metadata.json (edited for brevity):

{
    "main_package": {
        "pip_args": [
            "--index-url",
            "https://custom-index.example.com",
            "--cert=/path/to/custom/ca.pem"
        ],
}

However, they are completely ignored and then promptly overwritten with an empty list after running pipx upgrade foo (which usually does not find a newer version due to missing custom index URL, incorrect CA certificate bundle used, etc.).

I would expect pipx upgrade foo to always reuse the remembered pip_args from installation.

Notably, pipx upgrade-all already correctly reuses the install-time pip args when looking for upgrades, so things like custom index URLs and associated CA certificates work there. All hell breaks loose when I try to pipx upgrade just a single package though. :)