From f7d25641dedc0cb49b74b8c29f634d0a1bcf31a0 Mon Sep 17 00:00:00 2001 From: ayemiller Date: Mon, 19 Aug 2024 03:54:00 -0400 Subject: [PATCH] Fixes #1509 short-circuit of installing packages when already installed (#1510) Co-authored-by: chrysle <96722107+chrysle@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- changelog.d/1509.bugfix.md | 1 + src/pipx/commands/install.py | 6 +++++- tests/test_install.py | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 changelog.d/1509.bugfix.md diff --git a/changelog.d/1509.bugfix.md b/changelog.d/1509.bugfix.md new file mode 100644 index 0000000000..c539aaf3d5 --- /dev/null +++ b/changelog.d/1509.bugfix.md @@ -0,0 +1 @@ +Fix installation abortion on multiple packages when one or more are already installed. diff --git a/src/pipx/commands/install.py b/src/pipx/commands/install.py index adeff2b2b1..dbf26ba28f 100644 --- a/src/pipx/commands/install.py +++ b/src/pipx/commands/install.py @@ -84,7 +84,11 @@ def install( """ ) ) - return EXIT_CODE_INSTALL_VENV_EXISTS + if len(package_specs) == 1: + return EXIT_CODE_INSTALL_VENV_EXISTS + # Reset venv_dir to None ready to install the next package in the list + venv_dir = None + continue try: # Enable installing shared library `pip` with `pipx` diff --git a/tests/test_install.py b/tests/test_install.py index b83310e988..2cff936880 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -85,6 +85,19 @@ def test_install_tricky_packages(capsys, pipx_temp_env, caplog, package_name, pa install_packages(capsys, pipx_temp_env, caplog, [package_spec], [package_name]) +def test_install_multiple_packages_when_some_already_installed(capsys, pipx_temp_env, caplog): + run_pipx_cli(["install", "black", "pycowsay"]) + captured = capsys.readouterr() + assert "installed package black" in captured.out + assert "installed package pycowsay" in captured.out + + run_pipx_cli(["install", "black", "pycowsay", "isort"]) + captured = capsys.readouterr() + assert "'black' already seems to be installed" in captured.out + assert "'pycowsay' already seems to be installed" in captured.out + assert "installed package isort" in captured.out + + def test_install_tricky_multiple_packages(capsys, pipx_temp_env, caplog): if os.getenv("FAST"): pytest.skip("skipping slow tests")