Skip to content

Commit 3c1eb3d

Browse files
committed
fix(install): preserve detection errors
1 parent 9f9430c commit 3c1eb3d

5 files changed

Lines changed: 35 additions & 7 deletions

File tree

changelog.d/1567.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Preserve installer errors when package-name detection fails during local package installs.

src/pipx/backends/pip.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ def install(
9595
)
9696
if log_pip_errors:
9797
subprocess_post_check_handle_pip_error(process)
98-
else:
99-
subprocess_post_check(process, raise_error=False)
10098
return process
10199

102100
def uninstall(

src/pipx/backends/uv.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ def install(
113113
)
114114
if log_pip_errors:
115115
subprocess_post_check_handle_pip_error(process, tool_name="uv")
116-
else:
117-
subprocess_post_check(process, raise_error=False)
118116
return process
119117

120118
def uninstall(

src/pipx/venv.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,13 @@ def install_package_no_deps(self, package_or_url: str, pip_args: list[str]) -> s
390390
verbose=self.verbose,
391391
)
392392
if process.returncode:
393+
error_output = (process.stderr or process.stdout or "").strip()
394+
if error_output:
395+
raise PipxError(error_output, wrap_message=False)
393396
raise PipxError(
394397
f"""
395-
Cannot determine package name from spec {package_or_url!r}.
396-
Check package spec for errors.
398+
Error determining package name from spec {package_or_url!r}.
399+
See installer output for details.
397400
"""
398401
)
399402

tests/test_install.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from helpers import app_name, run_pipx_cli, skip_if_windows, unwrap_log_text
1111
from package_info import PKG
1212
from pipx import paths, shared_libs
13+
from pipx.util import PipxError
14+
from pipx.venv import Venv
1315

1416
TEST_DATA_PATH = "./testdata/test_package_specifier"
1517

@@ -263,7 +265,33 @@ def test_pip_args_forwarded_to_package_name_determination(pipx_temp_env, capsys)
263265
]
264266
)
265267
captured = capsys.readouterr()
266-
assert "Cannot determine package name from spec" in captured.err
268+
assert "--asdf" in captured.err
269+
assert "Cannot determine package name from spec" not in captured.err
270+
271+
272+
def test_package_name_determination_preserves_install_error(monkeypatch):
273+
class FailingBackend:
274+
def install(self, **kwargs):
275+
return subprocess.CompletedProcess(
276+
["pip", "install", "requires-newer-python"],
277+
1,
278+
stdout="",
279+
stderr="ERROR: Package 'requires-newer-python' requires a different Python\n",
280+
)
281+
282+
def no_installed_packages():
283+
return set()
284+
285+
venv = Venv(Path("requires-newer-python-venv"))
286+
monkeypatch.setattr(venv, "_backend", FailingBackend())
287+
monkeypatch.setattr(venv, "list_installed_packages", no_installed_packages)
288+
289+
with pytest.raises(PipxError) as excinfo:
290+
venv.install_package_no_deps("requires-newer-python", [])
291+
292+
error = str(excinfo.value)
293+
assert "requires a different Python" in error
294+
assert "Cannot determine package name from spec" not in error
267295

268296

269297
@pytest.mark.skipif(not sys.platform.startswith("win"), reason="Windows only")

0 commit comments

Comments
 (0)