| 486 | |
| 487 | |
| 488 | def 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 | |
| 513 | def extract_python_archive( |