Files
aigc-home/docs/hel-892/rtx-video-document-evidence/fetch_sources.py
T

68 lines
2.4 KiB
Python

"Bounded static text retrieval at the already pinned core/frontend commits."
import hashlib
import json
import urllib.request
from pathlib import Path
OUT = Path(__file__).resolve().parent
REF = OUT.parent / "rtx-video-reference"
OLD = OUT.parent / "rtx-reference"
FILES = {
"core": [
"comfy_extras/nodes_video.py",
"comfy_api/latest/_input/video_types.py",
"comfy_api/latest/_input_impl/video_types.py",
"comfy_api/latest/_util/video_types.py",
"comfy_api/latest/_input/__init__.py",
"comfy_api/latest/_input_impl/__init__.py",
"comfy_api/input/__init__.py",
"comfy_api/input/video_types.py",
"comfy_api/latest/_ui.py",
"comfy_api/latest/_input/basic_types.py",
],
"frontend": ["src/lib/litegraph/src/LGraphNode.ts", "src/scripts/app.ts"],
}
def main():
sources = []
for e in json.loads((OLD / "sources.json").read_bytes())["sources"]:
if e["id"] != "rgthree":
sources.append(
{**e, "local_file": "../rtx-reference/" + e["local_file"], "reused": True}
)
for key, paths in FILES.items():
tree = json.loads((OLD / (key + "-tree.json")).read_bytes())
commit = tree["sha"]
repo = "Comfy-Org/" + ("ComfyUI" if key == "core" else "ComfyUI_frontend")
for path in paths:
blob = next(x["sha"] for x in tree["tree"] if x["path"] == path)
url = f"https://raw.githubusercontent.com/{repo}/{commit}/{path}"
raw = urllib.request.urlopen(url, timeout=30).read(2000001)
assert len(raw) < 2000000
actual = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
assert actual == blob
name = key + "__" + path.replace("/", "__")
(REF / name).write_bytes(raw)
sources.append(
dict(
id=key,
file=path,
local_file=name,
url=url,
commit=commit,
sha256=hashlib.sha256(raw).hexdigest(),
git_blob_sha1=blob,
reused=False,
)
)
(REF / "sources.json").write_text(
json.dumps({"sources": sources}, ensure_ascii=False, indent=2) + "\n"
)
print("PASS exact new static texts", sum(not e.get("reused") for e in sources))
if __name__ == "__main__":
main()