Files
aigc-home/docs/hel-892/zimage-outpaint-document-evidence/prepare_sources.py
T

221 lines
7.7 KiB
Python

"""Reuse exact necessary bytes, then acquire bounded missing pinned source text only."""
import datetime
import hashlib
import json
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[3]
OUT = Path(__file__).resolve().parent
REF = OUT.parent / "zimage-outpaint-reference"
REF.mkdir(exist_ok=True)
SPECS = [
(
"core050",
"Comfy-Org/ComfyUI",
"v0.5.0",
[
"nodes.py",
"comfy_extras/nodes_images.py",
"comfy_extras/nodes_differential_diffusion.py",
"LICENSE",
],
),
(
"core0185",
"Comfy-Org/ComfyUI",
"v0.18.5",
[
"nodes.py",
"comfy_extras/nodes_model_patch.py",
"comfy_extras/nodes_images.py",
"comfy/samplers.py",
"comfy/sample.py",
"LICENSE",
],
),
("core0348", "Comfy-Org/ComfyUI", "v0.3.48", ["nodes.py", "folder_paths.py", "LICENSE"]),
("core0375", "Comfy-Org/ComfyUI", "v0.3.75", ["nodes.py", "folder_paths.py", "LICENSE"]),
(
"core0376",
"Comfy-Org/ComfyUI",
"v0.3.76",
[
"nodes.py",
"comfy_extras/nodes_model_patch.py",
"comfy_extras/nodes_post_processing.py",
"LICENSE",
],
),
("core0367", "Comfy-Org/ComfyUI", "v0.3.67", ["nodes.py", "LICENSE"]),
(
"layer",
"chflame163/ComfyUI_LayerStyle",
"90f4bfb38aaf121292f429b20eff07c6c121697e",
[
"__init__.py",
"py/image_scale_by_aspect_ratio_v2.py",
"py/purge_vram.py",
"py/purge_vram_v2.py",
"py/imagefunc.py",
"LICENSE",
],
),
(
"lanpaint",
"scraed/LanPaint",
"6109df6591a4cf2bc9d3b113d03f7297fa9248e9",
[
"__init__.py",
"src/LanPaint/nodes.py",
"src/LanPaint/utils.py",
"src/LanPaint/lanpaint.py",
"pyproject.toml",
"LICENSE",
],
),
(
"show",
"pythongosssss/ComfyUI-Custom-Scripts",
"f2838ed5e59de4d73cde5c98354b87a8d3200190",
["__init__.py", "py/show_text.py", "web/js/showText.js", "LICENSE"],
),
(
"kj",
"kijai/ComfyUI-KJNodes",
"7533dbdd79de10997d25ef9b65e7126668fb8c1d",
["__init__.py", "nodes/image_nodes.py", "LICENSE"],
),
(
"rgactive",
"rgthree/rgthree-comfy",
"b6e0e4b33ebcd337b3c27e46f2106792c44a032e",
["__init__.py", "py/image_comparer.py", "web/comfyui/image_comparer.js", "LICENSE"],
),
(
"rgbypass",
"rgthree/rgthree-comfy",
"8ff50e4521881eca1fe26aec9615fc9362474931",
["__init__.py", "py/image_comparer.py", "web/comfyui/image_comparer.js", "LICENSE"],
),
(
"seed",
"numz/ComfyUI-SeedVR2_VideoUpscaler",
"2a873e2f286224bb00c60fe3fb61b88b65258a6d",
[
"__init__.py",
"src/interfaces/video_upscaler.py",
"src/interfaces/dit_model.py",
"src/interfaces/vae_model.py",
"LICENSE",
],
),
]
def main():
rows = []
# Rebind existing exact LLM and frontend evidence, retaining original acquisition time.
for folder, ids in [("zimage-qwen-reference", {"llama"}), ("zimage-reference", {"frontend"})]:
root = REF.parent / folder
for original in json.loads((root / "sources.json").read_bytes())["sources"]:
if original["id"] not in ids:
continue
e = original.copy()
e["local_file"] = "../" + folder + "/" + e["local_file"]
if not e["license_file"].startswith("未知"):
e["license_file"] = "../" + folder + "/" + e["license_file"]
e["identity_root"] = "../" + folder + "/" + e.get("identity_root", ".")
e["identity_key"] = e.get("identity_key", e["id"])
e["applicability"] = "本图独立声明准确版本,重核原字节;不证明目标安装/别名恢复"
rows.append(e)
for key, repo, tag, files in SPECS:
cache = ROOT / ".local-evidence" / ("zimage-outpaint-" + key + "-git")
cache.mkdir(parents=True, exist_ok=True)
subprocess.run(["git", "init", "--bare", str(cache)], check=True, stdout=subprocess.DEVNULL)
if not (cache / "FETCH_HEAD").exists():
subprocess.run(
[
"git",
"-C",
str(cache),
"fetch",
"--filter=blob:none",
"--depth=1",
"https://github.com/" + repo + ".git",
("refs/tags/" + tag) if tag.startswith("v") else tag,
],
check=True,
)
def git(*args):
return subprocess.check_output(["git", "-C", str(cache), *args])
rev = git("rev-parse", "FETCH_HEAD^{commit}").decode().strip()
tree = git("rev-parse", rev + "^{tree}").decode().strip()
(REF / (key + "-commit.txt")).write_bytes(git("cat-file", "commit", rev))
(REF / (key + "-tag.txt")).write_bytes(git("cat-file", "-p", "FETCH_HEAD"))
(REF / (key + "-tag.json")).write_text(
json.dumps(
dict(ref=tag, commit=rev, object=git("rev-parse", "FETCH_HEAD").decode().strip()),
indent=2,
)
+ "\n"
)
entries = []
for line in git("ls-tree", "-r", rev).decode().splitlines():
head, path = line.split("\t", 1)
mode, kind, sha = head.split()
entries.append(dict(path=path, mode=mode, type=kind, sha=sha))
(REF / (key + "-tree.json")).write_text(
json.dumps(dict(sha=tree, truncated=False, tree=entries), indent=2) + "\n"
)
missing = []
# Discover exact source text names within accurate tree, bounded to relevant classes/files.
if key == "seed":
files += [
e["path"]
for e in entries
if e["path"].endswith(".py")
and any(s in e["path"].lower() for s in ["interface", "node", "schema"])
]
for f in dict.fromkeys(files):
ent = next((x for x in entries if x["path"] == f), None)
if ent is None:
missing.append(f)
continue
raw = git("show", rev + ":" + f)
name = key + "__" + f.replace("/", "__")
(REF / name).write_bytes(raw)
rows.append(
dict(
id=key,
repo=repo,
file=f,
local_file=name,
commit=rev,
tree=tree,
tag=tag,
url=f"https://raw.githubusercontent.com/{repo}/{rev}/{f}",
sha256=hashlib.sha256(raw).hexdigest(),
git_blob_sha1=ent["sha"],
acquisition_time=datetime.datetime.now(datetime.timezone.utc).isoformat(),
license_file=key + "__LICENSE",
transport="filtered git; selected text only",
applicability="本图准确声明版本静态参考;不执行上游或认证目标环境",
identity_root=".",
identity_key=key,
)
)
(REF / (key + "-absent.json")).write_text(json.dumps(missing, indent=2) + "\n")
(REF / "sources.json").write_text(
json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n"
)
print("PINNED", key, rev, flush=True)
if __name__ == "__main__":
main()