Skip to content

Commit c408dbe

Browse files
committed
fix config jsonify
1 parent 7cabff6 commit c408dbe

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

openglider/glider/parametric/config.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re
2-
from typing import Any, ClassVar, Self
2+
from typing import Any, ClassVar, Self, Annotated
33

44
from packaging.version import Version
55
import euklid
@@ -100,6 +100,14 @@ class SewingAllowanceConfig(ConfigTable):
100100
entry: Length = Length("10mm")
101101
folded: Length = Length("10mm")
102102

103+
def validate_version(version: Version | str) -> Version:
104+
if isinstance(version, str):
105+
return Version(version)
106+
107+
return version
108+
109+
VersionType = Annotated[Version, pydantic.BeforeValidator(validate_version)]
110+
103111
class ParametricGliderConfig(ConfigTable):
104112
table_name = "Data"
105113

@@ -125,14 +133,19 @@ class ParametricGliderConfig(ConfigTable):
125133
use_sag: bool = True
126134
baseline_pct: Percentage = Percentage(0.)
127135

128-
version: Version = Version(__version__)
136+
version: VersionType = Version(__version__)
129137

130138
@classmethod
131139
def __from_json__(cls, **data: Any) -> Self:
132140
for name in "pilot_position", "brake_offset":
133141
data[name] = euklid.vector.Vector3D(data[name])
134142

135143
return cls(**data)
144+
145+
def __json__(self) -> dict[str, Any]:
146+
data = super().__json__()
147+
data["version"] = str(self.version)
148+
return data
136149

137150
def get_lower_attachment_points(self) -> dict[str, Node]:
138151
points = {

0 commit comments

Comments
 (0)