@@ -232,6 +232,12 @@ def load(cls, settings, init=True, ignore=None):
232
232
else :
233
233
setattr (cls , k , Path (v ).absolute ())
234
234
elif hasattr (cls , k ):
235
+ match k :
236
+ # Handle special deserializations
237
+ case 'processing_groups' :
238
+ v = _deserialize_pg (v )
239
+ case _:
240
+ pass
235
241
setattr (cls , k , v )
236
242
237
243
if init :
@@ -785,6 +791,10 @@ def get(flat=False):
785
791
'nipype' : nipype .get (),
786
792
'seeds' : seeds .get (),
787
793
}
794
+
795
+ if (pg := settings ['execution' ].get ('processing_groups' )):
796
+ settings ['execution' ]['processing_groups' ] = _serialize_pg (pg )
797
+
788
798
if not flat :
789
799
return settings
790
800
@@ -836,3 +846,50 @@ def init_spaces(checkpoint=True):
836
846
837
847
# Make the SpatialReferences object available
838
848
workflow .spaces = spaces
849
+
850
+ def _serialize_pg (value : list [tuple [str , list [str ] | None ]]) -> list [str ]:
851
+ """
852
+ Serialize a list of participant-session tuples to be TOML-compatible.
853
+
854
+ Examples
855
+ --------
856
+ >>> _serialize_pg([('01', ['pre']), ('01', ['post'])])
857
+ ['01:pre', '01:post']
858
+ >>> _serialize_pg([('01', ['pre', 'post']), ('02', ['post'])])
859
+ ['01:pre,post', '02:post']
860
+ >>> _serialize_pg([('01', None), ('02', ['pre'])])
861
+ ['01', '02:pre']
862
+ """
863
+ serial = []
864
+ for val in value :
865
+ if val [1 ] is None :
866
+ serial .append (val [0 ])
867
+ else :
868
+ if not isinstance (val [1 ], list ):
869
+ val [1 ] = [val [1 ]]
870
+ serial .append (f'{ val [0 ]} :{ "," .join (val [1 ])} ' )
871
+ return serial
872
+
873
+
874
+ def _deserialize_pg (value : list [str ]) -> list [tuple [str , list [str ] | None ]]:
875
+ """
876
+ Deserialize a list of participant-session tuples to be TOML-compatible.
877
+
878
+ Examples
879
+ --------
880
+ >>> _deserialize_pg(['01:pre', '01:post'])
881
+ [('01', ['pre']), ('01', ['post'])]
882
+ >>> _deserialize_pg(['01:pre,post', '02:post'])
883
+ [('01', ['pre', 'post']), ('02', ['post'])]
884
+ >>> _deserialize_pg(['01', '02:pre'])
885
+ [('01', None), ('02', ['pre'])]
886
+ """
887
+ deserial = []
888
+ for val in value :
889
+ vals = val .split (':' , 1 )
890
+ if len (vals ) == 1 :
891
+ vals .append (None )
892
+ else :
893
+ vals [1 ] = vals [1 ].split (',' )
894
+ deserial .append (tuple (vals ))
895
+ return deserial
0 commit comments