Skip to content

Commit dde1cf0

Browse files
committed
Opt to check build dependencies
1 parent d0c89a1 commit dde1cf0

File tree

12 files changed

+46
-6
lines changed

12 files changed

+46
-6
lines changed

src/pip/_internal/cli/cmdoptions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,16 @@ def _handle_no_cache_dir(
749749
"if this option is used.",
750750
)
751751

752+
check_build_deps: Callable[..., Option] = partial(
753+
Option,
754+
"--check-build-deps",
755+
"--check-build-dependencies",
756+
dest="check_build_deps",
757+
action="store_true",
758+
default=False,
759+
help="Check the build dependencies when PEP517 is used.",
760+
)
761+
752762

753763
def _handle_no_use_pep517(
754764
option: Option, opt: str, value: str, parser: OptionParser

src/pip/_internal/cli/req_command.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def make_requirement_preparer(
293293
src_dir=options.src_dir,
294294
download_dir=download_dir,
295295
build_isolation=options.build_isolation,
296+
check_build_deps=options.check_build_deps,
296297
build_tracker=build_tracker,
297298
session=session,
298299
progress_bar=options.progress_bar,

src/pip/_internal/commands/download.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def add_options(self) -> None:
4949
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
5050
self.cmd_opts.add_option(cmdoptions.use_pep517())
5151
self.cmd_opts.add_option(cmdoptions.no_use_pep517())
52+
self.cmd_opts.add_option(cmdoptions.check_build_deps())
5253
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
5354

5455
self.cmd_opts.add_option(

src/pip/_internal/commands/install.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def add_options(self) -> None:
189189
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
190190
self.cmd_opts.add_option(cmdoptions.use_pep517())
191191
self.cmd_opts.add_option(cmdoptions.no_use_pep517())
192+
self.cmd_opts.add_option(cmdoptions.check_build_deps())
192193

193194
self.cmd_opts.add_option(cmdoptions.config_settings())
194195
self.cmd_opts.add_option(cmdoptions.install_options())

src/pip/_internal/commands/wheel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def add_options(self) -> None:
5757
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
5858
self.cmd_opts.add_option(cmdoptions.use_pep517())
5959
self.cmd_opts.add_option(cmdoptions.no_use_pep517())
60+
self.cmd_opts.add_option(cmdoptions.check_build_deps())
6061
self.cmd_opts.add_option(cmdoptions.constraints())
6162
self.cmd_opts.add_option(cmdoptions.editable())
6263
self.cmd_opts.add_option(cmdoptions.requirements())

src/pip/_internal/distributions/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def get_metadata_distribution(self) -> BaseDistribution:
3131

3232
@abc.abstractmethod
3333
def prepare_distribution_metadata(
34-
self, finder: PackageFinder, build_isolation: bool
34+
self,
35+
finder: PackageFinder,
36+
build_isolation: bool,
37+
check_build_deps: bool,
3538
) -> None:
3639
raise NotImplementedError()

src/pip/_internal/distributions/installed.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def get_metadata_distribution(self) -> BaseDistribution:
1515
return self.req.satisfied_by
1616

1717
def prepare_distribution_metadata(
18-
self, finder: PackageFinder, build_isolation: bool
18+
self,
19+
finder: PackageFinder,
20+
build_isolation: bool,
21+
check_build_deps: bool,
1922
) -> None:
2023
pass

src/pip/_internal/distributions/sdist.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def get_metadata_distribution(self) -> BaseDistribution:
2222
return self.req.get_dist()
2323

2424
def prepare_distribution_metadata(
25-
self, finder: PackageFinder, build_isolation: bool
25+
self,
26+
finder: PackageFinder,
27+
build_isolation: bool,
28+
check_build_deps: bool,
2629
) -> None:
2730
# Load pyproject.toml, to determine whether PEP 517 is to be used
2831
self.req.load_pyproject_toml()
@@ -43,7 +46,9 @@ def prepare_distribution_metadata(
4346
self.req.isolated_editable_sanity_check()
4447
# Install the dynamic build requirements.
4548
self._install_build_reqs(finder)
46-
elif self.req.use_pep517:
49+
# Check if the current environment provides build dependencies
50+
should_check_deps = self.req.use_pep517 and check_build_deps
51+
if should_check_deps:
4752
pyproject_requires = self.req.pyproject_requires
4853
assert pyproject_requires is not None
4954
conflicting, missing = self.req.build_env.check_requirements(

src/pip/_internal/distributions/wheel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def get_metadata_distribution(self) -> BaseDistribution:
2626
return get_wheel_distribution(wheel, canonicalize_name(self.req.name))
2727

2828
def prepare_distribution_metadata(
29-
self, finder: PackageFinder, build_isolation: bool
29+
self,
30+
finder: PackageFinder,
31+
build_isolation: bool,
32+
check_build_deps: bool,
3033
) -> None:
3134
pass

src/pip/_internal/operations/prepare.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,14 @@ def _get_prepared_distribution(
5050
build_tracker: BuildTracker,
5151
finder: PackageFinder,
5252
build_isolation: bool,
53+
check_build_deps: bool,
5354
) -> BaseDistribution:
5455
"""Prepare a distribution for installation."""
5556
abstract_dist = make_distribution_for_install_requirement(req)
5657
with build_tracker.track(req):
57-
abstract_dist.prepare_distribution_metadata(finder, build_isolation)
58+
abstract_dist.prepare_distribution_metadata(
59+
finder, build_isolation, check_build_deps
60+
)
5861
return abstract_dist.get_metadata_distribution()
5962

6063

@@ -199,6 +202,7 @@ def __init__(
199202
download_dir: Optional[str],
200203
src_dir: str,
201204
build_isolation: bool,
205+
check_build_deps: bool,
202206
build_tracker: BuildTracker,
203207
session: PipSession,
204208
progress_bar: str,
@@ -225,6 +229,9 @@ def __init__(
225229
# Is build isolation allowed?
226230
self.build_isolation = build_isolation
227231

232+
# Should check build dependencies?
233+
self.check_build_deps = check_build_deps
234+
228235
# Should hash-checking be required?
229236
self.require_hashes = require_hashes
230237

@@ -492,6 +499,7 @@ def _prepare_linked_requirement(
492499
self.build_tracker,
493500
self.finder,
494501
self.build_isolation,
502+
self.check_build_deps,
495503
)
496504
return dist
497505

@@ -545,6 +553,7 @@ def prepare_editable_requirement(
545553
self.build_tracker,
546554
self.finder,
547555
self.build_isolation,
556+
self.check_build_deps,
548557
)
549558

550559
req.check_if_exists(self.use_user_site)

tests/functional/test_pep517.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def test_validate_missing_pep517_backend_requirements(
174174
"-f",
175175
data.packages,
176176
"--no-build-isolation",
177+
"--check-build-deps",
177178
project_dir,
178179
expect_error=True,
179180
)
@@ -199,6 +200,7 @@ def test_validate_conflicting_pep517_backend_requirements(
199200
"-f",
200201
data.packages,
201202
"--no-build-isolation",
203+
"--check-build-deps",
202204
project_dir,
203205
expect_error=True,
204206
)

tests/unit/test_req.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def _basic_resolver(
9191
src_dir=os.path.join(self.tempdir, "src"),
9292
download_dir=None,
9393
build_isolation=True,
94+
check_build_deps=False,
9495
build_tracker=tracker,
9596
session=session,
9697
progress_bar="on",

0 commit comments

Comments
 (0)