@@ -125,26 +125,32 @@ def _parse_slurm_nodelist(nodelist: str) -> str:
125125 - Simple list: "node001,node002" -> "node001"
126126 - Range: "node[001-004]" -> "node001"
127127 - List in brackets: "node[001,003,005]" -> "node001"
128+ - Mixed entries: "nodeA,nodeB[1-3],nodeC" -> "nodeA"
128129
129130 Args:
130131 nodelist: The SLURM nodelist string to parse.
131132
132133 Returns:
133134 The hostname of the first node in the list.
134135 """
135- # Handle bracket notation: "prefix[range]" or "prefix[list]"
136- if "[" in nodelist :
137- # Split into base and range part
138- # e.g., "node[001-004]" -> base="node", range_part="001-004"
139- base = nodelist .split ("[" )[0 ]
140- range_part = nodelist .split ("[" )[1 ].split ("]" )[0 ]
141-
142- # Handle both ranges (001-004) and lists (001,003,005)
143- # Extract first element
144- first_element = range_part .split ("," )[0 ].split ("-" )[0 ]
145-
136+ # Find the first entry by scanning for a top-level comma (i.e., one
137+ # that is not inside a "[...]" group).
138+ in_bracket = False
139+ end = len (nodelist )
140+ for i , ch in enumerate (nodelist ):
141+ if ch == "[" :
142+ in_bracket = True
143+ elif ch == "]" :
144+ in_bracket = False
145+ elif ch == "," and not in_bracket :
146+ end = i
147+ break
148+ first = nodelist [:end ].strip ()
149+
150+ # If the first entry itself uses bracket expansion, expand to the first node.
151+ if "[" in first :
152+ base , _ , rest = first .partition ("[" )
153+ inside = rest .split ("]" )[0 ]
154+ first_element = inside .split ("," )[0 ].split ("-" )[0 ]
146155 return f"{ base } { first_element } "
147- else :
148- # Simple comma-separated list
149- # e.g., "node001,node002,node003" -> "node001"
150- return nodelist .split ("," )[0 ].strip ()
156+ return first
0 commit comments