@@ -829,11 +829,12 @@ def _rl_encode(seq):
829
829
830
830
831
831
def _parse_node (nodename ):
832
- m = re .search (r'(.*\D)(\d+)' , nodename )
832
+ m = re .search (r'(.*\D)(\d+)(\D*) ' , nodename )
833
833
if m is None :
834
834
basename = nodename
835
835
width = 0
836
836
nodeid = None
837
+ suffix = None
837
838
else :
838
839
basename = m .group (1 )
839
840
_id = m .group (2 ).lstrip ('0' )
@@ -843,8 +844,9 @@ def _parse_node(nodename):
843
844
844
845
nodeid = int (_id )
845
846
width = len (m .group (2 ))
847
+ suffix = m .group (3 )
846
848
847
- return basename , width , nodeid
849
+ return basename , width , nodeid , suffix
848
850
849
851
850
852
def count_digits (n ):
@@ -873,15 +875,20 @@ def _common_prefix(s1, s2):
873
875
874
876
875
877
class _NodeGroup :
876
- def __init__ (self , name , width ):
878
+ def __init__ (self , name , width , suffix ):
877
879
self .__name = name
880
+ self .__suffix = suffix
878
881
self .__width = width
879
882
self .__nodes = []
880
883
881
884
@property
882
885
def name (self ):
883
886
return self .__name
884
887
888
+ @property
889
+ def suffix (self ):
890
+ return self .__suffix
891
+
885
892
@property
886
893
def width (self ):
887
894
return self .__width
@@ -903,12 +910,12 @@ def __str__(self):
903
910
start , delta , size = unit
904
911
if size == 1 :
905
912
s_start = str (start ).zfill (self .width )
906
- abbrev .append (f'{ self .name } { s_start } ' )
913
+ abbrev .append (f'{ self .name } { s_start } { self . suffix } ' )
907
914
elif delta != 1 :
908
915
# We simply unpack node lists with delta != 1
909
916
for i in range (size ):
910
917
s_start = str (start + i * delta ).zfill (self .width )
911
- abbrev .append (f'{ self .name } { s_start } ' )
918
+ abbrev .append (f'{ self .name } { s_start } { self . suffix } ' )
912
919
else :
913
920
last = start + delta * (size - 1 )
914
921
digits_last = count_digits (last )
@@ -921,19 +928,21 @@ def __str__(self):
921
928
s_first = str (start ).zfill (digits_last )
922
929
s_last = str (last )
923
930
prefix , s_first , s_last = _common_prefix (s_first , s_last )
924
- nd_range += f'{ prefix } [{ s_first } -{ s_last } ]'
931
+ nd_range += f'{ prefix } [{ s_first } -{ s_last } ]{ self . suffix } '
925
932
abbrev .append (nd_range )
926
933
927
934
return ',' .join (abbrev )
928
935
929
936
def __hash__ (self ):
930
- return hash (self .name ) ^ hash (self .width )
937
+ return hash (self .name ) ^ hash (self .suffix ) ^ hash ( self . width )
931
938
932
939
def __eq__ (self , other ):
933
940
if not isinstance (other , _NodeGroup ):
934
941
return NotImplemented
935
942
936
- return self .name == other .name and self .width == other .width
943
+ return (self .name == other .name and
944
+ self .suffix == other .suffix and
945
+ self .width == other .width )
937
946
938
947
939
948
def nodelist_abbrev (nodes ):
@@ -978,8 +987,8 @@ def nodelist_abbrev(nodes):
978
987
979
988
node_groups = {}
980
989
for n in sorted (nodes ):
981
- basename , width , nid = _parse_node (n )
982
- ng = _NodeGroup (basename , width )
990
+ basename , width , nid , suffix = _parse_node (n )
991
+ ng = _NodeGroup (basename , width , suffix )
983
992
node_groups .setdefault (ng , ng )
984
993
if nid is not None :
985
994
node_groups [ng ].add (nid )
@@ -1004,7 +1013,9 @@ def nodelist_expand(nodespec):
1004
1013
return []
1005
1014
1006
1015
nodespec_parts = nodespec .split (',' )
1007
- node_patt = re .compile (r'(?P<prefix>.+)\[(?P<l>\d+)-(?P<u>\d+)\]' )
1016
+ node_patt = re .compile (
1017
+ r'(?P<prefix>.+)\[(?P<l>\d+)-(?P<u>\d+)\](?P<suffix>.*)'
1018
+ )
1008
1019
nodes = []
1009
1020
for ns in nodespec_parts :
1010
1021
if '[' not in ns and ']' not in ns :
@@ -1015,11 +1026,11 @@ def nodelist_expand(nodespec):
1015
1026
if not match :
1016
1027
raise ValueError (f'invalid nodespec: { nodespec } ' )
1017
1028
1018
- prefix = match .group ('prefix' )
1029
+ prefix , suffix = match .group ('prefix' ), match . group ( 'suffix ' )
1019
1030
low , upper = int (match .group ('l' )), int (match .group ('u' ))
1020
1031
width = count_digits (upper )
1021
1032
for nid in range (low , upper + 1 ):
1022
- nodes .append (f'{ prefix } { nid :0{width }} ' )
1033
+ nodes .append (f'{ prefix } { nid :0{width }} { suffix } ' )
1023
1034
1024
1035
return nodes
1025
1036
0 commit comments