Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display pyproject.toml's metatada parsing errors in verbose mode #1979

Merged
merged 12 commits into from
Sep 5, 2023
Merged
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