Skip to content

Commit d59824c

Browse files
authored
Fix bug in CLI with calling a factory-fn inside a list (#214)
* Fix bug in CLI with calling a factory-fn inside a list Signed-off-by: Marc Romeyn <[email protected]> * Remove breakpoint Signed-off-by: Marc Romeyn <[email protected]> * Remove old code Signed-off-by: Marc Romeyn <[email protected]> --------- Signed-off-by: Marc Romeyn <[email protected]>
1 parent 8b6370f commit d59824c

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

nemo_run/cli/cli_parser.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,13 +1261,35 @@ def parse_single_factory(factory_str):
12611261
return factory_fn()
12621262

12631263
# Check if the value is a list
1264-
list_match = re.match(r"^\s*\[(.*)\]\s*$", value)
1265-
if list_match:
1264+
if value.startswith("[") and value.endswith("]"):
12661265
# Check if arg_type is List[T], if so get T
12671266
if get_origin(arg_type) is list:
12681267
arg_type = get_args(arg_type)[0]
1269-
items = re.findall(r"([^,]+(?:\([^)]*\))?)", list_match.group(1))
1270-
return [parse_single_factory(item.strip()) for item in items]
1268+
1269+
# Parse list with nested structure handling
1270+
inner = value.strip("[] ")
1271+
elements = []
1272+
current = ""
1273+
nesting = 0
1274+
1275+
# Parse character by character to handle nested structures
1276+
for char in inner:
1277+
if char == "," and nesting == 0:
1278+
if current.strip():
1279+
elements.append(current.strip())
1280+
current = ""
1281+
else:
1282+
if char in "([{":
1283+
nesting += 1
1284+
elif char in ")]}":
1285+
nesting -= 1
1286+
current += char
1287+
1288+
# Add the last element if it exists
1289+
if current.strip():
1290+
elements.append(current.strip())
1291+
1292+
return [parse_single_factory(item.strip()) for item in elements]
12711293

12721294
return parse_single_factory(value)
12731295

0 commit comments

Comments
 (0)