95 lines
3.2 KiB
Python
95 lines
3.2 KiB
Python
"""Fetch exact bounded text only; never load or execute upstream code."""
|
|
|
|
import hashlib
|
|
import json
|
|
import urllib.request
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
from pathlib import Path
|
|
|
|
REF = Path(__file__).resolve().parent.parent / "resize-compare-reference"
|
|
SPECS = {
|
|
"load": ("Comfy-Org/ComfyUI", "v0.3.50", ["nodes.py", "folder_paths.py", "LICENSE"]),
|
|
"core": (
|
|
"Comfy-Org/ComfyUI",
|
|
"v0.3.65",
|
|
["nodes.py", "comfy/utils.py", "folder_paths.py", "LICENSE"],
|
|
),
|
|
"kj": (
|
|
"kijai/ComfyUI-KJNodes",
|
|
"f7eb33abc80a2aded1b46dff0dd14d07856a7d50",
|
|
["__init__.py", "nodes/image_nodes.py", "LICENSE"],
|
|
),
|
|
"layer": (
|
|
"chflame163/ComfyUI_LayerStyle",
|
|
"89014d833d2ad0998d724090eff1456692692a1d",
|
|
[
|
|
"__init__.py",
|
|
"py/image_scale_restore_v2.py",
|
|
"py/image_scale_by_aspect_ratio_v2.py",
|
|
"py/imagefunc.py",
|
|
"LICENSE",
|
|
],
|
|
),
|
|
}
|
|
|
|
|
|
def get(url):
|
|
with urllib.request.urlopen(url, timeout=40) as r:
|
|
b = r.read(3000001)
|
|
assert len(b) < 3000000
|
|
return b
|
|
|
|
|
|
def one(item):
|
|
key, (repo, rev, files) = item
|
|
if rev.startswith("v"):
|
|
b = get(f"https://api.github.com/repos/{repo}/git/ref/tags/{rev}")
|
|
(REF / f"{key}-tag.json").write_bytes(b)
|
|
obj = json.loads(b)["object"]
|
|
if obj["type"] == "tag":
|
|
b = get(obj["url"])
|
|
(REF / f"{key}-tag-object.json").write_bytes(b)
|
|
obj = json.loads(b)["object"]
|
|
rev = obj["sha"]
|
|
b = get(f"https://api.github.com/repos/{repo}/git/trees/{rev}?recursive=1")
|
|
(REF / f"{key}-tree.json").write_bytes(b)
|
|
t = json.loads(b)
|
|
assert t["sha"] == rev and not t["truncated"]
|
|
entries = []
|
|
for file in files:
|
|
blob = next(x["sha"] for x in t["tree"] if x["path"] == file)
|
|
url = f"https://raw.githubusercontent.com/{repo}/{rev}/{file}"
|
|
b = get(url)
|
|
assert hashlib.sha1(b"blob " + str(len(b)).encode() + b"\0" + b).hexdigest() == blob
|
|
name = key + "__" + file.replace("/", "__")
|
|
(REF / name).write_bytes(b)
|
|
entries.append(
|
|
dict(
|
|
id=key,
|
|
file=file,
|
|
local_file=name,
|
|
url=url,
|
|
commit=rev,
|
|
sha256=hashlib.sha256(b).hexdigest(),
|
|
git_blob_sha1=blob,
|
|
)
|
|
)
|
|
return dict(id=key, repo=repo, commit=rev), entries
|
|
|
|
|
|
if __name__ == "__main__":
|
|
with ThreadPoolExecutor(max_workers=4) as pool:
|
|
rows = list(pool.map(one, SPECS.items()))
|
|
(REF / "identities.json").write_text(json.dumps([r[0] for r in rows], indent=2) + "\n")
|
|
(REF / "sources.json").write_text(
|
|
json.dumps(dict(sources=[e for r in rows for e in r[1]]), indent=2) + "\n"
|
|
)
|
|
# Accurate registry release metadata; package Git bindings are not inferred.
|
|
for key, node, version in [
|
|
("impact", "comfyui-impact-pack", "8.25.1"),
|
|
("rgthree", "rgthree-comfy", "1.0.2510052058"),
|
|
]:
|
|
b = get(f"https://api.comfy.org/nodes/{node}/versions/{version}")
|
|
(REF / f"{key}-registry.json").write_bytes(b)
|
|
print(key, b[:450])
|