"Select necessary additional exact core text, without executing it." import datetime import hashlib import json import urllib.request from pathlib import Path REF = Path(__file__).resolve().parent.parent / "flux2-img-reference" def main(): d = json.loads((REF / "sources.json").read_bytes()) for key, files in [ ("core", ["comfy_extras/nodes_edit_model.py", "node_helpers.py", "comfy/utils.py"]) ]: seed = next(e for e in d["sources"] if e["id"] == key) t = json.loads((REF / (key + "-tree.json")).read_bytes())["tree"] for f in files: if any(e["id"] == key and e["file"] == f for e in d["sources"]): continue url = f"https://raw.githubusercontent.com/{seed['repo']}/{seed['commit']}/{f}" with urllib.request.urlopen(url, timeout=30) as r: raw = r.read(2000001) assert len(raw) < 2000000 blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest() assert next(e["sha"] for e in t if e["path"] == f) == blob name = key + "__" + f.replace("/", "__") (REF / name).write_bytes(raw) d["sources"].append( dict( seed, file=f, local_file=name, url=url, sha256=hashlib.sha256(raw).hexdigest(), git_blob_sha1=blob, acquisition_time=datetime.datetime.now(datetime.timezone.utc).isoformat(), ) ) (REF / "sources.json").write_text(json.dumps(d, ensure_ascii=False, indent=2) + "\n") if __name__ == "__main__": main()