Skip to content

Commit e30500d

Browse files
committed
Include pydantic model for black formatting
1 parent 155188e commit e30500d

2 files changed

Lines changed: 53 additions & 46 deletions

File tree

harp/model.py

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,42 @@
88
from typing import Any, Dict, List, Optional, Union
99
from typing_extensions import Annotated
1010

11-
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field, RootModel, conint, field_serializer
11+
from pydantic import (
12+
BaseModel,
13+
BeforeValidator,
14+
ConfigDict,
15+
Field,
16+
RootModel,
17+
conint,
18+
field_serializer,
19+
)
1220

1321

1422
class PayloadType(str, Enum):
15-
U8 = 'uint8'
16-
S8 = 'int8'
17-
U16 = 'uint16'
18-
S16 = 'int16'
19-
U32 = 'uint32'
20-
S32 = 'int32'
21-
U64 = 'uint64'
22-
S64 = 'int64'
23-
Float = 'float32'
23+
U8 = "uint8"
24+
S8 = "int8"
25+
U16 = "uint16"
26+
S16 = "int16"
27+
U32 = "uint32"
28+
S32 = "int32"
29+
U64 = "uint64"
30+
S64 = "int64"
31+
Float = "float32"
2432

2533

2634
class Access(Enum):
27-
Read = 'Read'
28-
Write = 'Write'
29-
Event = 'Event'
35+
Read = "Read"
36+
Write = "Write"
37+
Event = "Event"
3038

3139

3240
class MaskValueItem(BaseModel):
3341
model_config = ConfigDict(
34-
extra='forbid',
42+
extra="forbid",
3543
)
36-
value: int = Field(..., description='Specifies the numerical mask value.')
44+
value: int = Field(..., description="Specifies the numerical mask value.")
3745
description: Optional[str] = Field(
38-
None, description='Specifies a summary description of the mask value function.'
46+
None, description="Specifies a summary description of the mask value function."
3947
)
4048

4149
def __int__(self):
@@ -48,70 +56,70 @@ class MaskValue(RootModel[Union[int, MaskValueItem]]):
4856

4957
class BitMask(BaseModel):
5058
description: Optional[str] = Field(
51-
None, description='Specifies a summary description of the bit mask function.'
59+
None, description="Specifies a summary description of the bit mask function."
5260
)
5361
bits: Dict[str, MaskValue]
5462

5563

5664
class GroupMask(BaseModel):
5765
description: Optional[str] = Field(
58-
None, description='Specifies a summary description of the group mask function.'
66+
None, description="Specifies a summary description of the group mask function."
5967
)
6068
values: Dict[str, MaskValue]
6169

6270

6371
class MaskType(RootModel[str]):
6472
root: str = Field(
6573
...,
66-
description='Specifies the name of the bit mask or group mask used to represent the payload value.',
74+
description="Specifies the name of the bit mask or group mask used to represent the payload value.",
6775
)
6876

6977

7078
class InterfaceType(RootModel[str]):
7179
root: str = Field(
7280
...,
73-
description='Specifies the name of the type used to represent the payload value in the high-level interface.',
81+
description="Specifies the name of the type used to represent the payload value in the high-level interface.",
7482
)
7583

7684

7785
class Converter(Enum):
78-
None_ = 'None'
79-
Payload = 'Payload'
80-
RawPayload = 'RawPayload'
86+
None_ = "None"
87+
Payload = "Payload"
88+
RawPayload = "RawPayload"
8189

8290

8391
class MinValue(RootModel[float]):
8492
root: float = Field(
8593
...,
86-
description='Specifies the minimum allowable value for the payload or payload member.',
94+
description="Specifies the minimum allowable value for the payload or payload member.",
8795
)
8896

8997

9098
class MaxValue(RootModel[float]):
9199
root: float = Field(
92100
...,
93-
description='Specifies the maximum allowable value for the payload or payload member.',
101+
description="Specifies the maximum allowable value for the payload or payload member.",
94102
)
95103

96104

97105
class DefaultValue(RootModel[float]):
98106
root: float = Field(
99107
...,
100-
description='Specifies the default value for the payload or payload member.',
108+
description="Specifies the default value for the payload or payload member.",
101109
)
102110

103111

