Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
128 lines (114 loc) · 4.2 KB
/
Copy path__init__.py
File metadata and controls
128 lines (114 loc) · 4.2 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
124
125
126
127
import json
import pathlib
import threading
import urllib.request
from .py import endpoints, wildcard_processor
NODE_CLASS_MAPPINGS = {
"WildcardProcessor": wildcard_processor.WildcardProcessorNode,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"WildcardProcessor": "🃏 Wildcard Processor",
}
WEB_DIRECTORY = "./web"
# Garage is the source of truth for the bundled pmp wildcards — sync them on
# every ComfyUI start so prompt updates ship without waiting for a node release.
_GARAGE_WILDCARDS_URL = "https://github.com/huchukato/ComfyUI-Garage/raw/master/wildcards"
_GARAGE_WILDCARDS = (
"pmp/act.yaml",
"pmp/actff.yaml",
"pmp/actffm.yaml",
"pmp/actmmf.yaml",
"pmp/actsolo.yaml",
"pmp/blwjob.yaml",
"pmp/prmpt.yaml",
"pmp/qwen21.yaml",
"pmp/prmpt/acc.yaml",
"pmp/prmpt/char.yaml",
"pmp/prmpt/clths.yaml",
"pmp/prmpt/exprss.yaml",
"pmp/prmpt/hair.yaml",
"pmp/prmpt/imgcmp.yaml",
"pmp/prmpt/lctns.yaml",
"pmp/prmpt/light.yaml",
"pmp/prmpt/pose.yaml",
"pmp/prmpt/styles.yaml",
"mmh3/camera.yaml",
"mmh3/music.yaml",
"mmh3/nsfw.yaml",
"mmh3/style.yaml",
)
_GARAGE_TREE_URL = "https://api.github.com/repos/huchukato/ComfyUI-Garage/git/trees/master?recursive=1"
_WILDCARD_EXTS = {".yaml", ".yml", ".txt"}
def _garage_wildcard_list():
"""List every wildcard file under wildcards/ in the Garage repo.
Falls back to the bundled list if the GitHub API is unreachable."""
try:
req = urllib.request.Request(
_GARAGE_TREE_URL, headers={"User-Agent": "ComfyUI-TagForge"})
tree = json.loads(urllib.request.urlopen(req, timeout=10).read())
paths = [
blob["path"][len("wildcards/"):]
for blob in tree.get("tree", [])
if blob.get("type") == "blob"
and blob["path"].startswith("wildcards/")
and pathlib.PurePosixPath(blob["path"]).suffix.lower() in _WILDCARD_EXTS
]
if paths:
return paths
except Exception as exc:
print(f"[TagForge] Garage wildcard listing failed, using bundled list: {exc}")
return list(_GARAGE_WILDCARDS)
def _sync_garage_wildcards():
root = pathlib.Path(__file__).resolve().parent / "wildcards"
manifest = root / ".garage-manifest"
upstream = _garage_wildcard_list()
updated = False
try:
prev = set(manifest.read_text().splitlines()) if manifest.exists() else set()
except Exception:
prev = set()
managed = {rel.split("/")[0] for rel in upstream}
managed |= {rel.split("/")[0] for rel in prev} | {"vid"}
try:
local = {p.relative_to(root).as_posix() for p in root.rglob("*")
if p.is_file() and p.name not in (".garage-manifest", ".gitkeep")}
except Exception:
local = set()
stale = (prev | {rel for rel in local if rel.split("/")[0] in managed}) - set(upstream)
for rel in stale:
target = root / rel
try:
if target.is_file():
target.unlink()
updated = True
print(f"[TagForge] wildcard removed (gone from Garage): {rel}")
except Exception as exc:
print(f"[TagForge] wildcard removal failed {rel}: {exc}")
for rel in upstream:
try:
data = urllib.request.urlopen(f"{_GARAGE_WILDCARDS_URL}/{rel}", timeout=10).read()
dest = root / rel
if dest.exists() and dest.read_bytes() == data:
continue
dest.parent.mkdir(parents=True, exist_ok=True)
dest.write_bytes(data)
updated = True
print(f"[TagForge] wildcard updated from Garage: {rel}")
except Exception as exc:
print(f"[TagForge] wildcard sync skipped {rel}: {exc}")
try:
manifest.write_text("\n".join(upstream))
except Exception:
pass
for child in sorted(root.rglob("*"), key=lambda p: -len(p.parts)):
try:
if child.is_dir() and not any(child.iterdir()):
child.rmdir()
except Exception:
pass
if updated:
try:
wildcard_processor.WildcardLoader.refresh()
except Exception:
pass
threading.Thread(target=_sync_garage_wildcards, daemon=True).start()