Skip to content

Commit 40d0529

Browse files
committed
Patch __init__.py instead of __main__.py
The standalone pip doesn't have a correct sys.path when __main__.py is invoked, and we'd be patching the wrong certifi at that point. The sys.path is guaranteed to be correct when __init__.py is loaded (otherwise we wouldn't be able to import it in the first place).
1 parent 0d183d3 commit 40d0529

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/pip/_internal/build_env.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def __init__(self, path):
4747
"""
4848

4949

50-
def _format_main_py(source: pathlib.Path) -> bytes:
51-
"""Create a patched pip/__main__.py for the standalone pip.
50+
def _format_init_py(source: pathlib.Path) -> bytes:
51+
"""Create a patched pip/__init__.py for the standalone pip.
5252
5353
The default ``certifi.where()`` relies on the certificate bundle being a
5454
real physical file on-disk, so we monkey-patch it to return the one used
@@ -76,8 +76,8 @@ def _create_standalone_pip() -> Iterator[str]:
7676
with zipfile.ZipFile(pip_zip, "w") as zf:
7777
for child in source.rglob("*"):
7878
arcname = child.relative_to(source.parent).as_posix()
79-
if arcname == "pip/__main__.py":
80-
zf.writestr(arcname, _format_main_py(child))
79+
if arcname == "pip/__init__.py":
80+
zf.writestr(arcname, _format_init_py(child))
8181
else:
8282
zf.write(child, arcname)
8383
yield os.path.join(pip_zip, "pip")

0 commit comments

Comments
 (0)