Repository navigation
Expand file tree
/
Copy pathnode_inventory.py
More file actions
123 lines (112 loc) · 5.88 KB
/
Copy pathnode_inventory.py
File metadata and controls
123 lines (112 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
"""
Regenerate docs/NODE_LIBRARY/_INVENTORY.md - the catalog of every node type used across the kit's workflow
library, classified against a live ComfyUI.
What it does: parse every workflow JSON in the official template bundles (+ optional saved workflows), collect
the distinct node class_types and how many workflows use each, then cross-check each against a running
ComfyUI's /object_info to split CORE / API / custom-author / missing / subgraph.
Run it from the ComfyUI venv (so the template packages import) with ComfyUI running:
python tools/node_inventory.py > docs/NODE_LIBRARY/_INVENTORY.md
Config via env (sensible defaults below):
COMFY_URL default http://127.0.0.1:8188
COMFY_SITE_PACKAGES site-packages dir holding comfyui_workflow_templates_media_*; default: auto-locate
COMFY_USER_WORKFLOWS a folder of saved .json workflows to include (default: none)
"""
import json, glob, os, re, sys, urllib.request, collections, importlib.util
COMFY_URL = os.environ.get("COMFY_URL", "http://127.0.0.1:8188").rstrip("/")
SAVED = os.environ.get("COMFY_USER_WORKFLOWS", "")
def site_packages():
sp = os.environ.get("COMFY_SITE_PACKAGES")
if sp:
return sp
spec = importlib.util.find_spec("comfyui_workflow_templates_core")
if spec and spec.origin:
return os.path.dirname(os.path.dirname(spec.origin))
raise SystemExit("Could not locate template bundles; set COMFY_SITE_PACKAGES.")
SP = site_packages()
bundles = glob.glob(SP + "/comfyui_workflow_templates_media_*/templates")
files = []
for d in bundles:
files += [f for f in glob.glob(d + "/*.json") if not os.path.basename(f).startswith("index")]
saved_files = glob.glob(SAVED + "/*.json") if SAVED else []
files += saved_files
SKIP = {"Note", "MarkdownNote"}
usage = collections.Counter()
def types_of(d):
ts = []
if isinstance(d, dict) and isinstance(d.get("nodes"), list):
ts = [n["type"] for n in d["nodes"] if n.get("type")]
elif isinstance(d, dict):
ts = [v["class_type"] for v in d.values() if isinstance(v, dict) and "class_type" in v]
return ts
for f in files:
try:
d = json.load(open(f, encoding="utf-8"))
except Exception:
continue
for t in set(types_of(d)):
if t not in SKIP:
usage[t] += 1
oi = json.load(urllib.request.urlopen(COMFY_URL + "/object_info", timeout=60))
UUID = re.compile(r"^[0-9a-f-]{36}$")
# Node packs to leave out of the generated inventory. Set COMFY_PRIVATE_PACKS to a comma-separated list of
# custom_nodes directory names when a machine carries packs that must not appear in a public catalog
# (unreleased work, client work, anything under NDA). Empty by default, so the script ships with no one's
# private pack names baked into it.
PRIVATE_PACKS = {p.strip() for p in os.environ.get("COMFY_PRIVATE_PACKS", "").split(",") if p.strip()}
PREFIXES = ["ByteDance2","ByteDance","ElevenLabs","HappyHorse","OpenRouter","OpenAI","Gemini","Kling","Luma",
"Minimax","Pixverse","Runway","Rodin3D","Rodin","Meshy","Tripo","Bria","Magnific","Flux2",
"FluxKontext","FluxPro","Flux","Ideogram","Krea2","Grok","Reve","Quiver","HitPaw","Beeble","Pika",
"Recraft","Claude","Ltxv"]
def provider(t):
for p in PREFIXES:
if t.startswith(p):
return p
m = re.match(r"^[A-Z][a-z0-9]+", t)
return m.group(0) if m else "Other"
core, api, missing, subgraph = [], [], [], []
custom = collections.defaultdict(list); apiprov = collections.defaultdict(list)
for t in usage:
if UUID.match(t):
subgraph.append(t); continue
info = oi.get(t)
if not info:
missing.append(t); continue
pm = info.get("python_module") or ""; cat = info.get("category") or ""
if pm.startswith("custom_nodes."):
pack = pm.split(".", 2)[1]
if pack in PRIVATE_PACKS:
continue
custom[pack].append(t)
elif "api" in pm.lower() or info.get("api_node") or cat.lower().startswith("api"):
api.append(t); apiprov[provider(t)].append(t)
else:
core.append(t)
w = sys.stdout.write
w("# Node inventory - everything used across the kit's workflows (generated)\n\n")
w(f"Generated by `tools/node_inventory.py` from {len(files)} workflows ({len(bundles)} official template "
f"bundles{' + saved workflows' if saved_files else ''}) cross-checked against a live ComfyUI /object_info "
f"({len(oi)} installed types). Numbers are #workflows using each type. This is the master catalog: scan it to "
f"know a node EXISTS and where it comes from before deciding to document (see `_INDEX.md`) or build. Live I/O "
f"always from `get_node_info`, never frozen here.\n\n")
w(f"- **{len(usage)} distinct node types** total\n")
w(f"- CORE (stock comfy): **{len(core)}** | API / cloud partner: **{len(api)}** | custom-author (installed): "
f"**{sum(len(v) for v in custom.values())}** in {len(custom)} packs | missing (used, not installed): "
f"**{len(missing)}** | subgraph blueprint ids: **{len(subgraph)}**\n\n")
w("## Custom-author packs (read real source, document in custom-author.md, credit author)\n")
for pack, ts in sorted(custom.items(), key=lambda kv: -len(kv[1])):
w(f"### {pack} ({len(ts)} node types)\n")
for t in sorted(ts, key=lambda x: -usage[x]):
w(f"- `{t}` ({usage[t]})\n")
w("\n## Missing - used in a workflow but NOT installed (find / read source / document)\n")
for t in sorted(missing, key=lambda x: -usage[x]):
w(f"- `{t}` ({usage[t]})\n")
w("\n## CORE (stock ComfyUI), by usage\n")
for t in sorted(core, key=lambda x: -usage[x]):
w(f"- `{t}` ({usage[t]})\n")
w("\n## API / cloud partner nodes, by provider\n")
for prov, ts in sorted(apiprov.items(), key=lambda kv: -len(kv[1])):
w(f"### {prov} ({len(ts)})\n")
for t in sorted(ts, key=lambda x: -usage[x]):
w(f"- `{t}` ({usage[t]})\n")
w(f"\n## Subgraph blueprint ids ({len(subgraph)}) - not atomic nodes, not documented individually\n")