Skip to content

Commit 2ad5ee6

Browse files
author
Peyton
committed
Added code styling with black.
1 parent a3630c6 commit 2ad5ee6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ComfyUI-to-Python-Extension/generate_python_code.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from nodes import NODE_CLASS_MAPPINGS
1212

13+
import black
14+
1315
logging.basicConfig(level=logging.INFO)
1416

1517

@@ -154,7 +156,7 @@ def format_arg(key: str, value: any) -> str:
154156
args = ', '.join(format_arg(key, value) for key, value in kwargs.items())
155157

156158
# Generate the Python code
157-
code = f'{variable_name} = {obj_name}.{func}({args})'
159+
code = f'{variable_name} = {obj_name}.{func}({args})\n'
158160

159161
# If the code contains dependencies, indent the code because it will be placed inside
160162
# of a for loop
@@ -217,8 +219,10 @@ def assemble_python_code(import_statements: set, loader_code: List[str], code: L
217219
"""
218220
static_imports = ['import random']
219221
imports_code = [f"from nodes import {class_name}" for class_name in import_statements]
220-
main_function_code = f"def main():\n\t" + '\n\t'.join(loader_code) + f'\n\tfor q in {range(1, queue_size)}:\n\t' + '\n\t'.join(code)
222+
main_function_code = f"def main():\n\t" + '\n\t'.join(loader_code) + f'\n\n\tfor q in {range(1, queue_size)}:\n\t' + '\n\t'.join(code)
221223
final_code = '\n'.join(static_imports + ['import sys\nsys.path.append("../")'] + imports_code + ['', main_function_code, '', 'if __name__ == "__main__":', '\tmain()'])
224+
final_code = black.format_str(final_code, mode=black.Mode())
225+
222226

223227
return final_code
224228

0 commit comments

Comments
 (0)