Skip to content

Commit 9cab77e

Browse files
committed
Pass in cert path with private environ
1 parent 2eb7e88 commit 9cab77e

File tree

1 file changed

+3
-28
lines changed

1 file changed

+3
-28
lines changed

src/pip/_internal/build_env.py

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,6 @@ def __init__(self, path):
4141
self.lib_dirs = get_prefixed_libs(path)
4242

4343

44-
_CERTIFI_WHERE_PATCH = """
45-
from pip._vendor import certifi
46-
certifi.where = lambda: {pem!r}
47-
"""
48-
49-
50-
def _format_init_py(source: pathlib.Path) -> bytes:
51-
"""Create a patched pip/__init__.py for the standalone pip.
52-
53-
The default ``certifi.where()`` relies on the certificate bundle being a
54-
real physical file on-disk, so we monkey-patch it to return the one used
55-
by this process instead.
56-
57-
Passing ``--cert`` to the standalone pip does not work, since ``requests``
58-
calls ``where()`` unconditionally on import.
59-
"""
60-
with source.open("rb") as f:
61-
content = f.read()
62-
patch = _CERTIFI_WHERE_PATCH.format(pem=where()).encode("utf-8")
63-
return patch + content
64-
65-
6644
@contextlib.contextmanager
6745
def _create_standalone_pip() -> Iterator[str]:
6846
"""Create a "standalone pip" zip file.
@@ -75,11 +53,7 @@ def _create_standalone_pip() -> Iterator[str]:
7553
pip_zip = os.path.join(tmp_dir.path, "pip.zip")
7654
with zipfile.ZipFile(pip_zip, "w") as zf:
7755
for child in source.rglob("*"):
78-
arcname = child.relative_to(source.parent).as_posix()
79-
if arcname == "pip/__init__.py":
80-
zf.writestr(arcname, _format_init_py(child))
81-
else:
82-
zf.write(child, arcname)
56+
zf.write(child, child.relative_to(source.parent).as_posix())
8357
yield os.path.join(pip_zip, "pip")
8458

8559

@@ -253,8 +227,9 @@ def _install_requirements(
253227
args.append('--prefer-binary')
254228
args.append('--')
255229
args.extend(requirements)
230+
extra_environ = {"_PIP_STANDALONE_CERT": where()}
256231
with open_spinner(message) as spinner:
257-
call_subprocess(args, spinner=spinner)
232+
call_subprocess(args, spinner=spinner, extra_environ=extra_environ)
258233

259234

260235
class NoOpBuildEnvironment(BuildEnvironment):

0 commit comments

Comments
 (0)