Skip to content

Commit 2eb7e88

Browse files
committed
Patch certifi to use environ for passing cert
1 parent 40d0529 commit 2eb7e88

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/pip/_vendor/certifi/core.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,21 @@
88
"""
99
import os
1010

11+
12+
class _PipPatchedCertificate(Exception):
13+
pass
14+
15+
1116
try:
17+
# Return a certificate file on disk for a standalone pip zipapp running in
18+
# an isolated build environment to use. Passing --cert to the standalone
19+
# pip does not work since requests calls where() unconditionally on import.
20+
_PIP_STANDALONE_CERT = os.environ.get("_PIP_STANDALONE_CERT")
21+
if _PIP_STANDALONE_CERT:
22+
def where():
23+
return _PIP_STANDALONE_CERT
24+
raise _PipPatchedCertificate()
25+
1226
from importlib.resources import path as get_path, read_text
1327

1428
_CACERT_CTX = None
@@ -38,6 +52,8 @@ def where():
3852

3953
return _CACERT_PATH
4054

55+
except _PipPatchedCertificate:
56+
pass
4157

4258
except ImportError:
4359
# This fallback will work for Python versions prior to 3.7 that lack the

tools/vendoring/patches/certifi.patch

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
11
diff --git a/src/pip/_vendor/certifi/core.py b/src/pip/_vendor/certifi/core.py
2-
index 5d2b8cd32..8987449f6 100644
2+
index 5d2b8cd32..b8140cf1a 100644
33
--- a/src/pip/_vendor/certifi/core.py
44
+++ b/src/pip/_vendor/certifi/core.py
5-
@@ -33,7 +33,7 @@ try:
5+
@@ -8,7 +8,21 @@ This module returns the installation location of cacert.pem or its contents.
6+
"""
7+
import os
8+
9+
+
10+
+class _PipPatchedCertificate(Exception):
11+
+ pass
12+
+
13+
+
14+
try:
15+
+ # Return a certificate file on disk for a standalone pip zipapp running in
16+
+ # an isolated build environment to use. Passing --cert to the standalone
17+
+ # pip does not work since requests calls where() unconditionally on import.
18+
+ _PIP_STANDALONE_CERT = os.environ.get("_PIP_STANDALONE_CERT")
19+
+ if _PIP_STANDALONE_CERT:
20+
+ def where():
21+
+ return _PIP_STANDALONE_CERT
22+
+ raise _PipPatchedCertificate()
23+
+
24+
from importlib.resources import path as get_path, read_text
25+
26+
_CACERT_CTX = None
27+
@@ -33,11 +47,13 @@ try:
628
# We also have to hold onto the actual context manager, because
729
# it will do the cleanup whenever it gets garbage collected, so
830
# we will also store that at the global level as well.
931
- _CACERT_CTX = get_path("certifi", "cacert.pem")
1032
+ _CACERT_CTX = get_path("pip._vendor.certifi", "cacert.pem")
1133
_CACERT_PATH = str(_CACERT_CTX.__enter__())
12-
34+
1335
return _CACERT_PATH
36+
37+
+except _PipPatchedCertificate:
38+
+ pass
39+
40+
except ImportError:
41+
# This fallback will work for Python versions prior to 3.7 that lack the

0 commit comments

Comments
 (0)