Skip to content

Commit 999b121

Browse files
authored
Merge pull request #9883 from uranusjr/isolated-pip-py36-compat
Fallback to self-invoke via directory on 3.6
2 parents 7a77484 + f884203 commit 999b121

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

news/9878.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix Python 3.6 compatibility when a PEP 517 build requirement itself needs to be
2+
built in an isolated environment.

src/pip/_internal/build_env.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,17 @@ def install_requirements(
187187
prefix.setup = True
188188
if not requirements:
189189
return
190-
with _create_standalone_pip() as standalone_pip:
190+
with contextlib.ExitStack() as ctx:
191+
# TODO: Remove this block when dropping 3.6 support. Python 3.6
192+
# lacks importlib.resources and pep517 has issues loading files in
193+
# a zip, so we fallback to the "old" method by adding the current
194+
# pip directory to the child process's sys.path.
195+
if sys.version_info < (3, 7):
196+
pip_runnable = os.path.dirname(pip_location)
197+
else:
198+
pip_runnable = ctx.enter_context(_create_standalone_pip())
191199
self._install_requirements(
192-
standalone_pip,
200+
pip_runnable,
193201
finder,
194202
requirements,
195203
prefix,
@@ -198,14 +206,14 @@ def install_requirements(
198206

199207
@staticmethod
200208
def _install_requirements(
201-
standalone_pip: str,
209+
pip_runnable: str,
202210
finder: "PackageFinder",
203211
requirements: Iterable[str],
204212
prefix: _Prefix,
205213
message: str,
206214
) -> None:
207215
args = [
208-
sys.executable, standalone_pip, 'install',
216+
sys.executable, pip_runnable, 'install',
209217
'--ignore-installed', '--no-user', '--prefix', prefix.path,
210218
'--no-warn-script-location',
211219
] # type: List[str]

0 commit comments

Comments
 (0)