Skip to content

Commit

Permalink
Handle zipapp inception
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Apr 2, 2021
1 parent 9cab77e commit bba1226
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/pip/_internal/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,19 @@ def __init__(self, path):
def _create_standalone_pip() -> Iterator[str]:
"""Create a "standalone pip" zip file.
The zip file contains a (modified) copy of the pip currently running.
The zip file's content is identical to the currently-running pip.
It will be used to install requirements into the build environment.
"""
source = pathlib.Path(pip_location).resolve().parent

# Return the current instance if it is already a zip file. This can happen
# if a PEP 517 requirement is an sdist itself.
if not source.is_dir() and source.parent.name == "__env_pip__.zip":
yield str(source)
return

with TempDirectory(kind="standalone-pip") as tmp_dir:
pip_zip = os.path.join(tmp_dir.path, "pip.zip")
pip_zip = os.path.join(tmp_dir.path, "__env_pip__.zip")
with zipfile.ZipFile(pip_zip, "w") as zf:
for child in source.rglob("*"):
zf.write(child, child.relative_to(source.parent).as_posix())
Expand Down

0 comments on commit bba1226

Please sign in to comment.