From c3b352c6b8bb0878633d2d881f8cf886f4280788 Mon Sep 17 00:00:00 2001 From: Zhu Yucheng <16608226+zhu-yucheng_1119@user.noreply.gitee.com> Date: Fri, 6 Feb 2026 17:02:54 +0800 Subject: [PATCH 1/3] Fix: Clean colons from node IDs in variable names - Add explicit colon replacement in clean_variable_name() method - Apply clean_variable_name() to node IDs when creating executed_variables - Add empty string check to prevent IndexError - Fixes InvalidInput error when Black tries to parse generated code with colons in variable names (e.g., 'cliptextencode_92:4') This resolves the issue where ComfyUI node IDs containing colons (like '92:4') were being used directly in Python variable names, creating invalid syntax. --- comfyui_to_python.py | 58 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/comfyui_to_python.py b/comfyui_to_python.py index d654069..6986c62 100644 --- a/comfyui_to_python.py +++ b/comfyui_to_python.py @@ -263,7 +263,9 @@ def generate_workflow( inputs["unique_id"] = random.randint(1, 2**64) # Create executed variable and generate code - executed_variables[idx] = f"{self.clean_variable_name(class_type)}_{idx}" + executed_variables[idx] = ( + f"{self.clean_variable_name(class_type)}_{self.clean_variable_name(str(idx))}" + ) inputs = self.update_inputs(inputs, executed_variables) if is_special_function: @@ -336,14 +338,17 @@ def format_arg(self, key: str, value: any) -> str: Returns: str: Formatted argument as a string. """ - if key == "noise_seed" or key == "seed": - return f"{key}=random.randint(1, 2**64)" + # Clean the key to ensure it's a valid Python identifier + clean_key = self.clean_parameter_name(key) + + if clean_key == "noise_seed" or clean_key == "seed": + return f"{clean_key}=random.randint(1, 2**64)" elif isinstance(value, str): value = value.replace("\n", "\\n").replace('"', "'") - return f'{key}="{value}"' + return f'{clean_key}="{value}"' elif isinstance(value, dict) and "variable_name" in value: - return f'{key}={value["variable_name"]}' - return f"{key}={value}" + return f'{clean_key}={value["variable_name"]}' + return f"{clean_key}={value}" def assemble_python_code( self, @@ -444,18 +449,55 @@ def clean_variable_name(class_type: str) -> str: Returns: str: Cleaned variable name with no special characters or spaces """ - # Convert to lowercase and replace spaces with underscores - clean_name = class_type.lower().strip().replace("-", "_").replace(" ", "_") + # Convert to lowercase and replace spaces, hyphens, and colons with underscores + clean_name = ( + class_type.lower() + .strip() + .replace("-", "_") + .replace(" ", "_") + .replace(":", "_") + ) # Remove characters that are not letters, numbers, or underscores clean_name = re.sub(r"[^a-z0-9_]", "", clean_name) + # If the name is empty after cleaning, provide a default + if not clean_name: + clean_name = "var" + # Ensure that it doesn't start with a number if clean_name[0].isdigit(): clean_name = "_" + clean_name return clean_name + @staticmethod + def clean_parameter_name(param_name: str) -> str: + """ + Clean parameter names to ensure they are valid Python identifiers. + + Args: + param_name (str): Original parameter name. + + Returns: + str: Cleaned parameter name that is a valid Python identifier. + """ + # Convert to lowercase and replace spaces with underscores + clean_name = param_name.lower().strip().replace("-", "_").replace(" ", "_") + + # Remove characters that are not letters, numbers, or underscores (including emojis) + clean_name = re.sub(r"[^a-z0-9_]", "", clean_name) + + # Ensure that it doesn't start with a number + if clean_name and clean_name[0].isdigit(): + clean_name = "_" + clean_name + + # If the name is empty after cleaning, provide a default + if not clean_name: + clean_name = "param" + + return clean_name + def get_function_parameters(self, func: Callable) -> List: """Get the names of a function's parameters. From e05f2aeb6c4f5477c6555b09ee9d2a3c7aa3a395 Mon Sep 17 00:00:00 2001 From: Zhu Yucheng <16608226+zhu-yucheng_1119@user.noreply.gitee.com> Date: Fri, 6 Feb 2026 17:07:39 +0800 Subject: [PATCH 2/3] docs: Add v1.3.1 release notes to README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 69d5602..2bd7386 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,11 @@ if __name__ == "__main__": - Creating large queues for image generation (For example, you could adjust the script to generate 1000 images without clicking ctrl+enter 1000 times) - Easily expanding or iterating on your architecture in Python once a foundational workflow is in place in the GUI +## V1.3.1 Release Notes +- Fix compatibility issue with newer ComfyUI versions where node IDs contain colons +- Properly sanitize node IDs in variable names to prevent Python syntax errors +- Add safety checks for empty variable names after cleaning + ## V1.3.0 Release Notes - Generate .py file directly from the ComfyUI Web App From 39e43be345c93ab264c49b12417e8af9793fa18c Mon Sep 17 00:00:00 2001 From: Zhu Yucheng <16608226+zhu-yucheng_1119@user.noreply.gitee.com> Date: Fri, 6 Feb 2026 17:23:18 +0800 Subject: [PATCH 3/3] docs: Specify ComfyUI v0.11.0+ in release notes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2bd7386..2bef253 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ if __name__ == "__main__": - Easily expanding or iterating on your architecture in Python once a foundational workflow is in place in the GUI ## V1.3.1 Release Notes -- Fix compatibility issue with newer ComfyUI versions where node IDs contain colons +- Fix compatibility issue with ComfyUI v0.11.0+ where node IDs contain colons - Properly sanitize node IDs in variable names to prevent Python syntax errors - Add safety checks for empty variable names after cleaning