Load and validate a Dia configuration from a JSON file. Args: path: The path to the configuration file. Returns: A validated DiaConfig instance if the file exists and is valid, otherwise None if the file is not found. Raises:
(cls, path: str)
| 155 | |
| 156 | @classmethod |
| 157 | def load(cls, path: str) -> "DiaConfig | None": |
| 158 | """Load and validate a Dia configuration from a JSON file. |
| 159 | |
| 160 | Args: |
| 161 | path: The path to the configuration file. |
| 162 | |
| 163 | Returns: |
| 164 | A validated DiaConfig instance if the file exists and is valid, |
| 165 | otherwise None if the file is not found. |
| 166 | |
| 167 | Raises: |
| 168 | ValueError: If the path does not point to an existing .json file. |
| 169 | pydantic.ValidationError: If the JSON content fails validation against the DiaConfig schema. |
| 170 | """ |
| 171 | try: |
| 172 | with open(path, "r") as f: |
| 173 | content = f.read() |
| 174 | return cls.model_validate_json(content) |
| 175 | except FileNotFoundError: |
| 176 | return None |
no outgoing calls
no test coverage detected