Skip to content

Commit

Permalink
Plumb through venv build isolation
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Dec 11, 2022
1 parent f54dec8 commit 9c49e9e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/pip/_internal/build_env/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
from pip._internal.build_env._base import BuildEnvironment, get_runnable_pip
from pip._internal.build_env._custom import CustomBuildEnvironment
from pip._internal.build_env._noop import NoOpBuildEnvironment
from pip._internal.build_env._venv import VenvBuildEnvironment

BuildIsolationMode = Literal["noop", "custom", "venv"]
6 changes: 4 additions & 2 deletions src/pip/_internal/build_env/_noop.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from types import TracebackType
from typing import List, Optional, Type, Iterable
from typing import TYPE_CHECKING, Iterable, List, Optional, Type

from pip._internal.build_env import BuildEnvironment
from pip._internal.index.package_finder import PackageFinder

if TYPE_CHECKING:
from pip._internal.index.package_finder import PackageFinder


class NoOpBuildEnvironment(BuildEnvironment):
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ def check_list_path_option(options: Values) -> None:
"fast-deps",
"truststore",
"no-binary-enable-wheel-cache",
"venv-isolation",
],
help="Enable new functionality, that may be backward incompatible.",
)
Expand Down
2 changes: 2 additions & 0 deletions src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ def make_requirement_preparer(

if not options.build_isolation:
build_isolation: BuildIsolationMode = "noop"
elif "venv-isolation" in options.features_enabled:
build_isolation = "venv"
else:
build_isolation = "custom"

Expand Down
17 changes: 13 additions & 4 deletions src/pip/_internal/distributions/sdist.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import logging
from typing import Iterable, Set, Tuple

from pip._internal.build_env import BuildIsolationMode, CustomBuildEnvironment
from pip._internal.build_env import (
BuildIsolationMode,
CustomBuildEnvironment,
VenvBuildEnvironment,
)
from pip._internal.distributions.base import AbstractDistribution
from pip._internal.exceptions import InstallationError
from pip._internal.index.package_finder import PackageFinder
Expand Down Expand Up @@ -35,7 +39,7 @@ def prepare_distribution_metadata(
if should_isolate:
# Setup an isolated environment and install the build backend static
# requirements in it.
self._prepare_build_backend(finder)
self._prepare_build_backend(finder, build_isolation)
# Check that if the requirement is editable, it either supports PEP 660 or
# has a setup.py or a setup.cfg. This cannot be done earlier because we need
# to setup the build backend to verify it supports build_editable, nor can
Expand All @@ -60,13 +64,18 @@ def prepare_distribution_metadata(
self._raise_missing_reqs(missing)
self.req.prepare_metadata()

def _prepare_build_backend(self, finder: PackageFinder) -> None:
def _prepare_build_backend(
self, finder: PackageFinder, build_isolation: BuildIsolationMode
) -> None:
# Isolate in a BuildEnvironment and install the build-time
# requirements.
pyproject_requires = self.req.pyproject_requires
assert pyproject_requires is not None

self.req.build_env = CustomBuildEnvironment()
if build_isolation == "custom":
self.req.build_env = CustomBuildEnvironment()
else:
self.req.build_env = VenvBuildEnvironment()
self.req.build_env.install_requirements(
finder, pyproject_requires, "overlay", kind="build dependencies"
)
Expand Down

0 comments on commit 9c49e9e

Please sign in to comment.