|
7 | 7 | from pydantic import ConfigDict, field_validator, model_validator
|
8 | 8 |
|
9 | 9 | IDENTIFIER_REGEX = r"^[a-z_][a-z_0-9]*$"
|
10 |
| -__version__ = "0.1.0" |
| 10 | +__version__ = "0.1.1" |
| 11 | +_SUPPORTED_CONFIG_VERSIONS = {"0.1.0", "0.1.1"} |
| 12 | + |
11 | 13 |
|
12 | 14 | from pathlib import Path
|
13 | 15 | from typing import Optional, Union
|
@@ -140,7 +142,7 @@ class Config(BaseModel):
|
140 | 142 | """
|
141 | 143 |
|
142 | 144 | config_version: str = Field(
|
143 |
| - "0.1.0", |
| 145 | + __version__, |
144 | 146 | description="The version of the `optimade.yaml` config specification.",
|
145 | 147 | )
|
146 | 148 |
|
@@ -173,9 +175,22 @@ def from_string(data: str):
|
173 | 175 |
|
174 | 176 | @model_validator(mode="before")
|
175 | 177 | @classmethod
|
176 |
| - def validate_config_version(cls, values): |
177 |
| - if values.get("config_version") is None: |
178 |
| - raise UnsupportedConfigVersion(f"Config version must be {__version__}.") |
| 178 | + def validate_config_version(cls, values: dict): |
| 179 | + v = values.get("config_version") |
| 180 | + |
| 181 | + # If missing, keep current behavior: require explicit version |
| 182 | + if v is None: |
| 183 | + raise UnsupportedConfigVersion( |
| 184 | + f"Missing config_version. Supported versions are: {sorted(_SUPPORTED_CONFIG_VERSIONS)}. " |
| 185 | + f"The current version is {__version__}." |
| 186 | + ) |
| 187 | + |
| 188 | + if v not in _SUPPORTED_CONFIG_VERSIONS: |
| 189 | + raise UnsupportedConfigVersion( |
| 190 | + f"Unsupported config_version {v!r}. " |
| 191 | + f"Supported versions are: {sorted(_SUPPORTED_CONFIG_VERSIONS)}." |
| 192 | + ) |
| 193 | + |
179 | 194 | return values
|
180 | 195 |
|
181 | 196 | model_config = ConfigDict(extra="forbid")
|
0 commit comments