Skip to content

Commit

Permalink
Fix --system-site-packages for upgrade --install (#1378)
Browse files Browse the repository at this point in the history
* Fix --system-site-package for upgrade --install

Fix #1344

* Update changelog.d/1344.bugfix.md

Co-authored-by: chrysle <[email protected]>

---------

Co-authored-by: chrysle <[email protected]>
Co-authored-by: chrysle <[email protected]>
  • Loading branch information
3 people authored Apr 30, 2024
1 parent fd53625 commit 9c655e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/1344.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make the Python `venv` module arguments work with `upgrade --install`
10 changes: 9 additions & 1 deletion src/pipx/commands/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,18 @@ def _upgrade_venv(
upgrading_all: bool,
force: bool,
install: bool = False,
venv_args: Optional[List[str]] = None,
python: Optional[str] = None,
python_flag_passed: bool = False,
) -> int:
"""Return number of packages with changed versions."""
if not venv_dir.is_dir():
if install:
if venv_args is None:
venv_args = []
commands.install(
venv_dir=None,
venv_args=[],
venv_args=venv_args,
package_names=None,
package_specs=[str(venv_dir).split(os.path.sep)[-1]],
local_bin_dir=paths.ctx.bin_dir,
Expand All @@ -135,6 +138,9 @@ def _upgrade_venv(
"""
)

if venv_args and not install:
logger.info("Ignoring " + ", ".join(venv_args) + " as not combined with --install")

if python and not install:
logger.info("Ignoring --python as not combined with --install")

Expand Down Expand Up @@ -184,6 +190,7 @@ def upgrade(
venv_dirs: Dict[str, Path],
python: Optional[str],
pip_args: List[str],
venv_args: List[str],
verbose: bool,
*,
include_injected: bool,
Expand All @@ -202,6 +209,7 @@ def upgrade(
upgrading_all=False,
force=force,
install=install,
venv_args=venv_args,
python=python,
python_flag_passed=python_flag_passed,
)
Expand Down
1 change: 1 addition & 0 deletions src/pipx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def run_pipx_command(args: argparse.Namespace, subparsers: Dict[str, argparse.Ar
venv_dirs,
args.python,
pip_args,
venv_args,
verbose,
include_injected=args.include_injected,
force=args.force,
Expand Down

0 comments on commit 9c655e0

Please sign in to comment.