Commit b8e912dc by Randy Döring Committed by GitHub

installer: improve error messages for building dependencies (#7667)

parent 4dfb8940
...@@ -24,6 +24,7 @@ from poetry.installation.operations import Install ...@@ -24,6 +24,7 @@ from poetry.installation.operations import Install
from poetry.installation.operations import Uninstall from poetry.installation.operations import Uninstall
from poetry.installation.operations import Update from poetry.installation.operations import Update
from poetry.installation.wheel_installer import WheelInstaller from poetry.installation.wheel_installer import WheelInstaller
from poetry.puzzle.exceptions import SolverProblemError
from poetry.utils._compat import decode from poetry.utils._compat import decode
from poetry.utils.authenticator import Authenticator from poetry.utils.authenticator import Authenticator
from poetry.utils.env import EnvCommandError from poetry.utils.env import EnvCommandError
...@@ -301,7 +302,14 @@ class Executor: ...@@ -301,7 +302,14 @@ class Executor:
trace.render(io) trace.render(io)
if isinstance(e, ChefBuildError): if isinstance(e, ChefBuildError):
pkg = operation.package pkg = operation.package
requirement = pkg.to_dependency().to_pep_508() pip_command = "pip wheel --use-pep517"
if pkg.develop:
requirement = pkg.source_url
pip_command += " --editable"
else:
requirement = (
pkg.to_dependency().to_pep_508().split(";")[0].strip()
)
io.write_line("") io.write_line("")
io.write_line( io.write_line(
"<info>" "<info>"
...@@ -309,9 +317,18 @@ class Executor: ...@@ -309,9 +317,18 @@ class Executor:
" and is likely not a problem with poetry" " and is likely not a problem with poetry"
f" but with {pkg.pretty_name} ({pkg.full_pretty_version})" f" but with {pkg.pretty_name} ({pkg.full_pretty_version})"
" not supporting PEP 517 builds. You can verify this by" " not supporting PEP 517 builds. You can verify this by"
f" running 'pip wheel --use-pep517 \"{requirement}\"'." f" running '{pip_command} \"{requirement}\"'."
"</info>" "</info>"
) )
elif isinstance(e, SolverProblemError):
pkg = operation.package
io.write_line("")
io.write_line(
"<error>"
"Cannot resolve build-system.requires"
f" for {pkg.pretty_name}."
"</error>"
)
io.write_line("") io.write_line("")
finally: finally:
with self._lock: with self._lock:
......
[tool.poetry]
name = "simple-project"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <sebastien@eustace.io>"
]
license = "MIT"
readme = ["README.rst"]
homepage = "https://python-poetry.org"
repository = "https://github.com/python-poetry/poetry"
documentation = "https://python-poetry.org/docs"
keywords = ["packaging", "dependency", "poetry"]
classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules"
]
# Requirements
[tool.poetry.dependencies]
python = "^3.7"
[build-system]
requires = ["poetry-core==0.999"]
build-backend = "poetry.core.masonry.api"
...@@ -22,6 +22,7 @@ from cleo.io.buffered_io import BufferedIO ...@@ -22,6 +22,7 @@ from cleo.io.buffered_io import BufferedIO
from cleo.io.outputs.output import Verbosity from cleo.io.outputs.output import Verbosity
from poetry.core.packages.package import Package from poetry.core.packages.package import Package
from poetry.core.packages.utils.link import Link from poetry.core.packages.utils.link import Link
from poetry.core.packages.utils.utils import path_to_url
from poetry.factory import Factory from poetry.factory import Factory
from poetry.installation.chef import Chef as BaseChef from poetry.installation.chef import Chef as BaseChef
...@@ -1093,8 +1094,10 @@ Package operations: 1 install, 0 updates, 0 removals ...@@ -1093,8 +1094,10 @@ Package operations: 1 install, 0 updates, 0 removals
@pytest.mark.parametrize("failing_method", ["build", "get_requires_for_build"]) @pytest.mark.parametrize("failing_method", ["build", "get_requires_for_build"])
@pytest.mark.parametrize("editable", [False, True])
def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess( def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess(
failing_method: str, failing_method: str,
editable: bool,
mocker: MockerFixture, mocker: MockerFixture,
config: Config, config: Config,
pool: RepositoryPool, pool: RepositoryPool,
...@@ -1102,7 +1105,7 @@ def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess( ...@@ -1102,7 +1105,7 @@ def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess(
tmp_dir: str, tmp_dir: str,
mock_file_downloads: None, mock_file_downloads: None,
env: MockEnv, env: MockEnv,
): ) -> None:
error = BuildBackendException( error = BuildBackendException(
CalledProcessError(1, ["pip"], output=b"Error on stdout") CalledProcessError(1, ["pip"], output=b"Error on stdout")
) )
...@@ -1121,7 +1124,10 @@ def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess( ...@@ -1121,7 +1124,10 @@ def test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess(
.parent.parent.joinpath("fixtures/simple_project") .parent.parent.joinpath("fixtures/simple_project")
.resolve() .resolve()
.as_posix(), .as_posix(),
develop=editable,
) )
# must not be included in the error message
directory_package.python_versions = ">=3.7"
return_code = executor.execute( return_code = executor.execute(
[ [
...@@ -1145,14 +1151,70 @@ Package operations: 1 install, 0 updates, 0 removals ...@@ -1145,14 +1151,70 @@ Package operations: 1 install, 0 updates, 0 removals
Error on stdout Error on stdout
""" """
requirement = directory_package.to_dependency().to_pep_508() if editable:
pip_command = "pip wheel --use-pep517 --editable"
requirement = directory_package.source_url
assert Path(requirement).exists()
else:
pip_command = "pip wheel --use-pep517"
requirement = f"{package_name} @ {path_to_url(directory_package.source_url)}"
expected_end = f""" expected_end = f"""
Note: This error originates from the build backend, and is likely not a problem with \ Note: This error originates from the build backend, and is likely not a problem with \
poetry but with {package_name} ({package_version} {package_url}) not supporting \ poetry but with {package_name} ({package_version} {package_url}) not supporting \
PEP 517 builds. You can verify this by running 'pip wheel --use-pep517 "{requirement}"'. PEP 517 builds. You can verify this by running '{pip_command} "{requirement}"'.
""" """
output = io.fetch_output() output = io.fetch_output()
assert output.startswith(expected_start) assert output.startswith(expected_start)
assert output.endswith(expected_end) assert output.endswith(expected_end)
def test_build_system_requires_not_available(
config: Config,
pool: RepositoryPool,
io: BufferedIO,
tmp_dir: str,
mock_file_downloads: None,
env: MockEnv,
fixture_dir: FixtureDirGetter,
) -> None:
io.set_verbosity(Verbosity.NORMAL)
executor = Executor(env, pool, config, io)
package_name = "simple-project"
package_version = "1.2.3"
directory_package = Package(
package_name,
package_version,
source_type="directory",
source_url=fixture_dir("build_system_requires_not_available")
.resolve()
.as_posix(),
)
return_code = executor.execute(
[
Install(directory_package),
]
)
assert return_code == 1
package_url = directory_package.source_url
expected_start = f"""\
Package operations: 1 install, 0 updates, 0 removals
• Installing {package_name} ({package_version} {package_url})
SolveFailure
Because -root- depends on poetry-core (0.999) which doesn't match any versions,\
version solving failed.
"""
expected_end = "Cannot resolve build-system.requires for simple-project."
output = io.fetch_output().strip()
assert output.startswith(expected_start)
assert output.endswith(expected_end)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment