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

112 lines
3.9 KiB
Python

"Fetch bounded exact source text only, without importing upstream code."
import hashlib
import importlib.util
import json
import subprocess
from pathlib import Path
OUT = Path(__file__).resolve().parent
spec = importlib.util.spec_from_file_location(
"bounded_fetch", OUT.parent / "simple-vfi-document-evidence/fetch_sources.py"
)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
mod.REF = OUT.parent / "seedvr2-loop-reference"
SPECS = {
"path": (
"Kosinkadink/ComfyUI-VideoHelperSuite",
"4ee72c065db22c9d96c2427954dc69e7b908444b",
[
"__init__.py",
"videohelpersuite/load_video_nodes.py",
"videohelpersuite/utils.py",
"videohelpersuite/nodes.py",
"LICENSE",
],
),
"easy-float": (
"yolain/ComfyUI-Easy-Use",
"595e0738a9e3f8d0d9c4d875461b2d2c9e7559c7",
["py/nodes/logic.py", "__init__.py", "LICENSE"],
),
"core-math": ("Comfy-Org/ComfyUI", "v0.29.0", ["comfy_extras/nodes_math.py", "LICENSE"]),
"core-preview": (
"Comfy-Org/ComfyUI",
"v0.29.2",
["comfy_extras/nodes_preview_any.py", "LICENSE"],
),
}
if __name__ == "__main__":
rows = [mod.one(item) for item in SPECS.items() if item[0] != "core-preview"]
# GitHub REST quota was exhausted. Fetch the exact tag via Git smart protocol,
# inspect tree/blobs without checkout or executing any upstream module.
repo = "Comfy-Org/ComfyUI"
checkout = OUT.parents[2] / ".local-evidence/core-preview-git"
if not checkout.exists():
subprocess.run(
[
"git",
"clone",
"--depth",
"1",
"--filter=blob:none",
"--no-checkout",
"--branch",
"v0.29.2",
"https://github.com/Comfy-Org/ComfyUI.git",
str(checkout),
],
check=True,
)
def git(*args):
return subprocess.check_output(["git", "-C", str(checkout), *args])
rev = git("rev-parse", "v0.29.2^{commit}").decode().strip()
assert rev == "322122449c9d2ba8b8df1bb517364527dd0615f1"
listing = git("ls-tree", "-r", rev).decode().splitlines()
tree = []
for line in listing:
head, path = line.split("\t", 1)
mode, kind, sha = head.split()
tree.append(dict(path=path, mode=mode, type=kind, sha=sha))
(mod.REF / "core-preview-tree.json").write_text(
json.dumps(dict(sha=rev, truncated=False, tree=tree, transport="git ls-tree -r"), indent=2)
+ "\n"
)
(mod.REF / "core-preview-tag.json").write_text(
json.dumps(
dict(
ref="refs/tags/v0.29.2",
object=dict(type="commit", sha=rev),
transport="git ls-remote and rev-parse",
),
indent=2,
)
+ "\n"
)
entries = []
for file in ["comfy_extras/nodes_preview_any.py", "nodes.py", "LICENSE"]:
raw = git("show", rev + ":" + file)
blob = next(x["sha"] for x in tree if x["path"] == file)
assert hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest() == blob
name = "core-preview__" + file.replace("/", "__")
(mod.REF / name).write_bytes(raw)
entries.append(
dict(
id="core-preview",
file=file,
local_file=name,
commit=rev,
url=f"https://raw.githubusercontent.com/{repo}/{rev}/{file}",
sha256=hashlib.sha256(raw).hexdigest(),
git_blob_sha1=blob,
)
)
rows.append((dict(id="core-preview", repo=repo, commit=rev), entries))
(mod.REF / "identities.json").write_text(json.dumps([r[0] for r in rows], indent=2) + "\n")
(mod.REF / "sources.json").write_text(
json.dumps(dict(sources=[e for r in rows for e in r[1]]), indent=2) + "\n"
)