104112
class PayloadMember(BaseModel):
105113
mask: Optional[int] = Field(
106114
None,
107-
description='Specifies the mask used to read and write this payload member.',
115+
description="Specifies the mask used to read and write this payload member.",
108116
)
109117
offset: Optional[int] = Field(
110118
None,
111-
description='Specifies the payload array offset where this payload member is stored.',
119+
description="Specifies the payload array offset where this payload member is stored.",
112120
)
113121
description: Optional[str] = Field(
114-
None, description='Specifies a summary description of the payload member.'
122+
None, description="Specifies a summary description of the payload member."
115123
)
116124
minValue: Optional[MinValue] = None
117125
maxValue: Optional[MaxValue] = None
@@ -122,68 +130,68 @@ class PayloadMember(BaseModel):
122130

123131

124132
class Visibility(Enum):
125-
public = 'public'
126-
private = 'private'
133+
public = "public"
134+
private = "private"
127135

128136

129137
class Register(BaseModel):
130138
address: conint(le=255) = Field(
131-
..., description='Specifies the unique 8-bit address of the register.'
139+
..., description="Specifies the unique 8-bit address of the register."
132140
)
133141
type: Annotated[PayloadType, BeforeValidator(lambda v: PayloadType[v])]
134142
length: Optional[conint(ge=1)] = Field(
135-
default=1, description='Specifies the length of the register payload.'
143+
default=1, description="Specifies the length of the register payload."
136144
)
137145
access: Union[Access, List[Access]] = Field(
138-
..., description='Specifies the expected use of the register.'
146+
..., description="Specifies the expected use of the register."
139147
)
140148
description: Optional[str] = Field(
141-
None, description='Specifies a summary description of the register function.'
149+
None, description="Specifies a summary description of the register function."
142150
)
143151
minValue: Optional[MinValue] = None
144152
maxValue: Optional[MaxValue] = None
145153
defaultValue: Optional[DefaultValue] = None
146154
maskType: Optional[MaskType] = None
147155
visibility: Optional[Visibility] = Field(
148156
None,
149-
description='Specifies whether the register function is exposed in the high-level interface.',
157+
description="Specifies whether the register function is exposed in the high-level interface.",
150158
)
151159
volatile: Optional[bool] = Field(
152160
None,
153-
description='Specifies whether register values can be saved in non-volatile memory.',
161+
description="Specifies whether register values can be saved in non-volatile memory.",
154162
)
155163
payloadSpec: Optional[Dict[str, PayloadMember]] = None
156164
interfaceType: Optional[InterfaceType] = None
157165
converter: Optional[Converter] = None
158166

159-
@field_serializer('type')
167+
@field_serializer("type")
160168
def _serialize_type(self, type: PayloadType):
161169
return type.name
162170

163171

164172
class Registers(BaseModel):
165173
registers: Dict[str, Register] = Field(
166174
...,
167-
description='Specifies the collection of registers implementing the device function.',
175+
description="Specifies the collection of registers implementing the device function.",
168176
)
169177
bitMasks: Optional[Dict[str, BitMask]] = Field(
170178
None,
171-
description='Specifies the collection of masks available to be used with the different registers.',
179+
description="Specifies the collection of masks available to be used with the different registers.",
172180
)
173181
groupMasks: Optional[Dict[str, GroupMask]] = Field(
174182
None,
175-
description='Specifies the collection of group masks available to be used with the different registers.',
183+
description="Specifies the collection of group masks available to be used with the different registers.",
176184
)
177185

178186

179187
class Model(Registers):
180-
device: str = Field(..., description='Specifies the name of the device.')
188+
device: str = Field(..., description="Specifies the name of the device.")
181189
whoAmI: int = Field(
182-
..., description='Specifies the unique identifier for this device type.'
190+
..., description="Specifies the unique identifier for this device type."
183191
)
184192
firmwareVersion: str = Field(
185-
..., description='Specifies the semantic version of the device firmware.'
193+
..., description="Specifies the semantic version of the device firmware."
186194
)
187195
hardwareTargets: str = Field(
188-
..., description='Specifies the semantic version of the device hardware.'
196+
..., description="Specifies the semantic version of the device hardware."
189197
)

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ extend-exclude = '''
6565
(
6666
^/LICENSE
6767
^/README.md
68-
| harp/model.py
6968
| reflex-generator
7069
)
7170
'''

0 commit comments

Comments
 (0)