diff --git a/news/9774.feature.rst b/news/9774.feature.rst new file mode 100644 index 00000000000..8baac5e967f --- /dev/null +++ b/news/9774.feature.rst @@ -0,0 +1,3 @@ +Warn instead of erroring out when doing a PEP 517 build in presence of +``--build-option``. Warn when doing a PEP 517 build in presence of +``--global-option``. diff --git a/src/pip/_internal/operations/build/wheel.py b/src/pip/_internal/operations/build/wheel.py index 83fac3b3187..903bd7a0567 100644 --- a/src/pip/_internal/operations/build/wheel.py +++ b/src/pip/_internal/operations/build/wheel.py @@ -1,6 +1,6 @@ import logging import os -from typing import List, Optional +from typing import Optional from pip._vendor.pep517.wrappers import Pep517HookCaller @@ -13,7 +13,6 @@ def build_wheel_pep517( name, # type: str backend, # type: Pep517HookCaller metadata_directory, # type: str - build_options, # type: List[str] tempd, # type: str ): # type: (...) -> Optional[str] @@ -22,11 +21,6 @@ def build_wheel_pep517( Returns path to wheel if successfully built. Otherwise, returns None. """ assert metadata_directory is not None - if build_options: - # PEP 517 does not support --build-options - logger.error('Cannot build wheel for %s using PEP 517 when ' - '--build-option is present', name) - return None try: logger.debug('Destination directory: %s', tempd) diff --git a/src/pip/_internal/wheel_builder.py b/src/pip/_internal/wheel_builder.py index 4b2f6d5d4df..92f172bca16 100644 --- a/src/pip/_internal/wheel_builder.py +++ b/src/pip/_internal/wheel_builder.py @@ -244,11 +244,18 @@ def _build_one_inside_env( if req.use_pep517: assert req.metadata_directory assert req.pep517_backend + if global_options: + logger.warning( + 'Ignoring --global-option when building %s using PEP 517', req.name + ) + if build_options: + logger.warning( + 'Ignoring --build-option when building %s using PEP 517', req.name + ) wheel_path = build_wheel_pep517( name=req.name, backend=req.pep517_backend, metadata_directory=req.metadata_directory, - build_options=build_options, tempd=temp_dir.path, ) else: diff --git a/tests/functional/test_pep517.py b/tests/functional/test_pep517.py index a747b8a0756..4458a7ad56e 100644 --- a/tests/functional/test_pep517.py +++ b/tests/functional/test_pep517.py @@ -263,7 +263,20 @@ def test_pep517_and_build_options(script, tmpdir, data, common_wheels): '--build-option', 'foo', '-f', common_wheels, project_dir, - expect_error=True ) - assert 'Cannot build wheel' in result.stderr - assert 'when --build-option is present' in result.stderr + assert 'Ignoring --build-option when building' in result.stderr + assert 'using PEP 517' in result.stderr + + +@pytest.mark.network +def test_pep517_and_global_options(script, tmpdir, data, common_wheels): + """Backend generated requirements are installed in the build env""" + project_dir, name = make_pyproject_with_setup(tmpdir) + result = script.pip( + 'wheel', '--wheel-dir', tmpdir, + '--global-option', 'foo', + '-f', common_wheels, + project_dir, + ) + assert 'Ignoring --global-option when building' in result.stderr + assert 'using PEP 517' in result.stderr