Skip to content

Commit 5a6e59b

Browse files
committed
Apply suggestions from code review
1 parent 5c0763e commit 5a6e59b

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/pipx/backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99

1010
def path_to_exec(executable: str, installer: bool = False) -> str:
11-
if executable == "venv" or "pip":
11+
if executable in ("venv", "pip"):
1212
return executable
1313
path = shutil.which(executable)
1414
if path:
1515
return path
1616
elif installer:
17-
logger.warning(f"{executable} not found on PATH. Falling back to pip.")
17+
logger.warning(f"'{executable}' not found on PATH. Falling back to 'pip'.")
1818
return ""
1919
else:
20-
logger.warning(f"{executable} not found on PATH. Falling back to venv.")
20+
logger.warning(f"'{executable}' not found on PATH. Falling back to 'venv'.")
2121
return ""

src/pipx/venv.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __init__(
112112

113113
if not path_to_exec(self.backend):
114114
self.backend = "venv"
115-
if not path_to_exec(self.installer):
115+
if not path_to_exec(self.installer, installer=True):
116116
self.installer = "pip"
117117

118118
def check_upgrade_shared_libs(self, verbose: bool, pip_args: List[str], force_upgrade: bool = False):
@@ -290,7 +290,7 @@ def install_package(
290290
# no logging because any errors will be specially logged by
291291
# subprocess_post_check_handle_pip_error()
292292
install_process = self._run_installer(
293-
self.installer, [*pip_args, package_or_url], quiet=True, log_stdout=False, log_stderr=False
293+
[*pip_args, package_or_url], quiet=True, log_stdout=False, log_stderr=False
294294
)
295295
subprocess_post_check_handle_pip_error(install_process)
296296
if install_process.returncode:
@@ -329,7 +329,7 @@ def install_unmanaged_packages(self, requirements: List[str], pip_args: List[str
329329
# no logging because any errors will be specially logged by
330330
# subprocess_post_check_handle_pip_error()
331331
install_process = self._run_installer(
332-
self.installer, [*pip_args, *requirements], quiet=True, log_stdout=False, log_stderr=False
332+
[*pip_args, *requirements], quiet=True, log_stdout=False, log_stderr=False
333333
)
334334
subprocess_post_check_handle_pip_error(install_process)
335335
if install_process.returncode:
@@ -339,7 +339,7 @@ def install_package_no_deps(self, package_or_url: str, pip_args: List[str]) -> s
339339
with animate(f"determining package name from {package_or_url!r}", self.do_animation):
340340
old_package_set = self.list_installed_packages()
341341
# TODO: rename pip_args to installer_args? But we can keep pip_args as implicit one
342-
install_process = self._run_installer(self.installer, [*pip_args, package_or_url], no_deps=True)
342+
install_process = self._run_installer([*pip_args, package_or_url], no_deps=True)
343343

344344
subprocess_post_check(install_process, raise_error=False)
345345
if install_process.returncode:
@@ -464,7 +464,7 @@ def has_package(self, package_name: str) -> bool:
464464
def upgrade_package_no_metadata(self, package_name: str, pip_args: List[str]) -> None:
465465
logger.info("Upgrading %s", package_descr := full_package_description(package_name, package_name))
466466
with animate(f"upgrading {package_descr}", self.do_animation):
467-
upgrade_process = self._run_installer(self.installer, [*pip_args, "--upgrade", package_name])
467+
upgrade_process = self._run_installer([*pip_args, "--upgrade", package_name])
468468
subprocess_post_check(upgrade_process)
469469

470470
def upgrade_package(
@@ -479,7 +479,7 @@ def upgrade_package(
479479
) -> None:
480480
logger.info("Upgrading %s", package_descr := full_package_description(package_name, package_or_url))
481481
with animate(f"upgrading {package_descr}", self.do_animation):
482-
upgrade_process = self._run_installer(self.installer, [*pip_args, "--upgrade", package_or_url])
482+
upgrade_process = self._run_installer([*pip_args, "--upgrade", package_or_url])
483483
subprocess_post_check(upgrade_process)
484484

485485
self.update_package_metadata(
@@ -494,7 +494,6 @@ def upgrade_package(
494494

495495
def _run_installer(
496496
self,
497-
installer: str,
498497
cmd: List[str],
499498
quiet: bool = True,
500499
no_deps: bool = False,
@@ -503,7 +502,7 @@ def _run_installer(
503502
) -> "CompletedProcess[str]":
504503
# do not use -q with `pip install` so subprocess_post_check_pip_errors
505504
# has more information to analyze in case of failure.
506-
if installer != "uv":
505+
if self.installer != "uv":
507506
return self._run_pip(
508507
["--no-input", "install"] + (["--no-dependencies"] if no_deps else []) + cmd, quiet=quiet
509508
)

0 commit comments

Comments
 (0)