Bugfixes for args, updated the README
This commit is contained in:
@@ -11,7 +11,7 @@ from typing import Dict, List, Any, Callable, Tuple, TextIO
|
||||
import black
|
||||
|
||||
|
||||
from comfyui_to_python_utils import import_custom_nodes, find_path, add_comfyui_directory_to_sys_path, add_extra_model_paths, get_value_at_index
|
||||
from comfyui_to_python_utils import import_custom_nodes, find_path, add_comfyui_directory_to_sys_path, add_extra_model_paths, get_value_at_index, parse_arg
|
||||
|
||||
add_comfyui_directory_to_sys_path()
|
||||
from nodes import NODE_CLASS_MAPPINGS
|
||||
@@ -202,7 +202,7 @@ class CodeGenerator:
|
||||
arg_inputs.append((input_var, f"Argument {i}, input `{input}` for node \\\"{data['_meta'].get('title', class_type)}\\\" id {idx}"))
|
||||
print("WARNING: Missing required input", input, "for", class_type)
|
||||
print("That will be CLI arg " + str(len(arg_inputs)))
|
||||
missing.append((input_var, len(arg_inputs)))
|
||||
missing.append((input, input_var, len(arg_inputs)))
|
||||
|
||||
class_def = self.node_class_mappings[class_type]()
|
||||
|
||||
@@ -225,8 +225,8 @@ class CodeGenerator:
|
||||
|
||||
# Remove any keyword arguments from **inputs if they are not in class_def_params
|
||||
inputs = {key: value for key, value in inputs.items() if key in class_def_params}
|
||||
for input, arg in missing:
|
||||
inputs[input] = {"variable_name": f"argv." + input}
|
||||
for input, input_var, arg in missing:
|
||||
inputs[input] = {"variable_name": f"parse_arg(args." + input_var + ")"}
|
||||
# Deal with hidden variables
|
||||
if 'unique_id' in class_def_params:
|
||||
inputs['unique_id'] = random.randint(1, 2**64)
|
||||
@@ -303,18 +303,18 @@ class CodeGenerator:
|
||||
"""
|
||||
# Get the source code of the utils functions as a string
|
||||
func_strings = []
|
||||
for func in [get_value_at_index, find_path, add_comfyui_directory_to_sys_path, add_extra_model_paths, import_custom_nodes]:
|
||||
for func in [get_value_at_index, find_path, add_comfyui_directory_to_sys_path, add_extra_model_paths, import_custom_nodes, parse_arg]:
|
||||
func_strings.append(f'\n{inspect.getsource(func)}')
|
||||
|
||||
argparse_code = ""
|
||||
if arg_inputs:
|
||||
argparse_code = f'argv = sys.argv[:]\n\nparser = argparse.ArgumentParser(description="A converted ComfyUI workflow. Required inputs listed below. Values passed should be in JSON")\n'
|
||||
argparse_code = f'\nparser = argparse.ArgumentParser(description="A converted ComfyUI workflow. Required inputs listed below. Values passed should be in JSON")\n'
|
||||
for i, (input_name, arg_desc) in enumerate(arg_inputs):
|
||||
argparse_code += f'parser.add_argument("{input_name}", help="{arg_desc} (autogenerated)")\n'
|
||||
argparse_code += 'args = parser.parse_args()\nsys.argv = [sys.argv[0]]\n'
|
||||
|
||||
# Define static import statements required for the script
|
||||
static_imports = ['import os', 'import random', 'import sys', 'import argparse', 'from typing import Sequence, Mapping, Any, Union',
|
||||
static_imports = ['import os', 'import random', 'import sys', 'import json', 'import argparse', 'from typing import Sequence, Mapping, Any, Union',
|
||||
'import torch'] + func_strings + [argparse_code]
|
||||
# Check if custom nodes should be included
|
||||
if custom_nodes:
|
||||
|
||||
Reference in New Issue
Block a user