From 69dee6286d06b779dc51087a119448b1a94aba76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 4 Apr 2021 14:37:23 +0200 Subject: [PATCH 1/2] PEP 517 + --build-option is now a warning We warn instead of erroring out when --build-option is present when doing a PEP 517 build. There is no strong reason to error out, and this will avoid backward compatibility issues when we support build options in requirement files and installation. --- news/9774.feature.rst | 2 ++ src/pip/_internal/operations/build/wheel.py | 8 +------- src/pip/_internal/wheel_builder.py | 5 ++++- tests/functional/test_pep517.py | 5 ++--- 4 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 news/9774.feature.rst diff --git a/news/9774.feature.rst b/news/9774.feature.rst new file mode 100644 index 00000000000..298362f8be2 --- /dev/null +++ b/news/9774.feature.rst @@ -0,0 +1,2 @@ +Warn instead of erroring out when doing a PEP 517 build in presence of +``--build-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..c2cbf1eebb7 100644 --- a/src/pip/_internal/wheel_builder.py +++ b/src/pip/_internal/wheel_builder.py @@ -244,11 +244,14 @@ def _build_one_inside_env( if req.use_pep517: assert req.metadata_directory assert req.pep517_backend + 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..ae747d9fda1 100644 --- a/tests/functional/test_pep517.py +++ b/tests/functional/test_pep517.py @@ -263,7 +263,6 @@ 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 From 7c6ee48b041972e067bf2f1211e25959f8b95982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 4 Apr 2021 14:39:24 +0200 Subject: [PATCH 2/2] PEP 517 build in presence of --global-option emits a warning So these are not ignored silently. --- news/9774.feature.rst | 3 ++- src/pip/_internal/wheel_builder.py | 4 ++++ tests/functional/test_pep517.py | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/news/9774.feature.rst b/news/9774.feature.rst index 298362f8be2..8baac5e967f 100644 --- a/news/9774.feature.rst +++ b/news/9774.feature.rst @@ -1,2 +1,3 @@ Warn instead of erroring out when doing a PEP 517 build in presence of -``--build-option``. +``--build-option``. Warn when doing a PEP 517 build in presence of +``--global-option``. diff --git a/src/pip/_internal/wheel_builder.py b/src/pip/_internal/wheel_builder.py index c2cbf1eebb7..92f172bca16 100644 --- a/src/pip/_internal/wheel_builder.py +++ b/src/pip/_internal/wheel_builder.py @@ -244,6 +244,10 @@ 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 diff --git a/tests/functional/test_pep517.py b/tests/functional/test_pep517.py index ae747d9fda1..4458a7ad56e 100644 --- a/tests/functional/test_pep517.py +++ b/tests/functional/test_pep517.py @@ -266,3 +266,17 @@ def test_pep517_and_build_options(script, tmpdir, data, common_wheels): ) 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