Skip to content

Commit 30af807

Browse files
authored
Merge pull request #11117 from q0w/opt-check
Opt to check build dependencies
2 parents 923cb5a + 3166157 commit 30af807

File tree

13 files changed

+66
-6
lines changed

13 files changed

+66
-6
lines changed

news/11116.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Change the build environment dependency checking to be opt-in.

src/pip/_internal/cli/cmdoptions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,15 @@ 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-dependencies",
755+
dest="check_build_deps",
756+
action="store_true",
757+
default=False,
758+
help="Check the build dependencies when PEP517 is used.",
759+
)
760+
752761

753762
def _handle_no_use_pep517(
754763
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

0 commit comments

Comments
 (0)