Skip to content

Commit 1430658

Browse files
author
pydn
committed
Added docstring.
1 parent 27f7a84 commit 1430658

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

comfyui_to_python.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -325,21 +325,6 @@ def assemble_python_code(self, import_statements: set, speical_functions_code: L
325325
final_code = black.format_str(final_code, mode=black.Mode())
326326

327327
return final_code
328-
329-
def clean_variable_name(self, class_type: str) -> str:
330-
clean_name = class_type.lower().strip()
331-
332-
# Convert to lowercase and replace spaces with underscores
333-
clean_name = clean_name.lower().replace("-", "_").replace(" ", "_")
334-
335-
# Remove characters that are not letters, numbers, or underscores
336-
clean_name = re.sub(r'[^a-z0-9_]', '', clean_name)
337-
338-
# Ensure that it doesn't start with a number
339-
if clean_name[0].isdigit():
340-
clean_name = "_" + clean_name
341-
342-
return clean_name
343328

344329
def get_class_info(self, class_type: str) -> Tuple[str, str, str]:
345330
"""Generates and returns necessary information about class type.
@@ -358,6 +343,23 @@ def get_class_info(self, class_type: str) -> Tuple[str, str, str]:
358343
class_code = f'{variable_name} = NODE_CLASS_MAPPINGS["{class_type}"]()'
359344

360345
return class_type, import_statement, class_code
346+
347+
@staticmethod
348+
def clean_variable_name(class_type: str) -> str:
349+
"""
350+
Remove any characters from variable name that could cause errors running the Python script.
351+
"""
352+
# Convert to lowercase and replace spaces with underscores
353+
clean_name = class_type.lower().strip().replace("-", "_").replace(" ", "_")
354+
355+
# Remove characters that are not letters, numbers, or underscores
356+
clean_name = re.sub(r'[^a-z0-9_]', '', clean_name)
357+
358+
# Ensure that it doesn't start with a number
359+
if clean_name[0].isdigit():
360+
clean_name = "_" + clean_name
361+
362+
return clean_name
361363

362364
def get_function_parameters(self, func: Callable) -> List:
363365
"""Get the names of a function's parameters.

0 commit comments

Comments
 (0)