Files
aigc-home/docs/hel-892/sam3-document-evidence/fetch_sources.py
T
2026-10-30 21:59:57 +08:00

101 lines
3.6 KiB
Python

"""Bounded exact-tag textual investigation; never import upstream code."""
import concurrent.futures
import hashlib
import json
import urllib.request
from pathlib import Path
OUT = Path(__file__).resolve().parent
REF = OUT.parent / "sam3-reference"
PINS = {
"core": (
"Comfy-Org/ComfyUI",
"3086026401180c9216bcb6ace442a4e3587d2c66",
[
"nodes.py",
"comfy_extras/nodes_compositing.py",
"comfy_extras/nodes_mask.py",
"comfy_extras/nodes_video.py",
"comfy_api/latest/_input_impl/video_types.py",
"comfy_api/latest/_input/video_types.py",
"comfy_api/latest/_util/video_types.py",
"comfy_api/latest/_ui.py",
"comfy_api/latest/_io.py",
"folder_paths.py",
"LICENSE",
],
),
"frontend": ("Comfy-Org/ComfyUI_frontend", "4705b3186ecd621151daf95dd702009b266bd819", []),
}
def fetch(url):
with urllib.request.urlopen(
urllib.request.Request(url, headers={"User-Agent": "HEL-892-static-review"}), timeout=35
) as r:
return r.read()
def one(item):
key, repo, commit, file, blob = item
url = f"https://raw.githubusercontent.com/{repo}/{commit}/{file}"
cached = OUT.parent / "birefnet-reference" / (key + "__" + file.replace("/", "__"))
if key == "core" and cached.exists():
data = cached.read_bytes()
assert hashlib.sha1(b"blob " + str(len(data)).encode() + b"\0" + data).hexdigest() == blob
else:
data = fetch(url)
assert hashlib.sha1(b"blob " + str(len(data)).encode() + b"\0" + data).hexdigest() == blob
name = key + "__" + file.replace("/", "__")
(REF / name).write_bytes(data)
return dict(
id=key,
commit=commit,
file=file,
url=url,
local_file=name,
sha256=hashlib.sha256(data).hexdigest(),
git_blob_sha1=blob,
)
def main():
jobs = []
for key, (repo, commit, files) in PINS.items():
tree = json.loads((REF / (key + "-tree.json")).read_bytes())
assert tree["sha"] == commit and not tree["truncated"]
blobs = {x["path"]: x["sha"] for x in tree["tree"] if x["type"] == "blob"}
if key == "frontend":
# Bounded schema/host restoration modules; no unrelated history or dependencies.
files = ["LICENSE"] + [
p
for p in blobs
if p.startswith(("src/core/subgraph/", "src/lib/litegraph/src/subgraph/"))
and p.endswith(("/SubgraphNode.ts", "/Subgraph.ts"))
]
files += [
p
for p in [
"src/scripts/widgets.ts",
"src/scripts/app.ts",
"src/extensions/core/noteNode.ts",
"src/extensions/core/widgetInputs.ts",
"src/core/schemas/promotionSchema.ts",
"src/core/graph/subgraph/resolvePromotedWidgetSource.ts",
"src/core/graph/subgraph/legacyProxyWidgetNormalization.ts",
"src/core/graph/subgraph/resolveSubgraphInputTarget.ts",
"src/stores/promotionStore.ts",
]
if p in blobs
]
jobs += [(key, repo, commit, f, blobs[f]) for f in files]
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as pool:
sources = list(pool.map(one, jobs))
(REF / "sources.json").write_text(json.dumps(dict(sources=sources), indent=2) + "\n")
print("PASS", len(sources), "exact-commit textual originals; metadata separate")
if __name__ == "__main__":
main()