Skip to content

Commit

Permalink
Improve error reporting for build backend errors - TODO squash into o…
Browse files Browse the repository at this point in the history
…ther error handling commit
  • Loading branch information
radoering committed Jan 28, 2023
1 parent 54c4ac3 commit 3041a2b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/poetry/installation/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,40 @@ def _prepare(
runner=quiet_subprocess_runner,
)
env.install(builder.build_system_requires)
env.install(
builder.build_system_requires | builder.get_requires_for_build("wheel")
)

stdout = StringIO()
error: Exception | None = None
try:
with redirect_stdout(stdout):
env.install(
builder.build_system_requires
| builder.get_requires_for_build("wheel")
)
path = Path(
builder.build(
"wheel" if not editable else "editable",
destination.as_posix(),
)
)
except BuildBackendException as e:
disclaimer = (
"Note: This error originates from the build backend,"
" and is likely not a problem with poetry"
" but the concerning package not supporting PEP 517 builds."
" You can verify this by running"
" 'pip wheel --use-pep517 <concerning package>'."
)
message_parts = [disclaimer, str(e)]
if isinstance(e.exception, CalledProcessError) and (
e.exception.stdout is not None or e.exception.stderr is not None
):
message = (
message_parts.append(
e.exception.stderr.decode()
if e.exception.stderr is not None
else e.exception.stdout.decode()
)
error = ChefBuildError(message)
else:
error = ChefBuildError(str(e))

error = ChefBuildError("\n\n".join(message_parts))

if error is not None:
raise error from None
Expand Down
12 changes: 11 additions & 1 deletion tests/installation/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,9 @@ def test_executor_fallback_on_poetry_create_error_without_wheel_installer(
assert mock_pip_install.call_args[1].get("editable") is False


@pytest.mark.parametrize("failing_method", ["build", "get_requires_for_build"])
def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess(
failing_method: str,
mocker: MockerFixture,
config: Config,
pool: RepositoryPool,
Expand All @@ -923,7 +925,7 @@ def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess(
error = BuildBackendException(
CalledProcessError(1, ["pip"], output=b"Error on stdout")
)
mocker.patch.object(ProjectBuilder, "build", side_effect=error)
mocker.patch.object(ProjectBuilder, failing_method, side_effect=error)
io.set_verbosity(Verbosity.NORMAL)

executor = Executor(env, pool, config, io)
Expand Down Expand Up @@ -953,6 +955,14 @@ def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess(
ChefBuildError
Note: This error originates from the build backend, and is likely not a problem with \
poetry but the concerning package not supporting PEP 517 builds. You can verify this \
by running 'pip wheel --use-pep517 <concerning package>'.
\
Backend operation failed: CalledProcessError(1, ['pip'])
\
Error on stdout
"""

Expand Down

0 comments on commit 3041a2b

Please sign in to comment.