83 lines
3.0 KiB
Python
83 lines
3.0 KiB
Python
"""Bind existing exact text and six frontend subgraph files, without execution."""
|
|
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import shutil
|
|
import urllib.request
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
REF = ROOT / "docs/hel-892/flux2-clothing-reference"
|
|
|
|
|
|
def main():
|
|
rows = []
|
|
for stem, keys in [
|
|
("flux2-restore", {"core", "lora", "rgthree", "layer"}),
|
|
("flux2-dual", {"frontend", "negative"}),
|
|
("flux2-real", {"core"}),
|
|
]:
|
|
origin = REF.parent / (stem + "-reference")
|
|
for old in json.loads((origin / "sources.json").read_bytes())["sources"]:
|
|
if old["id"] not in keys or (
|
|
stem == "flux2-real" and old["file"] != "comfy_extras/nodes_images.py"
|
|
):
|
|
continue
|
|
e = dict(old)
|
|
if stem == "flux2-real":
|
|
e["identity_root"] = "../flux2-img-reference"
|
|
e["identity_key"] = "core"
|
|
e["license_file"] = "../flux2-img-reference/core__LICENSE"
|
|
for key in ["local_file", "license_file", "identity_root"]:
|
|
e[key] = os.path.relpath((origin / e[key]).resolve(), REF)
|
|
e["applicability"] = (
|
|
"仅服装迁移本图:core0.8.2/负向0.9.1/LoRA0.21.1/"
|
|
"frontend1.40.0/rgthree准确发布;Layer缺身份仅89014d假设;安装未知"
|
|
)
|
|
assert hashlib.sha256((REF / e["local_file"]).read_bytes()).hexdigest() == e["sha256"]
|
|
rows.append(e)
|
|
shutil.copyfile(
|
|
REF.parent / "flux2-restore-reference/layer-commit-meta.json",
|
|
REF / "layer-commit-meta.json",
|
|
)
|
|
base = next(e for e in rows if e["id"] == "frontend")
|
|
tree = json.loads((REF / base["identity_root"] / "frontend-tree.json").read_bytes())
|
|
for file in [
|
|
"src/lib/litegraph/src/subgraph/" + n + ".ts"
|
|
for n in [
|
|
"SubgraphNode",
|
|
"Subgraph",
|
|
"SubgraphInput",
|
|
"SubgraphOutput",
|
|
"SubgraphInputNode",
|
|
"SubgraphOutputNode",
|
|
]
|
|
]:
|
|
e = dict(base)
|
|
local = "frontend__" + file.replace("/", "__")
|
|
target = REF / local
|
|
url = f"https://raw.githubusercontent.com/{e['repo']}/{e['commit']}/{file}"
|
|
if not target.exists():
|
|
with urllib.request.urlopen(url, timeout=30) as response:
|
|
target.write_bytes(response.read())
|
|
raw = target.read_bytes()
|
|
blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
|
|
assert next(t["sha"] for t in tree["tree"] if t["path"] == file) == blob
|
|
e.update(
|
|
file=file,
|
|
local_file=local,
|
|
url=url,
|
|
sha256=hashlib.sha256(raw).hexdigest(),
|
|
git_blob_sha1=blob,
|
|
)
|
|
rows.append(e)
|
|
(REF / "sources.json").write_text(
|
|
json.dumps(dict(sources=rows, upstream_executed=False), ensure_ascii=False, indent=2) + "\n"
|
|
)
|
|
print("PASS", len(rows), "bound static texts")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|