Skip to content

Commit

Permalink
refactor: unify the -all operation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
huxuan committed Apr 19, 2024
1 parent e9d895a commit 3cb9884
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
4 changes: 1 addition & 3 deletions src/pipx/commands/reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def reinstall_all(
if venv_dir.name in skip:
continue
try:
package_exit = reinstall(
reinstall(
venv_dir=venv_dir,
local_bin_dir=local_bin_dir,
local_man_dir=local_man_dir,
Expand All @@ -134,8 +134,6 @@ def reinstall_all(
failed.append(venv_dir.name)
else:
first_reinstall = False
if package_exit != 0:
failed.append(venv_dir.name)
if len(failed) > 0:
raise PipxError(f"The following package(s) failed to reinstall: {', '.join(failed)}")
# Any failure to install will raise PipxError, otherwise success
Expand Down
28 changes: 13 additions & 15 deletions src/pipx/commands/upgrade.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import sys
from pathlib import Path
from typing import Dict, List, Optional, Sequence

Expand Down Expand Up @@ -220,15 +221,16 @@ def upgrade_all(
python_flag_passed: bool = False,
) -> ExitCode:
"""Returns pipx exit code."""
venv_error = False
venvs_upgraded = 0
failed: List[str] = []
upgraded: List[str] = []

for venv_dir in venv_container.iter_venv_dirs():
venv = Venv(venv_dir, verbose=verbose)
venv.check_upgrade_shared_libs(pip_args=pip_args, verbose=verbose)
if venv_dir.name in skip or "--editable" in venv.pipx_metadata.main_package.pip_args:
continue
try:
venvs_upgraded += _upgrade_venv(
_upgrade_venv(
venv_dir,
venv.pipx_metadata.main_package.pip_args,
verbose=verbose,
Expand All @@ -237,18 +239,14 @@ def upgrade_all(
force=force,
python_flag_passed=python_flag_passed,
)

except PipxError as e:
venv_error = True
logger.error(f"Error encountered when upgrading {venv_dir.name}:")
logger.error(f"{e}\n")

if venvs_upgraded == 0:
print(e, file=sys.stderr)
failed.append(venv_dir.name)
else:
upgraded.append(venv_dir.name)
if len(upgraded) == 0:
print(f"Versions did not change after running 'pipx upgrade' for each package {sleep}")
if venv_error:
raise PipxError(
"\nSome packages encountered errors during upgrade.\n" " See specific error messages above.",
wrap_message=False,
)

if len(failed) > 0:
raise PipxError(f"The following package(s) failed to upgrade: {','.join(failed)}")
# Any failure to install will raise PipxError, otherwise success
return EXIT_CODE_OK

0 comments on commit 3cb9884

Please sign in to comment.