1616import numpy as np
1717import pandas as pd
1818import sympy as sp
19- from pydantic import AnyUrl , BaseModel , Field , field_validator
19+ from pydantic import (
20+ AnyUrl ,
21+ BaseModel ,
22+ ConfigDict ,
23+ Field ,
24+ field_validator ,
25+ )
2026
2127from ..v1 import (
2228 parameter_mapping ,
@@ -1124,9 +1130,13 @@ def model_dump(self, **kwargs) -> dict[str, Any]:
11241130class ModelFile (BaseModel ):
11251131 """A file in the PEtab problem configuration."""
11261132
1127- location : str | AnyUrl
1133+ location : AnyUrl | Path
11281134 language : str
11291135
1136+ model_config = ConfigDict (
1137+ validate_assignment = True ,
1138+ )
1139+
11301140
11311141class ExtensionConfig (BaseModel ):
11321142 """The configuration of a PEtab extension."""
@@ -1139,13 +1149,13 @@ class ProblemConfig(BaseModel):
11391149 """The PEtab problem configuration."""
11401150
11411151 #: The path to the PEtab problem configuration.
1142- filepath : str | AnyUrl | None = Field (
1152+ filepath : AnyUrl | Path | None = Field (
11431153 None ,
11441154 description = "The path to the PEtab problem configuration." ,
11451155 exclude = True ,
11461156 )
11471157 #: The base path to resolve relative paths.
1148- base_path : str | AnyUrl | None = Field (
1158+ base_path : AnyUrl | Path | None = Field (
11491159 None ,
11501160 description = "The base path to resolve relative paths." ,
11511161 exclude = True ,
@@ -1156,17 +1166,16 @@ class ProblemConfig(BaseModel):
11561166 # TODO https://github.com/PEtab-dev/PEtab/pull/641:
11571167 # rename to parameter_files in yaml for consistency with other files?
11581168 # always a list?
1159- parameter_files : list [str | AnyUrl ] = Field (
1169+ parameter_files : list [AnyUrl | Path ] = Field (
11601170 default = [], alias = PARAMETER_FILES
11611171 )
11621172
1163- # TODO: consider changing str to Path
11641173 model_files : dict [str , ModelFile ] | None = {}
1165- measurement_files : list [str | AnyUrl ] = []
1166- condition_files : list [str | AnyUrl ] = []
1167- experiment_files : list [str | AnyUrl ] = []
1168- observable_files : list [str | AnyUrl ] = []
1169- mapping_files : list [str | AnyUrl ] = []
1174+ measurement_files : list [AnyUrl | Path ] = []
1175+ condition_files : list [AnyUrl | Path ] = []
1176+ experiment_files : list [AnyUrl | Path ] = []
1177+ observable_files : list [AnyUrl | Path ] = []
1178+ mapping_files : list [AnyUrl | Path ] = []
11701179
11711180 #: Extensions used by the problem.
11721181 extensions : list [ExtensionConfig ] | dict = {}
@@ -1194,7 +1203,24 @@ def to_yaml(self, filename: str | Path):
11941203 """
11951204 from ..v1 .yaml import write_yaml
11961205
1197- write_yaml (self .model_dump (by_alias = True ), filename )
1206+ data = self .model_dump (by_alias = True )
1207+ # convert Paths to strings for YAML serialization
1208+ for key in (
1209+ "measurement_files" ,
1210+ "condition_files" ,
1211+ "experiment_files" ,
1212+ "observable_files" ,
1213+ "mapping_files" ,
1214+ "parameter_files" ,
1215+ ):
1216+ data [key ] = list (map (str , data [key ]))
1217+
1218+ for model_id in data .get ("model_files" , {}):
1219+ data ["model_files" ][model_id ][MODEL_LOCATION ] = str (
1220+ data ["model_files" ][model_id ]["location" ]
1221+ )
1222+
1223+ write_yaml (data , filename )
11981224
11991225 @property
12001226 def format_version_tuple (self ) -> tuple [int , int , int , str ]:
0 commit comments