@@ -400,45 +400,26 @@ def load_models(args):
400400 models = []
401401 model_names = set ()
402402
403- def add_model (model ):
404- models .append (model )
403+ model_root = (Path (__file__ ).resolve ().parent / '../../models' ).resolve ()
405404
406- if models [- 1 ].name in model_names :
407- raise DeserializationError (
408- 'Duplicate model name "{}"' .format (models [- 1 ].name ))
409- model_names .add (models [- 1 ].name )
405+ for config_path in sorted (model_root .glob ('**/model.yml' )):
406+ subdirectory = config_path .parent .relative_to (model_root )
410407
411- if args . config is None : # per-model configs
412- model_root = ( Path ( __file__ ). resolve (). parent / '../../models' ). resolve ()
408+ with config_path . open ( 'rb' ) as config_file , \
409+ deserialization_context ( 'In config "{}"' . format ( config_path )):
413410
414- for config_path in sorted (model_root .glob ('**/model.yml' )):
415- subdirectory = config_path .parent .relative_to (model_root )
411+ model = yaml .safe_load (config_file )
416412
417- with config_path .open ('rb' ) as config_file , \
418- deserialization_context ('In config "{}"' .format (config_path )):
413+ for bad_key in ['name' , 'subdirectory' ]:
414+ if bad_key in model :
415+ raise DeserializationError ('Unsupported key "{}"' .format (bad_key ))
419416
420- model = yaml . safe_load ( config_file )
417+ models . append ( Model . deserialize ( model , subdirectory . name , subdirectory ) )
421418
422- for bad_key in ['name' , 'subdirectory' ]:
423- if bad_key in model :
424- raise DeserializationError ('Unsupported key "{}"' .format (bad_key ))
425-
426- add_model (Model .deserialize (model , subdirectory .name , subdirectory ))
427-
428- else : # monolithic config
429- print ('########## Warning: the --config option is deprecated and will be removed in a future release' ,
430- file = sys .stderr )
431- with args .config .open ('rb' ) as config_file , \
432- deserialization_context ('In config "{}"' .format (args .config )):
433- for i , model in enumerate (yaml .safe_load (config_file )['topologies' ]):
434- with deserialization_context ('In model #{}' .format (i )):
435- name = validate_string ('"name"' , model ['name' ])
436- if not name : raise DeserializationError ('"name": must not be empty' )
437-
438- with deserialization_context ('In model "{}"' .format (name )):
439- subdirectory = validate_relative_path ('"output"' , model ['output' ])
440-
441- add_model (Model .deserialize (model , name , subdirectory ))
419+ if models [- 1 ].name in model_names :
420+ raise DeserializationError (
421+ 'Duplicate model name "{}"' .format (models [- 1 ].name ))
422+ model_names .add (models [- 1 ].name )
442423
443424 return models
444425
0 commit comments