MCPcopy
hub / github.com/pex-tool/pex / fingerprint_cache_inputs

Function fingerprint_cache_inputs

scripts/build-cache-image.py:59–77  ·  view source on GitHub ↗
(image_id: str | None = None)

Source from the content-addressed store, hash-verified

57
58
59def fingerprint_cache_inputs(image_id: str | None = None) -> str:
60 def iter_files(path: Path) -> Iterator[Path]:
61 if path.is_dir():
62 for root, dirs, files in os.walk(path):
63 for f in files:
64 yield Path(root) / f
65 else:
66 yield path
67
68 hashes = {
69 str(path): hashlib.sha256(path.read_bytes()).hexdigest()
70 for path in sorted(
71 itertools.chain.from_iterable(iter_files(cache_input) for cache_input in _CACHE_INPUTS)
72 )
73 }
74
75 return hashlib.sha256(
76 json.dumps({"image_id": image_id, "hashes": hashes}, sort_keys=True).encode("utf-8")
77 ).hexdigest()
78
79
80def export_tarball_path(sub_image: str | None = None) -> Path:

Callers 1

build_cache_imageFunction · 0.85

Calls 3

iter_filesFunction · 0.70
hexdigestMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected