Skip to content

Commit

Permalink
Opt to check build dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
q0w committed May 13, 2022
1 parent d0c89a1 commit 3166157
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/11116.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change the build environment dependency checking to be opt-in.
9 changes: 9 additions & 0 deletions src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,15 @@ def _handle_no_cache_dir(
"if this option is used.",
)

check_build_deps: Callable[..., Option] = partial(
Option,
"--check-build-dependencies",
dest="check_build_deps",
action="store_true",
default=False,
help="Check the build dependencies when PEP517 is used.",
)


def _handle_no_use_pep517(
option: Option, opt: str, value: str, parser: OptionParser
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def make_requirement_preparer(
src_dir=options.src_dir,
download_dir=download_dir,
build_isolation=options.build_isolation,
check_build_deps=options.check_build_deps,
build_tracker=build_tracker,
session=session,
progress_bar=options.progress_bar,
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/commands/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def add_options(self) -> None:
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
self.cmd_opts.add_option(cmdoptions.use_pep517())
self.cmd_opts.add_option(cmdoptions.no_use_pep517())
self.cmd_opts.add_option(cmdoptions.check_build_deps())
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())

self.cmd_opts.add_option(
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def add_options(self) -> None:
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
self.cmd_opts.add_option(cmdoptions.use_pep517())
self.cmd_opts.add_option(cmdoptions.no_use_pep517())
self.cmd_opts.add_option(cmdoptions.check_build_deps())

self.cmd_opts.add_option(cmdoptions.config_settings())
self.cmd_opts.add_option(cmdoptions.install_options())
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/commands/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def add_options(self) -> None:
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
self.cmd_opts.add_option(cmdoptions.use_pep517())
self.cmd_opts.add_option(cmdoptions.no_use_pep517())
self.cmd_opts.add_option(cmdoptions.check_build_deps())
self.cmd_opts.add_option(cmdoptions.constraints())
self.cmd_opts.add_option(cmdoptions.editable())
self.cmd_opts.add_option(cmdoptions.requirements())
Expand Down
5 changes: 4 additions & 1 deletion src/pip/_internal/distributions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def get_metadata_distribution(self) -> BaseDistribution:

@abc.abstractmethod
def prepare_distribution_metadata(
self, finder: PackageFinder, build_isolation: bool
self,
finder: PackageFinder,
build_isolation: bool,
check_build_deps: bool,
) -> None:
raise NotImplementedError()
5 changes: 4 additions & 1 deletion src/pip/_internal/distributions/installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def get_metadata_distribution(self) -> BaseDistribution:
return self.req.satisfied_by

def prepare_distribution_metadata(
self, finder: PackageFinder, build_isolation: bool
self,
finder: PackageFinder,
build_isolation: bool,
check_build_deps: bool,
) -> None:
pass
9 changes: 7 additions & 2 deletions src/pip/_internal/distributions/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def get_metadata_distribution(self) -> BaseDistribution:
return self.req.get_dist()

def prepare_distribution_metadata(
self, finder: PackageFinder, build_isolation: bool
self,
finder: PackageFinder,
build_isolation: bool,
check_build_deps: bool,
) -> None:
# Load pyproject.toml, to determine whether PEP 517 is to be used
self.req.load_pyproject_toml()
Expand All @@ -43,7 +46,9 @@ def prepare_distribution_metadata(
self.req.isolated_editable_sanity_check()
# Install the dynamic build requirements.
self._install_build_reqs(finder)
elif self.req.use_pep517:
# Check if the current environment provides build dependencies
should_check_deps = self.req.use_pep517 and check_build_deps
if should_check_deps:
pyproject_requires = self.req.pyproject_requires
assert pyproject_requires is not None
conflicting, missing = self.req.build_env.check_requirements(
Expand Down
5 changes: 4 additions & 1 deletion src/pip/_internal/distributions/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def get_metadata_distribution(self) -> BaseDistribution:
return get_wheel_distribution(wheel, canonicalize_name(self.req.name))

def prepare_distribution_metadata(
self, finder: PackageFinder, build_isolation: bool
self,
finder: PackageFinder,
build_isolation: bool,
check_build_deps: bool,
) -> None:
pass
11 changes: 10 additions & 1 deletion src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ def _get_prepared_distribution(
build_tracker: BuildTracker,
finder: PackageFinder,
build_isolation: bool,
check_build_deps: bool,
) -> BaseDistribution:
"""Prepare a distribution for installation."""
abstract_dist = make_distribution_for_install_requirement(req)
with build_tracker.track(req):
abstract_dist.prepare_distribution_metadata(finder, build_isolation)
abstract_dist.prepare_distribution_metadata(
finder, build_isolation, check_build_deps
)
return abstract_dist.get_metadata_distribution()


Expand Down Expand Up @@ -199,6 +202,7 @@ def __init__(
download_dir: Optional[str],
src_dir: str,
build_isolation: bool,
check_build_deps: bool,
build_tracker: BuildTracker,
session: PipSession,
progress_bar: str,
Expand All @@ -225,6 +229,9 @@ def __init__(
# Is build isolation allowed?
self.build_isolation = build_isolation

# Should check build dependencies?
self.check_build_deps = check_build_deps

# Should hash-checking be required?
self.require_hashes = require_hashes

Expand Down Expand Up @@ -492,6 +499,7 @@ def _prepare_linked_requirement(
self.build_tracker,
self.finder,
self.build_isolation,
self.check_build_deps,
)
return dist

Expand Down Expand Up @@ -545,6 +553,7 @@ def prepare_editable_requirement(
self.build_tracker,
self.finder,
self.build_isolation,
self.check_build_deps,
)

req.check_if_exists(self.use_user_site)
Expand Down
22 changes: 22 additions & 0 deletions tests/functional/test_pep517.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,26 @@ def test_conflicting_pep517_backend_requirements(
assert result.returncode != 0 and msg in result.stderr, str(result)


def test_no_check_build_deps(
script: PipTestEnvironment, tmpdir: Path, data: TestData
) -> None:
project_dir = make_project(
tmpdir, requires=["simplewheel==2.0"], backend="test_backend"
)
script.pip(
"install",
"simplewheel==1.0",
"test_backend",
"--no-index",
"-f",
data.packages,
"-f",
data.backends,
)
result = script.pip("install", "--no-build-isolation", project_dir)
result.assert_installed("project", editable=False)


def test_validate_missing_pep517_backend_requirements(
script: PipTestEnvironment, tmpdir: Path, data: TestData
) -> None:
Expand All @@ -174,6 +194,7 @@ def test_validate_missing_pep517_backend_requirements(
"-f",
data.packages,
"--no-build-isolation",
"--check-build-dependencies",
project_dir,
expect_error=True,
)
Expand All @@ -199,6 +220,7 @@ def test_validate_conflicting_pep517_backend_requirements(
"-f",
data.packages,
"--no-build-isolation",
"--check-build-dependencies",
project_dir,
expect_error=True,
)
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_req.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def _basic_resolver(
src_dir=os.path.join(self.tempdir, "src"),
download_dir=None,
build_isolation=True,
check_build_deps=False,
build_tracker=tracker,
session=session,
progress_bar="on",
Expand Down

0 comments on commit 3166157

Please sign in to comment.