88
99import jsonschema
1010import numpy as np
11+ import pandas as pd
1112import yaml
1213from pandas .io .common import get_handle
1314
@@ -110,25 +111,46 @@ def validate_yaml_semantics(
110111 """
111112 if not path_prefix :
112113 if isinstance (yaml_config , str | Path ):
113- path_prefix = os . path . dirname ( str ( yaml_config ) )
114+ path_prefix = get_path_prefix ( yaml_config )
114115 else :
115116 path_prefix = ""
116117
117118 yaml_config = load_yaml (yaml_config )
118119
119120 def _check_file (_filename : str , _field : str ):
120- if not os .path .isfile (_filename ):
121+ # this could be a regular path or some local or remote URL
122+ # the simplest check is just trying to load the respective table or
123+ # sbml model
124+ if _field == SBML_FILES :
125+ from ..models .sbml_model import SbmlModel
126+
127+ try :
128+ SbmlModel .from_file (_filename )
129+ except Exception as e :
130+ raise AssertionError (
131+ f"Failed to read '{ _filename } ' provided as '{ _field } '."
132+ ) from e
133+ return
134+
135+ try :
136+ pd .read_csv (_filename , sep = "\t " )
137+ except pd .errors .EmptyDataError :
138+ # at this stage, we don't care about the content
139+ pass
140+ except Exception as e :
121141 raise AssertionError (
122- f"File '{ _filename } ' provided as '{ _field } ' " "does not exist ."
123- )
142+ f"Failed to read '{ _filename } ' provided as '{ _field } '."
143+ ) from e
124144
125145 # Handles both a single parameter file, and a parameter file that has been
126146 # split into multiple subset files.
127147 for parameter_subset_file in list (
128148 np .array (yaml_config [PARAMETER_FILE ]).flat
129149 ):
130150 _check_file (
131- os .path .join (path_prefix , parameter_subset_file ),
151+ f"{ path_prefix } /{ parameter_subset_file } "
152+ if path_prefix
153+ else parameter_subset_file ,
132154 parameter_subset_file ,
133155 )
134156
@@ -142,7 +164,12 @@ def _check_file(_filename: str, _field: str):
142164 ]:
143165 if field in problem_config :
144166 for filename in problem_config [field ]:
145- _check_file (os .path .join (path_prefix , filename ), field )
167+ _check_file (
168+ f"{ path_prefix } /{ filename } "
169+ if path_prefix
170+ else filename ,
171+ field ,
172+ )
146173
147174
148175def load_yaml (yaml_config : dict | Path | str ) -> dict :
0 commit comments