-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwildcard_text_node.py
More file actions
1659 lines (1211 loc) · 43 KB
/
Copy pathwildcard_text_node.py
File metadata and controls
1659 lines (1211 loc) · 43 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import fnmatch
import json
import random
import re
import secrets
from pathlib import Path
NODE_DIR = Path(__file__).resolve().parent
WILDCARD_DIR = NODE_DIR / "wildcards"
INSERT_PLACEHOLDER = "Select wildcard to insert"
NO_WILDCARDS = "No wildcards found"
ROOT_GROUP_NAME = "Root"
HEADER_PREFIX = "• "
MAX_SEED = 9007199254740991
MAX_DROPDOWN_ITEMS = 50000
SUPPORTED_FILE_EXTENSIONS = [".txt", ".json", ".yaml", ".yml"]
TOKEN_RE = re.compile(r"__([^\r\n]+?)__")
# Internal-only marker characters used to track which parts of the
# text were filled in by a wildcard or dynamic prompt. These never
# reach the final output - they are always either stripped out
# (for the plain text sent to generation nodes) or converted into
# visible brackets (for the on-screen preview only).
RESOLVED_START_MARKER = "\x01"
RESOLVED_END_MARKER = "\x02"
# Bracket characters used to visually highlight resolved text in the
# preview box. Chosen deliberately because they are simple,
# single-unit Unicode characters (not a "combined" character like
# bold letters), so they render identically and safely on every
# system, while still being bold and blocky enough to stand out.
RESOLVED_BRACKET_OPEN = "【"
RESOLVED_BRACKET_CLOSE = "】"
_CACHE_SIGNATURE = None
_CACHE_WILDCARDS = None
_CACHE_DROPDOWN = None
def ensure_wildcard_dir():
try:
WILDCARD_DIR.mkdir(parents=True, exist_ok=True)
except Exception as error:
print(f"[ComfyUI Local Wildcards] Could not create wildcards folder: {error}")
def read_text_file_safely(path):
"""
Reads a text file trying several common encodings in order.
Falls back to UTF-8 with lossy character replacement as a last
resort, so a badly-encoded wildcard file never crashes loading
or silently fails to load - worst case, one odd character gets
swapped out, but the rest of the file still loads correctly.
"""
encodings_to_try = ["utf-8-sig", "utf-8", "cp1252", "latin-1"]
for encoding in encodings_to_try:
try:
with open(path, "r", encoding=encoding) as file:
return file.read()
except (UnicodeDecodeError, UnicodeError):
continue
with open(path, "r", encoding="utf-8", errors="replace") as file:
return file.read()
def normalize_wildcard_name(name):
name = str(name or "").strip()
name = name.replace("\\", "/")
while "//" in name:
name = name.replace("//", "/")
if name.startswith("__") and name.endswith("__") and len(name) >= 4:
name = name[2:-2]
name = name.strip("/")
name = name.strip()
lower_name = name.lower()
for extension in SUPPORTED_FILE_EXTENSIONS:
if lower_name.endswith(extension):
name = name[: -len(extension)]
break
return name.strip()
def clean_text_line(line):
line = str(line).strip()
if not line:
return None
if line.startswith("#"):
return None
if line.startswith("//"):
return None
return line
def normalize_relative_name(path):
try:
relative = path.relative_to(WILDCARD_DIR)
no_suffix = relative.with_suffix("")
return no_suffix.as_posix()
except Exception:
return path.stem
def get_dropdown_directory(path):
try:
relative_parent = path.parent.relative_to(WILDCARD_DIR)
except Exception:
return ROOT_GROUP_NAME
if str(relative_parent) in ["", "."]:
return ROOT_GROUP_NAME
return relative_parent.as_posix()
def unique_keep_order(items):
seen = set()
output = []
for item in items:
item = normalize_wildcard_name(item)
if not item:
continue
key = item.lower()
if key not in seen:
seen.add(key)
output.append(item)
return output
def leaf_name(name):
name = normalize_wildcard_name(name)
if "/" in name:
name = name.split("/")[-1]
if "." in name:
name = name.split(".")[-1]
return name.strip()
def token_contains_glob(token):
token = str(token)
return "*" in token or "?" in token or "[" in token
def to_bold_dropdown_text(text):
"""
Used only for building the insert_wildcard dropdown list (folder
header names), which is a completely separate, unrelated feature
from the preview box. Left as-is since it already works fine and
is not part of the preview text pipeline.
"""
normal_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
bold_upper = "𝐀𝐁𝐂𝐃𝐄𝐅𝐆𝐇𝐈𝐉𝐊𝐋𝐌𝐍𝐎𝐏𝐐𝐑𝐒𝐓𝐔𝐕𝐖𝐗𝐘𝐙"
normal_lower = "abcdefghijklmnopqrstuvwxyz"
bold_lower = "𝐚𝐛𝐜𝐝𝐞𝐟𝐠𝐡𝐢𝐣𝐤𝐥𝐦𝐧𝐨𝐩𝐪𝐫𝐬𝐭𝐮𝐯𝐰𝐱𝐲𝐳"
normal_digits = "0123456789"
bold_digits = "𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗"
translation = {}
for normal, bold in zip(normal_upper, bold_upper):
translation[ord(normal)] = bold
for normal, bold in zip(normal_lower, bold_lower):
translation[ord(normal)] = bold
for normal, bold in zip(normal_digits, bold_digits):
translation[ord(normal)] = bold
return str(text).translate(translation)
def strip_resolved_markers(text):
"""
Removes the internal marker characters completely, leaving fully
plain text. This is what gets sent to the actual generation
pipeline (e.g. CLIP Text Encode), so it must never contain
special characters.
"""
text = str(text)
text = text.replace(RESOLVED_START_MARKER, "")
text = text.replace(RESOLVED_END_MARKER, "")
return text
def apply_resolved_markers(text):
"""
Converts the internal start/end markers into visible brackets
for the preview box, wrapping only the outermost resolved chunk
of text - if a resolved value happens to contain further nested
markers (e.g. a wildcard result that itself contains another
wildcard), only a single outer bracket pair is shown rather than
stacking multiple brackets inside each other.
Always produces fully clean, printable text with no control
characters left in it, safe to display anywhere.
"""
output_characters = []
depth = 0
for character in str(text):
if character == RESOLVED_START_MARKER:
depth += 1
if depth == 1:
output_characters.append(RESOLVED_BRACKET_OPEN)
continue
if character == RESOLVED_END_MARKER:
if depth == 1:
output_characters.append(RESOLVED_BRACKET_CLOSE)
depth = max(0, depth - 1)
continue
output_characters.append(character)
return "".join(output_characters)
def add_dropdown_name(display_groups, directory_name, wildcard_name):
directory_name = str(directory_name or ROOT_GROUP_NAME).strip()
if not directory_name:
directory_name = ROOT_GROUP_NAME
wildcard_name = normalize_wildcard_name(wildcard_name)
if not wildcard_name:
return
if directory_name not in display_groups:
display_groups[directory_name] = set()
display_groups[directory_name].add(wildcard_name)
def add_bare_alias_if_safe(database_names, bare_name, dropdown_directory, wildcards):
"""
Only adds a short/ambiguous alias name (a bare filename, a bare
nested JSON/YAML key, or a leaf name) if the file lives directly
in the Root wildcards folder AND no other wildcard has already
claimed that exact name.
This stops unrelated files - or unrelated nested keys buried
inside completely different JSON/YAML files, in any subfolder -
from silently merging their choices into an unrelated wildcard
that happens to share the same short name (e.g. a "color" key
nested under "hair" leaking into the Root "color" wildcard).
"""
if dropdown_directory != ROOT_GROUP_NAME:
return
bare_name = normalize_wildcard_name(bare_name)
if not bare_name:
return
if bare_name in wildcards or bare_name.lower() in wildcards:
return
database_names.append(bare_name)
def add_name_to_database(
wildcards,
display_groups,
name,
choices,
show_in_dropdown=False,
dropdown_directory=ROOT_GROUP_NAME,
):
name = normalize_wildcard_name(name)
if not name:
return
cleaned_choices = []
for choice in choices:
if choice is None:
continue
choice = str(choice).strip()
if choice:
cleaned_choices.append(choice)
if not cleaned_choices:
return
names_to_add = unique_keep_order(
[
name,
name.lower(),
]
)
for database_name in names_to_add:
if database_name not in wildcards:
wildcards[database_name] = []
wildcards[database_name].extend(cleaned_choices)
if show_in_dropdown:
add_dropdown_name(display_groups, dropdown_directory, name)
def add_choices_with_names(
wildcards,
display_groups,
database_names,
display_names_to_show,
choices,
dropdown_directory=ROOT_GROUP_NAME,
):
for name in database_names:
add_name_to_database(
wildcards,
display_groups,
name,
choices,
show_in_dropdown=False,
dropdown_directory=dropdown_directory,
)
for name in display_names_to_show:
add_name_to_database(
wildcards,
display_groups,
name,
choices,
show_in_dropdown=True,
dropdown_directory=dropdown_directory,
)
def value_to_choices(value):
choices = []
if value is None:
return choices
if isinstance(value, list):
for item in value:
if isinstance(item, str):
cleaned = item.strip()
if cleaned:
choices.append(cleaned)
elif isinstance(item, (int, float, bool)):
choices.append(str(item))
elif isinstance(item, dict):
if "text" in item:
choices.append(str(item["text"]))
elif "value" in item:
choices.append(str(item["value"]))
elif "prompt" in item:
choices.append(str(item["prompt"]))
elif "name" in item:
choices.append(str(item["name"]))
else:
choices.append(json.dumps(item, ensure_ascii=False))
else:
choices.append(str(item))
elif isinstance(value, str):
cleaned = value.strip()
if cleaned:
choices.append(cleaned)
elif isinstance(value, (int, float, bool)):
choices.append(str(value))
return choices
def load_txt_file(path, wildcards, display_groups):
try:
choices = []
text = read_text_file_safely(path)
for line in text.splitlines():
cleaned = clean_text_line(line)
if cleaned is not None:
choices.append(cleaned)
if not choices:
return
relative_name = normalize_relative_name(path)
simple_name = path.stem
dropdown_directory = get_dropdown_directory(path)
database_names = unique_keep_order(
[
relative_name,
]
)
add_bare_alias_if_safe(database_names, simple_name, dropdown_directory, wildcards)
display_names_to_show = unique_keep_order(
[
relative_name,
]
)
add_choices_with_names(
wildcards,
display_groups,
database_names,
display_names_to_show,
choices,
dropdown_directory=dropdown_directory,
)
except Exception as error:
print(f"[ComfyUI Local Wildcards] Could not read TXT file {path}: {error}")
def data_path_to_dot_name(parts):
clean_parts = []
for part in parts:
part = str(part).strip()
if part:
clean_parts.append(part)
return ".".join(clean_parts)
def data_path_to_slash_name(parts):
clean_parts = []
for part in parts:
part = str(part).strip()
if part:
clean_parts.append(part)
return "/".join(clean_parts)
def walk_data(
value,
wildcards,
display_groups,
file_relative_name,
file_simple_name,
data_parts,
dropdown_directory,
):
try:
current_dot_name = data_path_to_dot_name(data_parts)
current_slash_name = data_path_to_slash_name(data_parts)
direct_choice_keys = [
"choices",
"options",
"values",
"items",
"wildcards",
"prompts",
"list",
"data",
]
if isinstance(value, dict):
for direct_key in direct_choice_keys:
if direct_key in value and isinstance(value[direct_key], list):
choices = value_to_choices(value[direct_key])
if choices:
if current_dot_name:
current_leaf = leaf_name(current_dot_name)
full_dot_name = f"{file_relative_name}.{current_dot_name}"
full_slash_name = f"{file_relative_name}/{current_slash_name}"
database_names = unique_keep_order(
[
current_dot_name,
current_slash_name,
full_dot_name,
full_slash_name,
f"{file_simple_name}.{current_dot_name}",
f"{file_simple_name}/{current_slash_name}",
]
)
add_bare_alias_if_safe(
database_names, current_leaf, dropdown_directory, wildcards
)
display_names_to_show = unique_keep_order(
[
full_slash_name,
]
)
else:
database_names = unique_keep_order(
[
file_relative_name,
]
)
add_bare_alias_if_safe(
database_names, file_simple_name, dropdown_directory, wildcards
)
add_bare_alias_if_safe(
database_names,
leaf_name(file_relative_name),
dropdown_directory,
wildcards,
)
display_names_to_show = unique_keep_order(
[
file_relative_name,
]
)
add_choices_with_names(
wildcards,
display_groups,
database_names,
display_names_to_show,
choices,
dropdown_directory=dropdown_directory,
)
return
for key, child_value in value.items():
key = str(key).strip()
if not key:
continue
if key == "__yaml_list__":
continue
child_parts = data_parts + [key]
if isinstance(child_value, dict):
walk_data(
child_value,
wildcards,
display_groups,
file_relative_name,
file_simple_name,
child_parts,
dropdown_directory,
)
else:
child_dot_name = data_path_to_dot_name(child_parts)
child_slash_name = data_path_to_slash_name(child_parts)
child_leaf = leaf_name(child_dot_name)
full_dot_name = f"{file_relative_name}.{child_dot_name}"
full_slash_name = f"{file_relative_name}/{child_slash_name}"
choices = value_to_choices(child_value)
if choices:
database_names = unique_keep_order(
[
child_dot_name,
child_slash_name,
full_dot_name,
full_slash_name,
f"{file_simple_name}.{child_dot_name}",
f"{file_simple_name}/{child_slash_name}",
]
)
add_bare_alias_if_safe(
database_names, key, dropdown_directory, wildcards
)
add_bare_alias_if_safe(
database_names, child_leaf, dropdown_directory, wildcards
)
display_names_to_show = unique_keep_order(
[
full_slash_name,
]
)
add_choices_with_names(
wildcards,
display_groups,
database_names,
display_names_to_show,
choices,
dropdown_directory=dropdown_directory,
)
else:
choices = value_to_choices(value)
if choices:
database_names = unique_keep_order(
[
file_relative_name,
]
)
add_bare_alias_if_safe(
database_names, file_simple_name, dropdown_directory, wildcards
)
add_bare_alias_if_safe(
database_names, leaf_name(file_relative_name), dropdown_directory, wildcards
)
display_names_to_show = unique_keep_order(
[
file_relative_name,
]
)
add_choices_with_names(
wildcards,
display_groups,
database_names,
display_names_to_show,
choices,
dropdown_directory=dropdown_directory,
)
except Exception as error:
print(f"[ComfyUI Local Wildcards] Could not walk data in {file_relative_name}: {error}")
def load_json_file(path, wildcards, display_groups):
try:
text = read_text_file_safely(path)
data = json.loads(text)
relative_name = normalize_relative_name(path)
simple_name = path.stem
dropdown_directory = get_dropdown_directory(path)
walk_data(
data,
wildcards,
display_groups,
relative_name,
simple_name,
[],
dropdown_directory,
)
except Exception as error:
print(f"[ComfyUI Local Wildcards] Could not read JSON file {path}: {error}")
def count_leading_spaces(text):
count = 0
for character in text:
if character == " ":
count += 1
else:
break
return count
def collect_yaml_block_scalar(lines, start_index, parent_indent, folded=True):
collected_raw_lines = []
index = start_index
while index < len(lines):
raw_line = lines[index].rstrip("\r\n")
stripped = raw_line.strip()
if not stripped:
collected_raw_lines.append("")
index += 1
continue
indent = count_leading_spaces(raw_line)
if indent <= parent_indent:
break
collected_raw_lines.append(raw_line)
index += 1
non_empty_indents = []
for raw_line in collected_raw_lines:
if raw_line.strip():
non_empty_indents.append(count_leading_spaces(raw_line))
if non_empty_indents:
base_indent = min(non_empty_indents)
else:
base_indent = parent_indent + 1
cleaned_lines = []
for raw_line in collected_raw_lines:
if raw_line.strip():
cleaned_lines.append(raw_line[base_indent:].rstrip())
else:
cleaned_lines.append("")
if folded:
paragraphs = []
current_words = []
for line in cleaned_lines:
stripped_line = line.strip()
if not stripped_line:
if current_words:
paragraphs.append(" ".join(current_words))
current_words = []
continue
current_words.append(stripped_line)
if current_words:
paragraphs.append(" ".join(current_words))
return "\n".join(paragraphs).strip(), index
return "\n".join(cleaned_lines).strip(), index
def parse_simple_yaml_lines(lines):
root = {}
stack = [(-1, root)]
index = 0
block_markers = [">", "|", ">-", "|-", ">+", "|+"]
while index < len(lines):
line_without_newline = lines[index].rstrip("\r\n")
stripped = line_without_newline.strip()
if not stripped:
index += 1
continue
if stripped.startswith("#"):
index += 1
continue
indent = count_leading_spaces(line_without_newline)
while len(stack) > 1 and indent <= stack[-1][0]:
stack.pop()
parent = stack[-1][1]
if stripped == "-" or stripped.startswith("- "):
if "__yaml_list__" not in parent:
parent["__yaml_list__"] = []
if stripped == "-":
item = ""
else:
item = stripped[2:].strip()
if item in block_markers:
folded = item.startswith(">")
block_text, next_index = collect_yaml_block_scalar(
lines,
index + 1,
indent,
folded=folded,
)
if block_text:
parent["__yaml_list__"].append(block_text)
index = next_index
continue
parent["__yaml_list__"].append(item.strip('"').strip("'"))
index += 1
continue
if ":" in stripped:
key, value = stripped.split(":", 1)
key = key.strip()
value = value.strip()
if not key:
index += 1
continue
if value in block_markers:
folded = value.startswith(">")
block_text, next_index = collect_yaml_block_scalar(
lines,
index + 1,
indent,
folded=folded,
)
parent[key] = block_text
index = next_index
continue
if value == "":
new_dict = {}
parent[key] = new_dict
stack.append((indent, new_dict))
index += 1
continue
if value.startswith("[") and value.endswith("]"):
inside = value[1:-1].strip()
items = []
if inside:
for part in inside.split(","):
cleaned = part.strip().strip('"').strip("'")
if cleaned:
items.append(cleaned)
parent[key] = items
index += 1
continue
parent[key] = value.strip('"').strip("'")
index += 1
continue
index += 1
return root
def fix_simple_yaml_lists(value):
if isinstance(value, dict):
if "__yaml_list__" in value and len(value) == 1:
return value["__yaml_list__"]
fixed = {}
for key, child_value in value.items():
if key == "__yaml_list__":
fixed[key] = child_value
else:
fixed[key] = fix_simple_yaml_lists(child_value)
return fixed
if isinstance(value, list):
return [fix_simple_yaml_lists(item) for item in value]
return value
def load_yaml_file(path, wildcards, display_groups):
try:
text = read_text_file_safely(path)
data = None
try:
import yaml
data = yaml.safe_load(text)
except Exception:
data = None
if data is None:
lines = text.splitlines()
data = parse_simple_yaml_lines(lines)
data = fix_simple_yaml_lists(data)
if not data:
return
relative_name = normalize_relative_name(path)
simple_name = path.stem
dropdown_directory = get_dropdown_directory(path)
walk_data(
data,
wildcards,
display_groups,
relative_name,
simple_name,
[],
dropdown_directory,
)
except Exception as error:
print(f"[ComfyUI Local Wildcards] Could not read YAML file {path}: {error}")
def get_wildcard_file_paths():
ensure_wildcard_dir()
paths = []
try:
for path in WILDCARD_DIR.rglob("*"):
if path.is_file() and path.suffix.lower() in SUPPORTED_FILE_EXTENSIONS:
paths.append(path)
except Exception as error:
print(f"[ComfyUI Local Wildcards] Could not scan wildcards folder: {error}")
paths = sorted(paths, key=lambda p: p.as_posix().lower())
return paths
def get_scan_signature():
paths = get_wildcard_file_paths()
signature = []
for path in paths:
try:
stat = path.stat()
relative = path.relative_to(WILDCARD_DIR).as_posix()
signature.append((relative, stat.st_mtime_ns, stat.st_size))
except Exception:
pass
return tuple(signature)
def build_wildcard_database():
wildcards = {}
display_groups = {}
try:
paths = get_wildcard_file_paths()
for path in paths:
suffix = path.suffix.lower()
if suffix == ".txt":
load_txt_file(path, wildcards, display_groups)
elif suffix == ".json":
load_json_file(path, wildcards, display_groups)
elif suffix in [".yaml", ".yml"]:
load_yaml_file(path, wildcards, display_groups)
except Exception as error:
print(f"[ComfyUI Local Wildcards] Could not build wildcard database: {error}")
return wildcards, display_groups
def build_grouped_dropdown(display_groups):
dropdown = [INSERT_PLACEHOLDER]
try:
if not display_groups: