Skip to content

Commit

Permalink
Display pyproject.toml's metatada parsing errors in verbose mode (#…
Browse files Browse the repository at this point in the history
…1979)

Since version "1.0.0" is released on PyPI we can pass a type of
subprocess runner to "build.ProjectBuilder".
Before the type was hardcoded insude "ProjectBuilder" and was not
available to user. Therefore, whenever the error on parsing
pyproject.toml file happened, user seen only short and non-informative
`Backend subprocess exited when trying to invoke
get_requires_for_build_wheel`.
Now we can select `pyproject_hooks.default_subprocess_runner` from
`pyproject_hooks` library. This runner will throw the error directly
from toml parsing library.
  • Loading branch information
szobov committed Sep 5, 2023
1 parent f850d0e commit e272f65
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ repos:
- pep517==0.10.0
- toml==0.10.2
- pip==20.3.4
- build==0.9.0
- build==1.0.0
- pyproject_hooks==1.0.0
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
Expand Down
6 changes: 6 additions & 0 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pip._internal.req import InstallRequirement
from pip._internal.req.constructors import install_req_from_line
from pip._internal.utils.misc import redact_auth_from_url
from pyproject_hooks import default_subprocess_runner, quiet_subprocess_runner

from .._compat import parse_requirements
from ..cache import DependencyCache
Expand Down Expand Up @@ -323,6 +324,11 @@ def cli(
metadata = project_wheel_metadata(
os.path.dirname(os.path.abspath(src_file)),
isolated=build_isolation,
runner=(
default_subprocess_runner
if verbose
else quiet_subprocess_runner
),
)
except BuildBackendException as e:
log.error(str(e))
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ classifiers = [
keywords = ["pip", "requirements", "packaging"]
dependencies = [
# direct dependencies
"build",
"build >= 1.0.0",
"pyproject_hooks",
"click >= 8",
"pip >= 22.2",
"tomli; python_version < '3.11'",
Expand Down
34 changes: 34 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2582,6 +2582,40 @@ def test_input_formats(fake_dists, runner, make_module, fname, content):
assert "extra ==" not in out.stderr


@pytest.mark.parametrize("verbose_option", (True, False))
def test_error_in_pyproject_toml(
fake_dists, runner, make_module, capfd, verbose_option
):
"""
Test that an error in pyproject.toml is reported.
"""
fname = "pyproject.toml"
invalid_content = dedent(
"""\
[project]
invalid = "metadata"
"""
)
meta_path = make_module(fname=fname, content=invalid_content)

options = []
if verbose_option:
options = ["--verbose"]

options.extend(
["-n", "--no-build-isolation", "--find-links", fake_dists, meta_path]
)

out = runner.invoke(cli, options)

assert out.exit_code == 2, out.stderr
captured = capfd.readouterr()

assert (
"`project` must contain ['name'] properties" in captured.err
) is verbose_option


@pytest.mark.network
@pytest.mark.parametrize(("fname", "content"), METADATA_TEST_CASES)
def test_one_extra(fake_dists, runner, make_module, fname, content):
Expand Down

0 comments on commit e272f65

Please sign in to comment.