88
99from colorama import Fore
1010from colorama import init as init_colorama
11+ from jsonschema .exceptions import ValidationError as SchemaValidationError
1112
1213import petab
14+ from petab .v1 .C import FORMAT_VERSION
15+ from petab .v2 .lint import lint_problem
16+ from petab .versions import get_major_version
17+ from petab .yaml import validate
1318
1419logger = logging .getLogger (__name__ )
1520
@@ -153,13 +158,9 @@ def main():
153158 ch .setLevel (logging .WARN )
154159
155160 if args .yaml_file_name :
156- from jsonschema .exceptions import ValidationError
157-
158- from petab .yaml import validate
159-
160161 try :
161162 validate (args .yaml_file_name )
162- except ValidationError as e :
163+ except SchemaValidationError as e :
163164 logger .error (
164165 "Provided YAML file does not adhere to PEtab " f"schema: { e } "
165166 )
@@ -171,38 +172,54 @@ def main():
171172 # problem = petab.CompositeProblem.from_yaml(args.yaml_file_name)
172173 return
173174
174- problem = petab .Problem .from_yaml (args .yaml_file_name )
175-
176- else :
177- # DEPRECATED
178- logger .debug ("Looking for..." )
179- if args .sbml_file_name :
180- logger .debug (f"\t SBML model: { args .sbml_file_name } " )
181- if args .condition_file_name :
182- logger .debug (f"\t Condition table: { args .condition_file_name } " )
183- if args .observable_file_name :
184- logger .debug (f"\t Observable table: { args .observable_file_name } " )
185- if args .measurement_file_name :
186- logger .debug (f"\t Measurement table: { args .measurement_file_name } " )
187- if args .parameter_file_name :
188- logger .debug (f"\t Parameter table: { args .parameter_file_name } " )
189- if args .visualization_file_name :
190- logger .debug (
191- "\t Visualization table: " f"{ args .visualization_file_name } "
192- )
175+ match get_major_version (args .yaml_file_name ):
176+ case 1 :
177+ problem = petab .Problem .from_yaml (args .yaml_file_name )
178+ ret = petab .lint .lint_problem (problem )
179+ sys .exit (ret )
180+ case 2 :
181+ validation_issues = lint_problem (args .yaml_file_name )
182+ if validation_issues :
183+ validation_issues .log (logger = logger )
184+ sys .exit (1 )
185+ logger .info ("PEtab format check completed successfully." )
186+ sys .exit (0 )
187+ case _:
188+ logger .error (
189+ "The provided PEtab files are of unsupported version "
190+ f"or the `{ FORMAT_VERSION } ` field is missing in the yaml "
191+ "file."
192+ )
193+
194+ # DEPRECATED - only supported for v1
195+ logger .debug ("Looking for..." )
196+ if args .sbml_file_name :
197+ logger .debug (f"\t SBML model: { args .sbml_file_name } " )
198+ if args .condition_file_name :
199+ logger .debug (f"\t Condition table: { args .condition_file_name } " )
200+ if args .observable_file_name :
201+ logger .debug (f"\t Observable table: { args .observable_file_name } " )
202+ if args .measurement_file_name :
203+ logger .debug (f"\t Measurement table: { args .measurement_file_name } " )
204+ if args .parameter_file_name :
205+ logger .debug (f"\t Parameter table: { args .parameter_file_name } " )
206+ if args .visualization_file_name :
207+ logger .debug (
208+ "\t Visualization table: " f"{ args .visualization_file_name } "
209+ )
193210
194- try :
195- problem = petab .Problem .from_files (
196- sbml_file = args .sbml_file_name ,
197- condition_file = args .condition_file_name ,
198- measurement_file = args .measurement_file_name ,
199- parameter_file = args .parameter_file_name ,
200- observable_files = args .observable_file_name ,
201- visualization_files = args .visualization_file_name ,
202- )
203- except FileNotFoundError as e :
204- logger .error (e )
205- sys .exit (1 )
211+ try :
212+ problem = petab .Problem .from_files (
213+ sbml_file = args .sbml_file_name ,
214+ condition_file = args .condition_file_name ,
215+ measurement_file = args .measurement_file_name ,
216+ parameter_file = args .parameter_file_name ,
217+ observable_files = args .observable_file_name ,
218+ visualization_files = args .visualization_file_name ,
219+ )
220+ except FileNotFoundError as e :
221+ logger .error (e )
222+ sys .exit (1 )
206223
207224 ret = petab .lint .lint_problem (problem )
208225 sys .exit (ret )
0 commit comments