Files
aigc-home/docs/hel-892/index-tts-document-evidence/fetch_sources.py
T

185 lines
5.9 KiB
Python

"""Fetch only pinned upstream text; never import upstream code."""
import datetime
import hashlib
import json
import urllib.request
from pathlib import Path
OUT = Path(__file__).resolve().parents[1] / "index-tts-reference"
SPECS = {
"emotion": (
"chenpipi0807/ComfyUI-Index-TTS",
"9f1685ac0db7faa565efd5122a5db747502d142d",
[
"__init__.py",
"nodes.py",
"index_tts_pro.py",
"tts_models.py",
"utils/index_tts_impl.py",
"pyproject.toml",
"README.md",
],
),
"basepro": (
"chenpipi0807/ComfyUI-Index-TTS",
"59b91cc1ee75791e7bb28a0294d0f02aab85cb5d",
[
"__init__.py",
"nodes.py",
"index_tts_pro.py",
"tts_models.py",
"utils/index_tts_impl.py",
"pyproject.toml",
"README.md",
"index_tts2_mode_nodes.py",
"index_tts2_cache_nodes.py",
"index_tts2_nodes.py",
"indextts2/model_loader.py",
"indextts2/infer.py",
"indextts2/utils.py",
"indextts2/__init__.py",
],
),
"easy": (
"yolain/ComfyUI-Easy-Use",
"17b163e234024384aa32675d8a52e1cc30dac7f6",
[
"__init__.py",
"LICENSE",
"py/nodes/logic.py",
"web_version/v1/js/easy/easy.js",
"web_version/v2/easyuse.js",
"web_version/v1/js/easy/easyWidgets.js",
"web_version/v2/assets/extensions-BKvoulgR.js",
],
),
}
def get(url):
with urllib.request.urlopen(
urllib.request.Request(url, headers={"User-Agent": "offline-source-review"}), timeout=40
) as r:
return r.read()
def fetch(spec):
key, (repo, rev, files) = spec
base = f"https://api.github.com/repos/{repo}/git/"
tree_path = OUT / (key + "-tree.json")
tree = (
tree_path.read_bytes()
if tree_path.exists()
else get(base + f"trees/{rev}?recursive=1&review=hel892index")
)
t = json.loads(tree)
assert not t["truncated"]
(OUT / (key + "-tree.json")).write_bytes(tree)
commit_path = OUT / (key + "-commit.json")
commit = (
commit_path.read_bytes()
if commit_path.exists()
else get(base + f"commits/{rev}?review=hel892index")
)
(OUT / (key + "-commit.json")).write_bytes(commit)
rows = []
previous = (
json.loads((OUT / "sources.json").read_bytes())["sources"]
if (OUT / "sources.json").exists()
else []
)
for f in files:
url = f"https://raw.githubusercontent.com/{repo}/{rev}/{f}"
prior = next((e for e in previous if e["id"] == key and e["file"] == f), None)
name = prior["local_file"] if prior else key + "__" + f.replace("/", "__")
cached = OUT / name
raw = cached.read_bytes() if cached.exists() else get(url)
blob = next(e["sha"] for e in t["tree"] if e["path"] == f)
assert hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest() == blob
if not cached.exists():
cached.write_bytes(raw)
rows.append(
dict(
id=key,
repo=repo,
file=f,
local_file=name,
commit=rev,
tree=json.loads(commit)["tree"]["sha"],
url=url,
sha256=hashlib.sha256(raw).hexdigest(),
git_blob_sha1=blob,
verified_at=datetime.datetime.now(datetime.timezone.utc).isoformat(),
acquisition_time="unknown for reused cache; verification time above",
cached_bytes_reverified=True,
license_file=next(
(
e["local_file"]
for e in previous
if e["id"] == key and e["file"] == "LICENSE"
),
key + "__LICENSE"
if any(x["path"] == "LICENSE" for x in t["tree"])
else "unknown: pyproject declares LICENSE but exact tree has no such file",
),
applicability="源声明准确提交;发布包/目标安装绑定未知",
transport="GitHub pinned raw text; blob verified",
)
)
return rows
def main():
OUT.mkdir(parents=True, exist_ok=True)
tag_path = OUT / "core0357-tag.json"
tag = (
tag_path.read_bytes()
if tag_path.exists()
else get(
(
"https://api.github.com/repos/Comfy-"
"Org/ComfyUI/git/ref/tags/v0.3.57?re"
"view=hel892index"
)
)
)
tag_path.write_bytes(tag)
commit = json.loads(tag)["object"]["sha"]
assert json.loads(tag)["object"]["type"] == "commit"
SPECS["core"] = (
"Comfy-Org/ComfyUI",
commit,
["comfy_extras/nodes_audio.py", "nodes.py", "folder_paths.py", "LICENSE"],
)
frontend_tag = get(
("https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/ref/tags/v1.34.8")
)
(OUT / "frontend1348-tag.json").write_bytes(frontend_tag)
frontend_commit = json.loads(frontend_tag)["object"]["sha"]
assert json.loads(frontend_tag)["object"]["type"] == "commit"
SPECS["frontend"] = (
"Comfy-Org/ComfyUI_frontend",
frontend_commit,
[
"package.json",
"pnpm-lock.yaml",
"src/scripts/widgets.ts",
"src/scripts/app.ts",
"src/lib/litegraph/src/LGraphNode.ts",
"src/extensions/core/uploadAudio.ts",
("src/renderer/extensions/vueNodes/widgets/composables/useIntWidget.ts"),
"LICENSE",
],
)
rows = []
for spec in SPECS.items():
rows += fetch(spec)
(OUT / "sources.json").write_text(
json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n"
)
if __name__ == "__main__":
main()