From 727295b52e5f7b5429e81ca2179172865aa83b99 Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Thu, 24 Oct 2024 00:25:57 +0900 Subject: [PATCH] fix: wildcard bugs - cannot remove comment - cannot populate if `{count$$}` https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/789 https://github.com/ltdrdata/ComfyUI-Impact-Pack/issues/788 --- modules/impact/config.py | 2 +- modules/impact/wildcards.py | 34 +++++++++++++++++++++++++++++++--- pyproject.toml | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/modules/impact/config.py b/modules/impact/config.py index af1fcc9..0396af0 100644 --- a/modules/impact/config.py +++ b/modules/impact/config.py @@ -1,7 +1,7 @@ import configparser import os -version_code = [7, 10, 5] +version_code = [7, 10, 6] version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '') dependency_version = 23 diff --git a/modules/impact/wildcards.py b/modules/impact/wildcards.py index f6bf0c2..1509d89 100644 --- a/modules/impact/wildcards.py +++ b/modules/impact/wildcards.py @@ -58,11 +58,11 @@ def read_wildcard_dict(wildcard_path): try: with open(file_path, 'r', encoding="ISO-8859-1") as f: lines = f.read().splitlines() - wildcard_dict[key] = lines + wildcard_dict[key] = [x for x in lines if not x.strip().startswith('#')] except yaml.reader.ReaderError: with open(file_path, 'r', encoding="UTF-8", errors="ignore") as f: lines = f.read().splitlines() - wildcard_dict[key] = lines + wildcard_dict[key] = [x for x in lines if not x.strip().startswith('#')] elif file.endswith('.yaml'): file_path = os.path.join(root, file) @@ -150,7 +150,7 @@ def process(text, seed=None): matches = re.findall(wildcard_pattern, multi_select_pattern[1]) if len(options) == 1 and matches: # count$$ - options = local_wildcard_dict.get(matches[0]) + options = get_wildcard_options(multi_select_pattern[1]) else: # count$$opt1|opt2|... options[0] = multi_select_pattern[1] @@ -199,6 +199,34 @@ def process(text, seed=None): return replaced_string, replacements_found + def get_wildcard_options(string): + pattern = r"__([\w.\-+/*\\]+?)__" + matches = re.findall(pattern, string) + + options = [] + + for match in matches: + keyword = match.lower() + keyword = wildcard_normalize(keyword) + if keyword in local_wildcard_dict: + options.extend(local_wildcard_dict[keyword]) + elif '*' in keyword: + subpattern = keyword.replace('*', '.*').replace('+', '\\+') + total_patterns = [] + found = False + for k, v in local_wildcard_dict.items(): + if re.match(subpattern, k) is not None or re.match(subpattern, k+'/') is not None: + total_patterns += v + found = True + + if found: + options.extend(total_patterns) + elif '/' not in keyword: + string_fallback = string.replace(f"__{match}__", f"__*/{match}__", 1) + options.extend(get_wildcard_options(string_fallback)) + + return options + def replace_wildcard(string): pattern = r"__([\w.\-+/*\\]+?)__" matches = re.findall(pattern, string) diff --git a/pyproject.toml b/pyproject.toml index 8ad5b64..3e7fb25 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-impact-pack" description = "This extension offers various detector nodes and detailer nodes that allow you to configure a workflow that automatically enhances facial details. And provide iterative upscaler." -version = "7.10.5" +version = "7.10.6" license = { file = "LICENSE.txt" } dependencies = ["segment-anything", "scikit-image", "piexif", "transformers", "opencv-python-headless", "GitPython", "scipy>=1.11.4"]