Skip to content

Commit e62c95a

Browse files
committed
info: fix metadata build error propagation
This change fixes a regression that caused the swallowing of PEP517 build errors when isolated builds fail during metadata build.
1 parent c70cbf4 commit e62c95a

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/poetry/inspection/info.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import functools
55
import glob
66
import logging
7+
import subprocess
78
import tempfile
89

910
from pathlib import Path
@@ -542,7 +543,33 @@ def get_pep517_metadata(path: Path) -> PackageInfo:
542543
info = PackageInfo.from_metadata_directory(dest)
543544
except BuildBackendException as e:
544545
logger.debug("PEP517 build failed: %s", e)
545-
raise PackageInfoError(path, e, "PEP517 build failed")
546+
547+
if isinstance(e.exception, subprocess.CalledProcessError):
548+
inner_traceback = (
549+
e.exception.output.decode()
550+
if type(e.exception.output) is bytes
551+
else e.exception.output
552+
)
553+
inner_reason = "\n | ".join(
554+
["", str(e.exception), "", *inner_traceback.split("\n")]
555+
)
556+
reasons = [
557+
f"<warning>{inner_reason}</warning>",
558+
(
559+
"<info>"
560+
"<options=bold>Note:</> This error originates from the build backend, and is likely not a "
561+
f"problem with poetry but with the package at {path}\n\n"
562+
" (a) not supporting PEP 517 builds\n"
563+
" (b) not specifying PEP 517 build requirements correctly; or\n"
564+
" (c) the build requirement not being successfully installed in your system environment.\n\n"
565+
f'You can verify this by running <c1>pip wheel --no-cache-dir --use-pep517 "{path}"</c1>.'
566+
"</info>"
567+
),
568+
]
569+
else:
570+
reasons = [e, "PEP517 build failed"]
571+
572+
raise PackageInfoError(path, *reasons) from None
546573

547574
if info:
548575
return info

tests/inspection/test_info.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import shutil
4+
import uuid
45

56
from subprocess import CalledProcessError
67
from typing import TYPE_CHECKING
@@ -331,15 +332,24 @@ def test_info_setup_complex(demo_setup_complex: Path) -> None:
331332
def test_info_setup_complex_pep517_error(
332333
mocker: MockerFixture, demo_setup_complex: Path
333334
) -> None:
335+
output = uuid.uuid4().hex
334336
mocker.patch(
335337
"build.ProjectBuilder.from_isolated_env",
336338
autospec=True,
337-
side_effect=BuildBackendException(CalledProcessError(1, "mock", output="mock")),
339+
side_effect=BuildBackendException(CalledProcessError(1, "mock", output=output)),
338340
)
339341

340-
with pytest.raises(PackageInfoError):
342+
with pytest.raises(PackageInfoError) as exc:
341343
PackageInfo.from_directory(demo_setup_complex)
342344

345+
text = str(exc.value)
346+
assert "Command 'mock' returned non-zero exit status 1." in text
347+
assert output in text
348+
assert (
349+
"This error originates from the build backend, and is likely not a problem with poetry"
350+
in text
351+
)
352+
343353

344354
def test_info_setup_complex_pep517_legacy(
345355
demo_setup_complex_pep517_legacy: Path,

0 commit comments

Comments
 (0)