Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions news/9878.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix Python 3.6 compatibility when a PEP 517 build requirement itself needs to be
built in an isolated environment.
16 changes: 12 additions & 4 deletions src/pip/_internal/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,17 @@ def install_requirements(
prefix.setup = True
if not requirements:
return
with _create_standalone_pip() as standalone_pip:
with contextlib.ExitStack() as ctx:
# TODO: Remove this block when dropping 3.6 support. Python 3.6
# lacks importlib.resources and pep517 has issues loading files in
# a zip, so we fallback to the "old" method by adding the current
# pip directory to the child process's sys.path.
if sys.version_info < (3, 7):
pip_runnable = os.path.dirname(pip_location)
else:
pip_runnable = ctx.enter_context(_create_standalone_pip())
self._install_requirements(
standalone_pip,
pip_runnable,
finder,
requirements,
prefix,
Expand All @@ -198,14 +206,14 @@ def install_requirements(

@staticmethod
def _install_requirements(
standalone_pip: str,
pip_runnable: str,
finder: "PackageFinder",
requirements: Iterable[str],
prefix: _Prefix,
message: str,
) -> None:
args = [
sys.executable, standalone_pip, 'install',
sys.executable, pip_runnable, 'install',
'--ignore-installed', '--no-user', '--prefix', prefix.path,
'--no-warn-script-location',
] # type: List[str]
Expand Down