Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions nemo_run/cli/cli_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,13 +1253,35 @@ def parse_single_factory(factory_str):
return factory_fn()

# Check if the value is a list
list_match = re.match(r"^\s*\[(.*)\]\s*$", value)
if list_match:
if value.startswith("[") and value.endswith("]"):
# Check if arg_type is List[T], if so get T
if get_origin(arg_type) is list:
arg_type = get_args(arg_type)[0]
items = re.findall(r"([^,]+(?:\([^)]*\))?)", list_match.group(1))
return [parse_single_factory(item.strip()) for item in items]

# Parse list with nested structure handling
inner = value.strip("[] ")
elements = []
current = ""
nesting = 0

# Parse character by character to handle nested structures
for char in inner:
if char == "," and nesting == 0:
if current.strip():
elements.append(current.strip())
current = ""
else:
if char in "([{":
nesting += 1
elif char in ")]}":
nesting -= 1
current += char

# Add the last element if it exists
if current.strip():
elements.append(current.strip())

return [parse_single_factory(item.strip()) for item in elements]

return parse_single_factory(value)

Expand Down
Loading