65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
"""Add one reviewed definition; preserve every other review object exactly."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
|
|
from build_definition import OUT, PATHS, REPO, build, canonical
|
|
|
|
BASE = "9db8857228fed24724c7e5ef4d0b71df74e817b3"
|
|
RESOURCE = "calliope-backend/src/calliope/comfyui/source_reviews.json"
|
|
|
|
|
|
def build_all():
|
|
previous = json.loads(subprocess.check_output(["git", "show", f"{BASE}:{RESOURCE}"], cwd=REPO))
|
|
reviews = json.loads(json.dumps(previous, ensure_ascii=False))
|
|
for i, path in enumerate(PATHS):
|
|
block = build(i)
|
|
assert reviews[path]["source_sha"] == block["source_sha1"]
|
|
assert "fixed_version_document" not in previous[path]
|
|
reviews[path]["fixed_version_document"] = block
|
|
return reviews, previous
|
|
|
|
|
|
def main():
|
|
current = json.loads((REPO / RESOURCE).read_bytes())
|
|
reviews, previous = build_all()
|
|
(REPO / RESOURCE).write_text(json.dumps(reviews, ensure_ascii=False, indent=2) + "\n")
|
|
pins = {}
|
|
for i, path in enumerate(PATHS):
|
|
block = reviews[path]["fixed_version_document"]
|
|
pins[path] = hashlib.sha256(canonical(block)).hexdigest()
|
|
(OUT / f"definition-{i}.json").write_text(
|
|
json.dumps(block, ensure_ascii=False, indent=2) + "\n"
|
|
)
|
|
# Explicit maintenance of the code-owned allowlist, never trust runtime caller digests.
|
|
module = REPO / "calliope-backend/src/calliope/comfyui/fixed_document.py"
|
|
text = module.read_text()
|
|
for path, digest in pins.items():
|
|
old_block = current[path].get("fixed_version_document")
|
|
old_digest = hashlib.sha256(canonical(old_block)).hexdigest() if old_block else None
|
|
if old_digest and old_digest in text:
|
|
text = text.replace(old_digest, digest)
|
|
elif digest in text:
|
|
pass
|
|
else:
|
|
text = text.replace(
|
|
"DEFINITIONS = {",
|
|
"DEFINITIONS = {\n (\n"
|
|
+ "".join(
|
|
" " + repr(path[i : i + 40]) + "\n" for i in range(0, len(path), 40)
|
|
)
|
|
+ " ): "
|
|
+ repr(digest)
|
|
+ ",",
|
|
)
|
|
module.write_text(text)
|
|
(OUT / "pins.json").write_text(json.dumps(pins, ensure_ascii=False, indent=2) + "\n")
|
|
print("PASS one definition; other 155 reviews and old 21 blocks unchanged")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|