Improve compatibility of dynamicprompts YAML wildcards (#339)

- Folder paths are prepended to tree structures in YAML
- Single strings are parsed as collections containing a single item
main
Yasutaka ATARASHI 2026-03-21 19:51:51 +09:00 committed by GitHub
parent 7deb665416
commit 8c441f9afc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 6 deletions

View File

@ -156,17 +156,21 @@ def parse_umi_format(umi_tags, data):
count += 1
def parse_dynamic_prompt_format(yaml_wildcards, data, path):
def parse_dynamic_prompt_format(yaml_wildcards, data, path, root):
# Recurse subkeys, delete those without string lists as values
def recurse_dict(d: dict):
for key, value in d.copy().items():
if isinstance(value, dict):
recurse_dict(value)
elif not (isinstance(value, list) and all(isinstance(v, str) for v in value)):
elif (not isinstance(value, str) and # a string value is treated as a list of one item
not (isinstance(value, list) and all(isinstance(v, str) for v in value))):
del d[key]
try:
recurse_dict(data)
# prepend folder parts
for part in reversed(path.relative_to(root).parent.parts):
data = {part: data}
# Add to yaml_wildcards
yaml_wildcards[path.name] = data
except:
@ -177,14 +181,14 @@ def get_yaml_wildcards():
"""Returns a list of all tags found in extension YAML files found under a Tags: key."""
yaml_files = []
for path in WILDCARD_EXT_PATHS:
yaml_files.extend(p for p in path.rglob("*.yml") if p.is_file())
yaml_files.extend(p for p in path.rglob("*.yaml") if p.is_file())
yaml_files.extend((p, path) for p in path.rglob("*.yml") if p.is_file())
yaml_files.extend((p, path) for p in path.rglob("*.yaml") if p.is_file())
yaml_wildcards = {}
umi_tags = {} # { tag: count }
for path in yaml_files:
for path, root in yaml_files:
try:
with open(path, encoding="utf8") as file:
data = yaml.safe_load(file)
@ -192,7 +196,7 @@ def get_yaml_wildcards():
if (is_umi_format(data)):
parse_umi_format(umi_tags, data)
else:
parse_dynamic_prompt_format(yaml_wildcards, data, path)
parse_dynamic_prompt_format(yaml_wildcards, data, path, root)
else:
print('No data found in ' + path.name)
except (yaml.YAMLError, UnicodeDecodeError, AttributeError, TypeError) as e: