Skip to content

Commit

Permalink
info: fix metadata build error propagation
Browse files Browse the repository at this point in the history
This change fixes a regression that caused the swallowing of PEP517
build errors when isolated builds fail during metadata build.
  • Loading branch information
abn committed Nov 28, 2024
1 parent 37b1013 commit bd25690
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
29 changes: 28 additions & 1 deletion src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import functools
import glob
import logging
import subprocess
import tempfile

from pathlib import Path
Expand Down Expand Up @@ -542,7 +543,33 @@ def get_pep517_metadata(path: Path) -> PackageInfo:
info = PackageInfo.from_metadata_directory(dest)
except BuildBackendException as e:
logger.debug("PEP517 build failed: %s", e)
raise PackageInfoError(path, e, "PEP517 build failed")

if isinstance(e.exception, subprocess.CalledProcessError):
inner_traceback = (
e.exception.output.decode()
if type(e.exception.output) is bytes
else e.exception.output
)
inner_reason = "\n | ".join(
["", str(e.exception), "", *inner_traceback.split("\n")]
)
reasons = [
f"<warning>{inner_reason}</warning>",
(
"<info>"
"<options=bold>Note:</> This error originates from the build backend, and is likely not a "
f"problem with poetry but with the package at {path}\n\n"
" (a) not supporting PEP 517 builds\n"
" (b) not specifying PEP 517 build requirements correctly; or\n"
" (c) the build requirement not being successfully installed in your system environment.\n\n"
f'You can verify this by running <c1>pip wheel --no-cache-dir --use-pep517 "{path}"</c1>.'
"</info>"
),
]
else:
reasons = [str(e), "PEP517 build failed"]

raise PackageInfoError(path, *reasons) from None

if info:
return info
Expand Down
14 changes: 12 additions & 2 deletions tests/inspection/test_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import shutil
import uuid

from subprocess import CalledProcessError
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -331,15 +332,24 @@ def test_info_setup_complex(demo_setup_complex: Path) -> None:
def test_info_setup_complex_pep517_error(
mocker: MockerFixture, demo_setup_complex: Path
) -> None:
output = uuid.uuid4().hex
mocker.patch(
"build.ProjectBuilder.from_isolated_env",
autospec=True,
side_effect=BuildBackendException(CalledProcessError(1, "mock", output="mock")),
side_effect=BuildBackendException(CalledProcessError(1, "mock", output=output)),
)

with pytest.raises(PackageInfoError):
with pytest.raises(PackageInfoError) as exc:
PackageInfo.from_directory(demo_setup_complex)

text = str(exc.value)
assert "Command 'mock' returned non-zero exit status 1." in text
assert output in text
assert (
"This error originates from the build backend, and is likely not a problem with poetry"
in text
)


def test_info_setup_complex_pep517_legacy(
demo_setup_complex_pep517_legacy: Path,
Expand Down

0 comments on commit bd25690

Please sign in to comment.