@@ -21,17 +21,22 @@ def __repr__(self):
2121
2222 @staticmethod
2323 @abc .abstractmethod
24- def from_file (filepath_or_buffer : Any , model_id : str ) -> Model :
24+ def from_file (
25+ filepath_or_buffer : Any , model_id : str , base_path : str | Path = None
26+ ) -> Model :
2527 """Load the model from the given path/URL
2628
27- :param filepath_or_buffer: URL or path of the model
29+ :param filepath_or_buffer:
30+ Absolute or relative path/URL to the model file.
31+ If relative, it is interpreted relative to `base_path` if given.
32+ :param base_path: Base path for relative paths in the model file.
2833 :param model_id: Model ID
2934 :returns: A ``Model`` instance holding the given model
3035 """
3136 ...
3237
3338 @abc .abstractmethod
34- def to_file (self , filename : [ str , Path ] ):
39+ def to_file (self , filename : str | Path | None = None ):
3540 """Save the model to the given file
3641
3742 :param filename: Destination filename
@@ -131,11 +136,16 @@ def is_state_variable(self, id_: str) -> bool:
131136
132137
133138def model_factory (
134- filepath_or_buffer : Any , model_language : str , model_id : str = None
139+ filepath_or_buffer : Any ,
140+ model_language : str ,
141+ model_id : str = None ,
142+ base_path : str | Path = None ,
135143) -> Model :
136144 """Create a PEtab model instance from the given model
137145
138- :param filepath_or_buffer: Path/URL of the model
146+ :param filepath_or_buffer: Path/URL of the model.
147+ Absolute or relative to `base_path` if given.
148+ :param base_path: Base path for relative paths in the model file.
139149 :param model_language: PEtab model language ID for the given model
140150 :param model_id: PEtab model ID for the given model
141151 :returns: A :py:class:`Model` instance representing the given model
@@ -145,12 +155,16 @@ def model_factory(
145155 if model_language == MODEL_TYPE_SBML :
146156 from .sbml_model import SbmlModel
147157
148- return SbmlModel .from_file (filepath_or_buffer , model_id = model_id )
158+ return SbmlModel .from_file (
159+ filepath_or_buffer , model_id = model_id , base_path = base_path
160+ )
149161
150162 if model_language == MODEL_TYPE_PYSB :
151163 from .pysb_model import PySBModel
152164
153- return PySBModel .from_file (filepath_or_buffer , model_id = model_id )
165+ return PySBModel .from_file (
166+ filepath_or_buffer , model_id = model_id , base_path = base_path
167+ )
154168
155169 if model_language in known_model_types :
156170 raise NotImplementedError (
0 commit comments