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

127 lines
4.4 KiB
Python

"""Read only bounded exact Git metadata and necessary text. Never execute upstream."""
import hashlib
import json
import urllib.request
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
REF = Path(__file__).resolve().parent.parent / "seedvr2-reference"
REPOS = {
"core": ("Comfy-Org/ComfyUI", "v0.27.0"),
"frontend": ("Comfy-Org/ComfyUI_frontend", "v1.45.20"),
"rgthree": ("rgthree/rgthree-comfy", "27b4f4cdcf3b127c29d5d8135ac1536ecbd4c383"),
}
FILES = {
"core": [
"nodes.py",
"comfy_extras/nodes_images.py",
"comfy_extras/nodes_post_processing.py",
"comfy_extras/nodes_seedvr2.py",
"comfy_extras/nodes_seed.py",
"comfy_extras/nodes_mask.py",
"comfy_extras/nodes_compositing.py",
"comfy_api/latest/_io.py",
"comfy_api/latest/_ui.py",
"comfy/utils.py",
"comfy_extras/nodes_sd3.py",
"comfy/samplers.py",
"folder_paths.py",
"LICENSE",
],
"frontend": [
"src/lib/litegraph/src/LGraphNode.ts",
"src/lib/litegraph/src/subgraph/SubgraphNode.ts",
"src/lib/litegraph/src/subgraph/Subgraph.ts",
"src/scripts/app.ts",
"src/scripts/widgets.ts",
"src/extensions/core/uploadImage.ts",
"src/core/graph/widgets/dynamicWidgets.ts",
"src/extensions/core/dynamicPrompts.ts",
"src/extensions/core/noteNode.ts",
"src/core/graph/subgraph/resolveSubgraphInputTarget.ts",
"src/core/graph/subgraph/promotedWidgetView.ts",
"LICENSE",
],
"rgthree": [
"__init__.py",
"py/image_comparer.py",
"py/image_output.py",
"src_web/comfyui/image_comparer.ts",
"src_web/comfyui/base_node.ts",
"src_web/comfyui/base_node_mode_changer.ts",
"py/constants.py",
"LICENSE",
],
}
def get(url):
with urllib.request.urlopen(url, timeout=45) as r:
b = r.read(3000001)
assert len(b) < 3000000
return b
def main():
expected = {
"core": "bb131be9e83d2f773c90f1d6f1e4b248a498c8c5",
"frontend": "7bd9f8b0d0b854ccb5a947623468f36a392ea0ff",
"rgthree": "27b4f4cdcf3b127c29d5d8135ac1536ecbd4c383",
}
entries = []
for key, (repo, version) in REPOS.items():
if version.startswith("v"):
raw = get(f"https://api.github.com/repos/{repo}/git/ref/tags/{version}")
(REF / f"{key}-tag.json").write_bytes(raw)
obj = json.loads(raw)["object"]
assert obj["type"] == "commit"
commit = obj["sha"]
else:
commit = version
assert commit == expected[key], "Exact tag binding changed; stop"
raw = get(f"https://api.github.com/repos/{repo}/git/trees/{commit}?recursive=1")
tree = json.loads(raw)
assert not tree["truncated"] and tree["sha"] == commit
(REF / f"{key}-tree.json").write_bytes(raw)
paths = {e["path"]: e for e in tree["tree"] if e["type"] == "blob"}
print(key, commit, "seed matches", [p for p in paths if "seedvr" in p.lower()], flush=True)
selected = [p for p in FILES[key] if p in paths]
# Include registration/seed matching text only, not weights or media.
if key == "core":
selected += [
p
for p in paths
if "seedvr" in p.lower() and p.endswith(".py") and p not in selected
]
if key == "rgthree":
print("comparer files", [p for p in paths if "comparer" in p.lower()], flush=True)
def fetch(p):
url = f"https://raw.githubusercontent.com/{repo}/{commit}/{p}"
b = get(url)
blob = hashlib.sha1(b"blob " + str(len(b)).encode() + b"\0" + b).hexdigest()
assert blob == paths[p]["sha"]
name = key + "__" + p.replace("/", "__")
(REF / name).write_bytes(b)
return dict(
id=key,
file=p,
local_file=name,
url=url,
commit=commit,
sha256=hashlib.sha256(b).hexdigest(),
git_blob_sha1=blob,
)
with ThreadPoolExecutor(max_workers=4) as pool:
entries.extend(pool.map(fetch, selected))
(REF / "sources.json").write_text(
json.dumps({"sources": entries}, ensure_ascii=False, indent=2) + "\n"
)
print("static texts", len(entries))
if __name__ == "__main__":
main()