Skip to content

Commit 4c5f8fd

Browse files
authored
Merge pull request #191 from pfmoore/gen_all_zipapps
Generate versioned zipapps for all supported pip versions
2 parents 233a34e + d9f7d92 commit 4c5f8fd

15 files changed

+28
-5
lines changed

noxfile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def check(session):
4141
@nox.session
4242
def generate(session):
4343
"""Update the scripts, to the latest versions."""
44-
session.install("packaging", "requests", "cachecontrol[filecache]", "rich", "pkg_metadata")
44+
session.install("packaging", "requests", "urllib3<2", "cachecontrol[filecache]", "rich", "pkg_metadata")
4545

4646
public = Path("public")
4747
shutil.rmtree(public, ignore_errors=True)

public/zipapp/pip-22.3.1.pyz

1.93 MB
Binary file not shown.

public/zipapp/pip-22.3.pyz

1.93 MB
Binary file not shown.

public/zipapp/pip-23.0.1.pyz

1.94 MB
Binary file not shown.

public/zipapp/pip-23.0.pyz

1.94 MB
Binary file not shown.

public/zipapp/pip-23.1.1.pyz

1.94 MB
Binary file not shown.

public/zipapp/pip-23.1.2.pyz

1.94 MB
Binary file not shown.

public/zipapp/pip-23.1.pyz

1.94 MB
Binary file not shown.

public/zipapp/pip-23.2.1.pyz

1.96 MB
Binary file not shown.

public/zipapp/pip-23.2.pyz

1.96 MB
Binary file not shown.

public/zipapp/pip-23.3.1.pyz

1.98 MB
Binary file not shown.

public/zipapp/pip-23.3.2.pyz

1.98 MB
Binary file not shown.

public/zipapp/pip-23.3.pyz

1.98 MB
Binary file not shown.

public/zipapp/pip-24.0.pyz

1.98 MB
Binary file not shown.

scripts/generate.py

+27-4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@
6363
},
6464
}
6565

66+
# This is the oldest version of pip we will distribute as a zipapp.
67+
# Pip 22.3 was the first pip to support being shipped as a zipapp,
68+
# but we may in future choose to increase this value to stop shipping
69+
# very old pip versions (if we find the overhead of shipping every
70+
# version is too high).
71+
OLDEST_ZIPAPP = Version("22.3")
72+
6673
# Scripts here use the "moved" template, with the key being the file path and
6774
# value being the path on bootstrap.pypa.io that the user should use instead.
6875
#
@@ -278,12 +285,18 @@ def generate_moved(destination: str, *, location: str, console: Console):
278285
f.write(rendered_template)
279286

280287

288+
def zipapp_location(pip_version: Version) -> Path:
289+
zipapp_dir = Path("public/zipapp")
290+
# Ensure that the zipapp directory is present
291+
zipapp_dir.mkdir(exist_ok=True)
292+
return zipapp_dir / f"pip-{pip_version}.pyz"
293+
294+
281295
def generate_zipapp(pip_version: Version, *, console: Console, pip_versions: Dict[Version, Tuple[str, str]]) -> None:
282296
wheel_url, wheel_hash = pip_versions[pip_version]
283297
console.log(f" Downloading [green]{Path(wheel_url).name}")
284298
original_wheel = download_wheel(wheel_url, wheel_hash)
285-
286-
zipapp_name = "public/pip.pyz"
299+
zipapp_name = zipapp_location(pip_version)
287300

288301
console.log(f" Creating [green]{zipapp_name}")
289302
with open(zipapp_name, "wb") as f:
@@ -332,6 +345,12 @@ def generate_zipapp(pip_version: Version, *, console: Console, pip_versions: Dic
332345
dest.writestr(main_info, zipapp_main)
333346

334347

348+
def generate_zipapp_for_current(pip_version: Version) -> None:
349+
zipapp_name = zipapp_location(pip_version)
350+
unversioned_name = "public/pip.pyz"
351+
shutil.copy(zipapp_name, unversioned_name)
352+
353+
335354
def main() -> None:
336355
console = Console()
337356
with console.status("Fetching pip versions..."):
@@ -353,8 +372,12 @@ def main() -> None:
353372
status.update(f"Working on [magenta]{legacy}")
354373
generate_moved(legacy, console=console, location=current)
355374

356-
with console.status("Generating zipapp...") as status:
357-
generate_zipapp(max(pip_versions), console=console, pip_versions=pip_versions)
375+
with console.status("Generating zipapps...") as status:
376+
for version in pip_versions:
377+
if version < OLDEST_ZIPAPP:
378+
continue
379+
generate_zipapp(version, console=console, pip_versions=pip_versions)
380+
generate_zipapp_for_current(max(pip_versions))
358381

359382

360383
if __name__ == "__main__":

0 commit comments

Comments
 (0)