Skip to content

Conversation

@longredzhong
Copy link
Contributor

This pull request adds support for generatingThis pull request adds support for generating Python scripts with keyword arguments instead of positional arguments in the WorkflowToScriptTranspiler class and its CLI. This allows users to choose between more explicit, readable function calls and the previous positional style. The change is implemented throughout the transpiler, CLI, and tests.

Support for keyword arguments in script generation:

  • Added a use_keyword_args parameter to the WorkflowToScriptTranspiler class and its factory methods (from_image, from_file) to control whether generated scripts use keyword arguments or positional arguments. [1] [2] [3]
  • Implemented the _format_args_as_keyword method to format node arguments as keyword arguments, and updated _node_to_assign_st to use this formatting when use_keyword_args is enabled. [1] [2]

CLI and test enhancements:

  • Added a --use-keyword-args flag to the CLI, allowing users to generate scripts with keyword arguments via the command line.
  • Added new parameterized tests to verify that scripts generated with use_keyword_args=True match the expected output for various workflows. Python scripts with keyword arguments instead of positional arguments in the WorkflowToScriptTranspiler class and its CLI. This allows users to choose between more explicit, readable function calls and the previous positional style. The change is implemented throughout the transpiler, CLI, and tests.

Support for keyword arguments in script generation:

  • Added a use_keyword_args parameter to the WorkflowToScriptTranspiler class and its factory methods (from_image, from_file) to control whether generated scripts use keyword arguments or positional arguments. [1] [2] [3]
  • Implemented the _format_args_as_keyword method to format node arguments as keyword arguments, and updated _node_to_assign_st to use this formatting when use_keyword_args is enabled. [1] [2]

CLI and test enhancements:

  • Added a --use-keyword-args flag to the CLI, allowing users to generate scripts with keyword arguments via the command line.
  • Added new parameterized tests to verify that scripts generated with use_keyword_args=True match the expected output for various workflows.

Example

python -m comfy_script.transpile "workflow.json" --api http://localhost:8188/ --use-keyword-args

model = UNETLoader(unet_name='z_image_turbo_bf16.safetensors', weight_dtype='default')
model = ModelSamplingAuraFlow(model=model, shift=3)
clip = CLIPLoader(clip_name='qwen_3_4b.safetensors', type='lumina2', device='default')
conditioning = CLIPTextEncode(text='Latina female with thick wavy hair, harbor boats and pastel houses behind. Breezy seaside light, warm tones, cinematic close-up. ', clip=clip)
conditioning2 = ConditioningZeroOut(conditioning=conditioning)
latent = EmptySD3LatentImage(width=1024, height=1024, batch_size=1)
latent = KSampler(model=model, seed=20014533042969, steps=9, cfg=1, sampler_name='res_multistep', scheduler='simple', positive=conditioning, negative=conditioning2, latent_image=latent, denoise=1)
vae = VAELoader(vae_name='ae.safetensors')
image = VAEDecode(samples=latent, vae=vae)
SaveImage(images=image, filename_prefix='z-image')

Copilot AI and others added 6 commits December 23, 2025 02:19
Co-authored-by: longredzhong <29575929+longredzhong@users.noreply.github.com>
Co-authored-by: longredzhong <29575929+longredzhong@users.noreply.github.com>
Co-authored-by: longredzhong <29575929+longredzhong@users.noreply.github.com>
… test coverage

Co-authored-by: longredzhong <29575929+longredzhong@users.noreply.github.com>
…support

Add keyword argument support to transpiler
Copilot AI review requested due to automatic review settings December 23, 2025 06:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for generating Python scripts with keyword arguments instead of positional arguments in the WorkflowToScriptTranspiler class. This enhancement allows users to choose between explicit, readable function calls with named parameters and the previous positional style.

  • Added use_keyword_args parameter throughout the transpiler infrastructure (constructor, factory methods, and CLI)
  • Implemented _format_args_as_keyword method to format node arguments as keyword arguments
  • Added comprehensive parameterized tests for verifying keyword argument generation

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/comfy_script/transpile/__init__.py Added use_keyword_args parameter to WorkflowToScriptTranspiler class and factory methods; implemented _format_args_as_keyword method; updated _node_to_assign_st to conditionally use keyword argument formatting
src/comfy_script/transpile/__main__.py Added --use-keyword-args CLI flag and passed it through to the transpiler
tests/transpile/test_transpiler.py Added new parameterized test function test_workflow_with_keyword_args with test cases for various workflow types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Chaoses-Ib Chaoses-Ib added enhancement New feature or request transpiler labels Dec 24, 2025
@Chaoses-Ib
Copy link
Owner

Thanks for your PR. I've changed the CLI usage to --args kwd. And the default behavior is changed to format as keyword arguments if there are more than 2 inputs:

model, clip, vae = CheckpointLoaderSimple('v1-5-pruned-emaonly.ckpt')
conditioning = CLIPTextEncode('beautiful scenery nature glass bottle landscape, , purple galaxy bottle,', clip)
conditioning2 = CLIPTextEncode('text, watermark', clip)
latent = EmptyLatentImage(width=512, height=512, batch_size=1)
latent = KSampler(model=model, seed=156680208700286, steps=20, cfg=8, sampler_name='euler', scheduler='normal', positive=conditioning, negative=conditioning2, latent_image=latent, denoise=1)
image = VAEDecode(latent, vae)
SaveImage(image, 'ComfyUI')

@Chaoses-Ib Chaoses-Ib merged commit 96e8f47 into Chaoses-Ib:main Dec 24, 2025
@Chaoses-Ib Chaoses-Ib linked an issue Dec 24, 2025 that may be closed by this pull request
4 tasks
@Chaoses-Ib Chaoses-Ib mentioned this pull request Dec 24, 2025
4 tasks
@Chaoses-Ib
Copy link
Owner

Pre-released in https://github.com/Chaoses-Ib/ComfyScript/releases/tag/v0.7.0a1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request transpiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transpiling unknown nodes

2 participants