Skip to content

Commit

Permalink
Merge pull request #9774 from sbidoul/warn-on-pep517-build-global-option
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Apr 14, 2021
2 parents e6a65fc + 7c6ee48 commit d4c32a2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
3 changes: 3 additions & 0 deletions news/9774.feature.rst
Original file line number Diff line number Diff line change
@@ -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``.
8 changes: 1 addition & 7 deletions src/pip/_internal/operations/build/wheel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os
from typing import List, Optional
from typing import Optional

from pip._vendor.pep517.wrappers import Pep517HookCaller

Expand All @@ -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]
Expand All @@ -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)

Expand Down
9 changes: 8 additions & 1 deletion src/pip/_internal/wheel_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 16 additions & 3 deletions tests/functional/test_pep517.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d4c32a2

Please sign in to comment.