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

225 lines
7.9 KiB
Python

"""Fetch bounded exact-commit text only; never execute upstream or fetch media."""
import hashlib
import json
import urllib.request
from pathlib import Path
OUT = Path(__file__).resolve().parent.parent / "nlf-reference"
REPOS = {
"nlf": ("kijai/ComfyUI-WanVideoWrapper", "4a3ab6958a5d9650eb4e3c2eb1753c2d7c5b77c6"),
"scail": ("kijai/ComfyUI-SCAIL-Pose", "93059f0fe4ea3881c0d6ec0e327e5d920554277d"),
"onnx": ("kijai/ComfyUI-WanAnimatePreprocess", "74f834b9ecec0e9f48535ab2ec95219f5288018a"),
"layer": ("chflame163/ComfyUI_LayerStyle", "421a1c10767567e3607c32b774e85415f82287ea"),
"math": ("kijai/ComfyUI_essentials", "76e9d1e4399bd025ce8b12c290753d58f9f53e93"),
"int": ("kijai/ComfyUI-KJNodes", "50e7dd34d3b6e6bbab1d41e8068e1ddd19bd4d1b"),
"concat": ("kijai/ComfyUI-KJNodes", "ff7f876c09ff5a53be051073c3c1731b96ee31a3"),
"combine": ("Kosinkadink/ComfyUI-VideoHelperSuite", "0a75c7958fe320efcb052f1d9f8451fd20c730a8"),
}
def get(url):
return urllib.request.urlopen(
urllib.request.Request(url, headers={"User-Agent": "static-reference"}), timeout=30
).read()
def main():
for key, (repo, commit) in REPOS.items():
dest = OUT / (key + "-tree.json")
if not dest.exists():
dest.write_bytes(
get(f"https://api.github.com/repos/{repo}/git/trees/{commit}?recursive=1")
)
tree = json.loads(dest.read_bytes())
paths = [e["path"] for e in tree["tree"] if e["type"] == "blob"]
print(
key,
[
p
for p in paths
if p.endswith((".py", ".js"))
and (
p.count("/") < 1
or any(
s in p.lower()
for s in [
"nlf",
"pose",
"scale_by_aspect",
"constant",
"image_nodes",
"vhs.core",
]
)
)
],
)
FILES = {
"nlf": [
"LICENSE",
"__init__.py",
"MTV/nlf.py",
"MTV/nodes.py",
"nodes.py",
"nodes_utility.py",
"nodes_model_loading.py",
"nodes_deprecated.py",
],
"scail": [
"__init__.py",
"nodes.py",
"NLFPoseExtract/nlf_render.py",
"NLFPoseExtract/align3d.py",
"render_3d/render_cylinder.py",
"render_3d/taichi_cylinder.py",
"pose_draw/draw_utils.py",
"pose_draw/draw_3d_utils.py",
"vitpose_utils/utils.py",
"pyproject.toml",
],
"onnx": ["LICENSE", "__init__.py", "nodes.py", "models/onnx_models.py"],
"layer": ["LICENSE", "__init__.py", "py/image_scale_by_aspect_ratio_v2.py", "py/imagefunc.py"],
"math": ["LICENSE", "__init__.py", "misc.py"],
"int": ["LICENSE", "__init__.py", "nodes/nodes.py"],
"concat": ["LICENSE", "__init__.py", "nodes/image_nodes.py", "web/js/jsnodes.js"],
"combine": [
"LICENSE",
"__init__.py",
"videohelpersuite/nodes.py",
"videohelpersuite/utils.py",
"video_formats/h264-mp4.json",
"web/js/VHS.core.js",
],
}
def fetch_texts():
import concurrent.futures
import subprocess
for key, repo, tag in [
("frontend", "Comfy-Org/ComfyUI_frontend", "v1.23.0"),
("core", "Comfy-Org/ComfyUI", "v0.3.76"),
]:
raw = subprocess.check_output(
["git", "ls-remote", "https://github.com/" + repo + ".git", "refs/tags/" + tag],
timeout=40,
)
(OUT / (key + "-tag.txt")).write_bytes(raw)
REPOS[key] = (repo, raw.decode().split()[0])
FILES["frontend"] = [
"LICENSE",
"src/lib/litegraph/src/LGraphNode.ts",
"src/utils/executionUtil.ts",
"src/scripts/widgets.ts",
"src/extensions/core/uploadImage.ts",
]
FILES["core"] = ["LICENSE", "nodes.py"]
jobs = [(key, file) for key, files in FILES.items() for file in files]
def fetch(job):
key, file = job
repo, commit = REPOS[key]
url = f"https://raw.githubusercontent.com/{repo}/{commit}/{file}"
local = key + "__" + file.replace("/", "__")
try:
raw = get(url)
(OUT / local).write_bytes(raw)
return dict(
id=key,
file=file,
local_file=local,
url=url,
commit=commit,
sha256=hashlib.sha256(raw).hexdigest(),
)
except urllib.error.HTTPError as e:
if e.code != 404:
raise
return dict(id=key, file=file, url=url, commit=commit, unavailable=404)
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as pool:
entries = list(pool.map(fetch, jobs))
# Reuse only the already pinned identical LoadVideo commit; keep its own exact identity.
source = json.loads((OUT.parent / "vhs-reference/sources.json").read_bytes())
source = source["sources"] if isinstance(source, dict) else source
for e in source:
if e.get("commit") == "8550981384301e9bc5bfea83e5c2c75258102593":
local = OUT.parent / "vhs-reference" / e["local_file"]
if not local.exists():
print("missing cached", e)
continue
dest = "load__" + e["local_file"].split("/", 1)[1].replace("/", "__")
raw = local.read_bytes()
(OUT / dest).write_bytes(raw)
entries.append(
dict(
id="load",
file=e["local_file"].split("/", 1)[1],
local_file=dest,
url=e["raw_url"],
commit=e["commit"],
sha256=hashlib.sha256(raw).hexdigest(),
)
)
(OUT / "sources.json").write_text(
json.dumps(dict(base="nlf-reference", sources=entries), ensure_ascii=False, indent=2) + "\n"
)
print("TEXTS", len(entries), "UNAVAILABLE", [e for e in entries if "unavailable" in e])
def fetch_frontend_dependency():
import subprocess
records = json.loads((OUT / "sources.json").read_bytes())
front_commit = (OUT / "frontend-tag.txt").read_text().split()[0]
for file in ["package.json", "package-lock.json"]:
url = f"https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/{front_commit}/{file}"
raw = get(url)
local = "frontend__" + file
(OUT / local).write_bytes(raw)
records["sources"].append(
dict(
id="frontend",
file=file,
local_file=local,
url=url,
commit=front_commit,
sha256=hashlib.sha256(raw).hexdigest(),
)
)
lock = json.loads((OUT / "frontend__package-lock.json").read_bytes())
assert lock["packages"]["node_modules/@comfyorg/litegraph"]["version"] == "0.15.15"
repo = "Comfy-Org/litegraph.js"
tag = subprocess.check_output(
["git", "ls-remote", "https://github.com/" + repo + ".git", "refs/tags/v0.15.15"],
timeout=40,
)
(OUT / "litegraph-tag.txt").write_bytes(tag)
commit = tag.decode().split()[0]
for file in ["src/LGraphNode.ts", "LICENSE"]:
url = f"https://raw.githubusercontent.com/{repo}/{commit}/{file}"
raw = get(url)
local = "litegraph__" + file.replace("/", "__")
(OUT / local).write_bytes(raw)
records["sources"].append(
dict(
id="litegraph",
file=file,
local_file=local,
url=url,
commit=commit,
sha256=hashlib.sha256(raw).hexdigest(),
)
)
(OUT / "sources.json").write_text(json.dumps(records, ensure_ascii=False, indent=2) + "\n")
if __name__ == "__main__":
main()
fetch_texts()
fetch_frontend_dependency()