pipx
pipx copied to clipboard
`pipx upgrade --install` ignores `--system-site-packages` option
Describe the bug
Recently in this PR the --install option was added to the upgrade command.
Unfortunately this doesn't seem to respect the --system-site-packages option.
How to reproduce
When using upgrade --install the --system-site-packages option isn't respected:
❯ pipx upgrade --install --system-site-packages pycowsay
❯ grep system $HOME/.local/share/pipx/venvs/pycowsay/pyvenv.cfg
include-system-site-packages = false
Comparison with the install command, where it works correctly:
❯ pipx install --system-site-packages pycowsay
❯ grep system $HOME/.local/share/pipx/venvs/pycowsay/pyvenv.cfg
include-system-site-packages = true
command = /usr/bin/python3 -m venv --without-pip --system-site-packages /home/sadamczyk/.local/share/pipx/venvs/pycowsay
Expected behavior
The upgrade --install command should handle the --system-site-packages option just like the install command does.
Investigation
Looking through the code, the --system-site-packages option seems to be passed to the install command in the venv_args variable from the get_venv_args function: https://github.com/pypa/pipx/blob/5482fac6c3dfc3775af398d630ef30102f15bdcc/src/pipx/main.py#L170-L174
https://github.com/pypa/pipx/blob/5482fac6c3dfc3775af398d630ef30102f15bdcc/src/pipx/main.py#L182
But venv_args is only passed to the run, install and install-all commands
https://github.com/pypa/pipx/blob/5482fac6c3dfc3775af398d630ef30102f15bdcc/src/pipx/main.py#L244-L253
... but not to the upgrade command:
https://github.com/pypa/pipx/blob/5482fac6c3dfc3775af398d630ef30102f15bdcc/src/pipx/main.py#L294-L304
It might be enough to add the required function arguments so that the venv_args from the main.py can be passed through all the way to the install call here:
https://github.com/pypa/pipx/blob/5482fac6c3dfc3775af398d630ef30102f15bdcc/src/pipx/commands/upgrade.py#L111-L114
Although the --install option is merely meant as a backup (e. g. for automation), and still pipx install should be used to enable more customization, probably it wouldn't hurt to implement your suggestion. Would you like to do this yourself?
@chrysle Sure, I can try implementing it. I'll take a look in the coming weeks.