Files
aigc-home/docs/hel-892/flux2-document-evidence/add_sources.py
T

62 lines
2.2 KiB
Python

"""Acquire necessary exact text helpers; never import upstream."""
import datetime
import hashlib
import json
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[3]
REF = Path(__file__).resolve().parent.parent / "flux2-reference"
def main():
d = json.loads((REF / "sources.json").read_bytes())
for key, files in {
"core": [
"comfy_api/latest/_io.py",
"comfy_api/latest/_io_public.py",
"comfy/cli_args.py",
"latent_preview.py",
],
"primitive": ["comfy_api/latest/_io.py"],
"tt": ["nodes/resolution_selector.py"],
"frontend": [
("src/lib/litegraph/src/Reroute.ts"),
("src/utils/migration/migrateReroute.ts"),
],
}.items():
seed = next(e for e in d["sources"] if e["id"] == key)
for f in files:
if any(e["id"] == key and e["file"] == f for e in d["sources"]):
continue
cache = ROOT / ".local-evidence" / ("flux2-" + key + "-git")
raw = subprocess.check_output(
["git", "-C", str(cache), "show", seed["commit"] + ":" + f]
)
name = key + "__" + f.replace("/", "__")
(REF / name).write_bytes(raw)
e = dict(
seed,
file=f,
local_file=name,
url=f"https://raw.githubusercontent.com/{seed['repo']}/{seed['commit']}/{f}",
sha256=hashlib.sha256(raw).hexdigest(),
git_blob_sha1=hashlib.sha1(
b"blob " + str(len(raw)).encode() + b"\0" + raw
).hexdigest(),
acquisition_time=datetime.datetime.now(datetime.timezone.utc).isoformat(),
)
if key == "tt":
e["license_file"] = "未知:准确完整树无LICENSE文件;不推定授权"
d["sources"].append(e)
for e in d["sources"]:
if e["id"] == "tt":
e["tag"] = "固定完整commit,无tag声明"
e["license_file"] = "未知:准确完整树无LICENSE文件;不推定授权"
(REF / "sources.json").write_text(json.dumps(d, ensure_ascii=False, indent=2) + "\n")
if __name__ == "__main__":
main()