Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rework arguments
  • Loading branch information
ichard26 committed Jul 29, 2025
commit 20f7b67e12e07ac9a07c31481a895a93482790d1
50 changes: 18 additions & 32 deletions src/pip/_internal/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from contextlib import AbstractContextManager, nullcontext
from functools import partial
from io import StringIO
from optparse import Values
from types import TracebackType
from typing import TYPE_CHECKING, Protocol, TypedDict

Expand Down Expand Up @@ -268,24 +267,25 @@ class InprocessBuildEnvironmentInstaller:
Options are inherited from the parent install command unless
they don't make sense for build dependencies (in which case, they
are hard-coded, see comments below).

NOTE: This can only be used with the resolvelib resolver.
"""

def __init__(
self,
finder: PackageFinder,
session: PipSession,
build_tracker: BuildTracker,
# TODO: maybe inheriting this is not the best idea?
build_dir: str,
verbosity: int,
options: Values,
resume_retries: int,
cache_dir: str,
ignore_requires_python: bool,
) -> None:
from pip._internal.cache import WheelCache
from pip._internal.operations.prepare import RequirementPreparer

self.finder = finder
self.options = options
self._ignore_requires_python = ignore_requires_python

self._preparer = RequirementPreparer(
build_isolation_installer=self,
Expand All @@ -295,11 +295,10 @@ def __init__(
build_dir=build_dir,
build_tracker=build_tracker,
verbosity=verbosity,
resume_retries=options.resume_retries,
# This probably shouldn't be inherited, but it won't be used
# anyway as it only applies to editable requirements.
src_dir=options.src_dir,
# Hard-coded options (they should NOT be inherited).
resume_retries=resume_retries,
# This is irrelevant as it only applies to editable requirements.
src_dir="",
# Hard-coded options (that should NOT be inherited).
download_dir=None,
build_isolation=True,
check_build_deps=False,
Expand All @@ -311,7 +310,7 @@ def __init__(
lazy_wheel=False,
legacy_resolver=False,
)
self._wheel_cache = WheelCache(options.cache_dir)
self._wheel_cache = WheelCache(cache_dir)

def install(
self,
Expand Down Expand Up @@ -362,16 +361,8 @@ def _install_impl(self, requirements: Iterable[str], prefix: _Prefix) -> None:

ireqs = []
for req in requirements:
ireq = install_req_from_line(
req,
# I have no idea whether inheriting this is useful, but whatever.
isolated=self.options.isolated_mode,
# Hard-coded options (they should NOT be inherited).
comes_from=None,
use_pep517=True,
user_supplied=True,
config_settings={},
)
# TODO: maybe don't enforce PEP 517 for nested builds?
ireq = install_req_from_line(req, use_pep517=True, user_supplied=True)
ireqs.append(ireq)

resolver = self._make_resolver()
Expand All @@ -386,7 +377,7 @@ def _install_impl(self, requirements: Iterable[str], prefix: _Prefix) -> None:
reqs_to_build,
wheel_cache=self._wheel_cache,
verify=True,
# Hard-coded options (they should NOT be inherited).
# Hard-coded options (that should NOT be inherited).
build_options=[],
global_options=[],
)
Expand All @@ -397,7 +388,7 @@ def _install_impl(self, requirements: Iterable[str], prefix: _Prefix) -> None:
installed = install_given_reqs(
to_install,
prefix=prefix.path,
# Hard-coded options (they should NOT be inherited).
# Hard-coded options (that should NOT be inherited).
global_options=[],
root=None,
home=None,
Expand All @@ -410,7 +401,7 @@ def _install_impl(self, requirements: Iterable[str], prefix: _Prefix) -> None:
progress_bar="off",
)

env = get_environment(prefix.lib_dirs)
env = get_environment(list(prefix.lib_dirs))
if summary := installed_packages_summary(installed, env):
logger.info(summary)

Expand All @@ -421,19 +412,14 @@ def _make_resolver(self) -> BaseResolver:
from pip._internal.req.constructors import install_req_from_req_string
from pip._internal.resolution.resolvelib.resolver import Resolver

make_install_req = partial(
install_req_from_req_string,
isolated=self.options.isolated_mode,
use_pep517=True,
)
return Resolver(
make_install_req=make_install_req,
make_install_req=partial(install_req_from_req_string, use_pep517=True),
# Inherited state.
preparer=self._preparer,
finder=self.finder,
wheel_cache=self._wheel_cache,
ignore_requires_python=self.options.ignore_requires_python,
# Hard-coded options (they should NOT be inherited).
ignore_requires_python=self._ignore_requires_python,
# Hard-coded options (that should NOT be inherited).
use_user_site=False,
ignore_dependencies=False,
ignore_installed=True,
Expand Down
9 changes: 8 additions & 1 deletion src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@ def make_requirement_preparer(
env_installer: BuildEnvironmentInstaller
if "inprocess-build-deps" in options.features_enabled:
env_installer = InprocessBuildEnvironmentInstaller(
finder, session, build_tracker, temp_build_dir_path, verbosity, options
finder=finder,
session=session,
build_tracker=build_tracker,
build_dir=temp_build_dir_path,
verbosity=verbosity,
resume_retries=options.resume_retries,
cache_dir=options.cache_dir,
ignore_requires_python=options.ignore_requires_python,
)
else:
env_installer = SubprocessBuildEnvironmentInstaller(
Expand Down