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

157 lines
5.2 KiB
Python

"""Bounded exact upstream text acquisition, never checkout or execute upstream."""
import datetime
import hashlib
import json
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[3]
OUT = Path(__file__).resolve().parent
REF = OUT.parent / "flux2-reference"
def main():
rows = []
for key, repo, tag, files in [
(
"core",
"Comfy-Org/ComfyUI",
"v0.8.2",
[
"nodes.py",
"folder_paths.py",
"comfy_extras/nodes_custom_sampler.py",
"comfy_extras/nodes_flux.py",
"comfy_extras/nodes_primitive.py",
"comfy/samplers.py",
"comfy/sample.py",
"comfy/sd.py",
"LICENSE",
],
),
(
"frontend",
"Comfy-Org/ComfyUI_frontend",
"v1.36.14",
[
"package.json",
"pnpm-lock.yaml",
"src/scripts/widgets.ts",
"src/scripts/app.ts",
"src/extensions/core/widgetInputs.ts",
"src/lib/litegraph/src/LGraphNode.ts",
"src/extensions/core/rerouteNode.ts",
"src/lib/litegraph/LICENSE",
"LICENSE",
],
),
(
"primitive",
"Comfy-Org/ComfyUI",
"v0.9.1",
["comfy_extras/nodes_primitive.py", "nodes.py", "LICENSE"],
),
(
"tt",
"AICoderTudou/ComfyUI-TT-Resolution_selector-Node",
"b69cf75c2ce5f864e3db5301dba46a6b5eeaa8fb",
["__init__.py", "LICENSE", "resolution_selector.py"],
),
]:
cache = ROOT / ".local-evidence" / ("flux2-" + key + "-git")
if not cache.exists():
cache.mkdir(parents=True)
subprocess.run(
["git", "init", "--bare", str(cache)], check=True, stdout=subprocess.DEVNULL
)
subprocess.run(
[
"git",
"-C",
str(cache),
"fetch",
"--depth=1",
"https://github.com/" + repo + ".git",
("refs/tags/" + tag) if key != "tt" else tag,
],
check=True,
)
def git(*args):
return subprocess.check_output(["git", "-C", str(cache), *args])
rev = git("rev-parse", "FETCH_HEAD^{commit}").decode().strip()
tree_sha = git("rev-parse", rev + "^{tree}").decode().strip()
commit = git("cat-file", "commit", rev)
(REF / (key + "-commit.txt")).write_bytes(commit)
tag_raw = git("cat-file", "-p", "FETCH_HEAD")
(REF / (key + "-tag.txt")).write_bytes(tag_raw)
(REF / (key + "-tag.json")).write_text(
json.dumps(
dict(
ref=("refs/tags/" + tag) if key != "tt" else tag,
commit=rev,
object=git("rev-parse", "FETCH_HEAD").decode().strip(),
),
indent=2,
)
+ "\n"
)
tree = []
for line in git("ls-tree", "-r", rev).decode().splitlines():
head, path = line.split("\t", 1)
mode, kind, sha = head.split()
tree.append(dict(path=path, mode=mode, type=kind, sha=sha))
(REF / (key + "-tree.json")).write_text(
json.dumps(dict(sha=tree_sha, truncated=False, tree=tree), indent=2) + "\n"
)
# Discover relevant exact filenames before selecting any necessary helper.
print(
key,
rev,
"\n".join(
e["path"]
for e in tree
if any(
s in e["path"].lower() for s in ["minimax", "logic", "subgraphnode", "seednode"]
)
),
flush=True,
)
missing = []
for file in files:
e = next((e for e in tree if e["path"] == file), None)
if e is None:
missing.append(file)
continue
raw = git("show", rev + ":" + file)
name = key + "__" + file.replace("/", "__")
(REF / name).write_bytes(raw)
rows.append(
dict(
id=key,
repo=repo,
file=file,
local_file=name,
commit=rev,
tree=tree_sha,
tag=tag,
url=f"https://raw.githubusercontent.com/{repo}/{rev}/{file}",
sha256=hashlib.sha256(raw).hexdigest(),
git_blob_sha1=e["sha"],
acquisition_time=datetime.datetime.now(datetime.timezone.utc).isoformat(),
license_file=key + "__LICENSE",
transport="git exact tag text; no execution",
applicability="本图准确声明版本;目标安装与UE恢复未知",
)
)
(REF / (key + "-absent.json")).write_text(json.dumps(missing, indent=2) + "\n")
(REF / "sources.json").write_text(
json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n"
)
if __name__ == "__main__":
main()