MCPcopy
hub / github.com/astral-sh/python-build-standalone / compress_python_archive

Function compress_python_archive

pythonbuild/utils.py:488–510  ·  view source on GitHub ↗
(
    source_path: pathlib.Path, dist_path: pathlib.Path, basename: str
)

Source from the content-addressed store, hash-verified

486
487
488def compress_python_archive(
489 source_path: pathlib.Path, dist_path: pathlib.Path, basename: str
490):
491 dest_path = dist_path / ("%s.tar.zst" % basename)
492 temp_path = dist_path / ("%s.tar.zst.tmp" % basename)
493
494 print("compressing Python archive to %s" % dest_path)
495
496 try:
497 with source_path.open("rb") as ifh, temp_path.open("wb") as ofh:
498 params = zstandard.ZstdCompressionParameters.from_level(
499 22, strategy=zstandard.STRATEGY_BTULTRA2
500 )
501 cctx = zstandard.ZstdCompressor(compression_params=params)
502 cctx.copy_stream(ifh, ofh, source_path.stat().st_size)
503
504 temp_path.rename(dest_path)
505 finally:
506 temp_path.unlink(missing_ok=True)
507
508 print("%s has SHA256 %s" % (dest_path, hash_path(dest_path)))
509
510 return dest_path
511
512
513def extract_python_archive(

Callers 2

mainFunction · 0.90
mainFunction · 0.90

Calls 1

hash_pathFunction · 0.85

Tested by

no test coverage detected