@@ -207,12 +207,14 @@ def check_metadata(self):
207
207
"copyfile" ,
208
208
"help_string" ,
209
209
"mandatory" ,
210
+ "readonly" ,
210
211
"output_field_name" ,
211
212
"output_file_template" ,
212
213
"position" ,
213
214
"requires" ,
214
215
"separate_ext" ,
215
216
"xor" ,
217
+ "sep" ,
216
218
}
217
219
# special inputs, don't have to follow rules for standard inputs
218
220
special_input = ["_func" , "_graph_checksums" ]
@@ -222,22 +224,23 @@ def check_metadata(self):
222
224
mdata = fld .metadata
223
225
# checking keys from metadata
224
226
if set (mdata .keys ()) - supported_keys :
225
- raise Exception (
227
+ raise AttributeError (
226
228
f"only these keys are supported { supported_keys } , but "
227
229
f"{ set (mdata .keys ()) - supported_keys } provided"
228
230
)
229
231
# checking if the help string is provided (required field)
230
232
if "help_string" not in mdata :
231
- raise Exception (f"{ fld .name } doesn't have help_string field" )
232
-
233
+ raise AttributeError (f"{ fld .name } doesn't have help_string field" )
233
234
# assuming that fields with output_file_template shouldn't have default
234
- if not fld .default == attr .NOTHING and mdata .get ("output_file_template" ):
235
- raise Exception (
235
+ if fld .default not in [attr .NOTHING , True , False ] and mdata .get (
236
+ "output_file_template"
237
+ ):
238
+ raise AttributeError (
236
239
"default value should not be set together with output_file_template"
237
240
)
238
241
# not allowing for default if the field is mandatory
239
242
if not fld .default == attr .NOTHING and mdata .get ("mandatory" ):
240
- raise Exception (
243
+ raise AttributeError (
241
244
"default value should not be set when the field is mandatory"
242
245
)
243
246
# setting default if value not provided and default is available
@@ -260,15 +263,17 @@ def check_fields_input_spec(self):
260
263
# checking if the mandatory field is provided
261
264
if getattr (self , fld .name ) is attr .NOTHING :
262
265
if mdata .get ("mandatory" ):
263
- raise Exception (f"{ fld .name } is mandatory, but no value provided" )
266
+ raise AttributeError (
267
+ f"{ fld .name } is mandatory, but no value provided"
268
+ )
264
269
else :
265
270
continue
266
271
names .append (fld .name )
267
272
268
273
# checking if fields meet the xor and requires are
269
274
if "xor" in mdata :
270
275
if [el for el in mdata ["xor" ] if el in names ]:
271
- raise Exception (
276
+ raise AttributeError (
272
277
f"{ fld .name } is mutually exclusive with { mdata ['xor' ]} "
273
278
)
274
279
@@ -283,15 +288,15 @@ def check_fields_input_spec(self):
283
288
for nm , required in require_to_check .items ():
284
289
required_notfound = [el for el in required if el not in names ]
285
290
if required_notfound :
286
- raise Exception (f"{ nm } requires { required_notfound } " )
291
+ raise AttributeError (f"{ nm } requires { required_notfound } " )
287
292
288
293
# TODO: types might be checked here
289
294
self ._type_checking ()
290
295
291
296
def _file_check (self , field ):
292
297
file = Path (getattr (self , field .name ))
293
298
if not file .exists ():
294
- raise Exception (f"the file from the { field .name } input does not exist" )
299
+ raise AttributeError (f"the file from the { field .name } input does not exist" )
295
300
296
301
def _type_checking (self ):
297
302
"""Use fld.type to check the types TODO.
@@ -327,7 +332,9 @@ def collect_additional_outputs(self, input_spec, inputs, output_dir):
327
332
if (
328
333
fld .default is None or fld .default == attr .NOTHING
329
334
) and not fld .metadata : # TODO: is it right?
330
- raise Exception ("File has to have default value or metadata" )
335
+ raise AttributeError (
336
+ "File has to have default value or metadata"
337
+ )
331
338
elif not fld .default == attr .NOTHING :
332
339
additional_out [fld .name ] = self ._field_defaultvalue (
333
340
fld , output_dir
@@ -343,7 +350,7 @@ def collect_additional_outputs(self, input_spec, inputs, output_dir):
343
350
def _field_defaultvalue (self , fld , output_dir ):
344
351
"""Collect output file if the default value specified."""
345
352
if not isinstance (fld .default , (str , Path )):
346
- raise Exception (
353
+ raise AttributeError (
347
354
f"{ fld .name } is a File, so default value "
348
355
f"should be a string or a Path, "
349
356
f"{ fld .default } provided"
@@ -358,15 +365,15 @@ def _field_defaultvalue(self, fld, output_dir):
358
365
if default .exists ():
359
366
return default
360
367
else :
361
- raise Exception (f"file { default } does not exist" )
368
+ raise AttributeError (f"file { default } does not exist" )
362
369
else :
363
370
all_files = list (Path (default .parent ).expanduser ().glob (default .name ))
364
371
if len (all_files ) > 1 :
365
372
return all_files
366
373
elif len (all_files ) == 1 :
367
374
return all_files [0 ]
368
375
else :
369
- raise Exception (f"no file matches { default .name } " )
376
+ raise AttributeError (f"no file matches { default .name } " )
370
377
371
378
def _field_metadata (self , fld , inputs , output_dir ):
372
379
"""Collect output file if metadata specified."""
0 commit comments