Skip to content

Commit e4555bc

Browse files
committed
Format code with ruff
1 parent 6fd6135 commit e4555bc

36 files changed

+7804
-4542
lines changed

cadquery_helpers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ class StepAssembly:
2121
"""
2222
A STEP assembly.
2323
"""
24+
2425
def __init__(self, name: str):
2526
self.assembly = cq.Assembly(name=name)
2627

2728
# Less verbose output
2829
for printer in Message.DefaultMessenger_s().Printers():
2930
printer.SetTraceLevel(Message_Gravity.Message_Fail)
3031

31-
def add_body(self, body: cq.Workplane, name: str, color: cq.Color,
32-
location: Optional[cq.Location] = None) -> None:
32+
def add_body(
33+
self, body: cq.Workplane, name: str, color: cq.Color, location: Optional[cq.Location] = None
34+
) -> None:
3335
"""
3436
Add a body to the assembly.
3537

common.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Common functionality for generator scripts.
33
"""
4+
45
import collections
56
import csv
67
import re
@@ -18,7 +19,7 @@
1819
('\r', '\\r'),
1920
('\t', '\\t'),
2021
('\v', '\\v'),
21-
('"', '\\"'),
22+
('"', '\\"'),
2223
)
2324

2425

@@ -113,10 +114,7 @@ def get_pad_uuids(base_lib_path: str, pkg_uuid: str) -> Dict[str, str]:
113114
"""
114115
with open(path.join(base_lib_path, 'pkg', pkg_uuid, 'package.lp'), 'r') as f:
115116
lines = f.readlines()
116-
opt_matches = [
117-
re.match(r' \(pad ([^\s]*) \(name "([^"]*)"\)\)$', line)
118-
for line in lines
119-
]
117+
opt_matches = [re.match(r' \(pad ([^\s]*) \(name "([^"]*)"\)\)$', line) for line in lines]
120118
matches = list(filter(None, opt_matches))
121119
mapping = {}
122120
for match in matches:
@@ -132,13 +130,16 @@ def human_sort_key(key: str) -> List[Any]:
132130
Function that can be used for natural sorting, where "PB2" comes before
133131
"PB10" and after "PA3".
134132
"""
133+
135134
def _convert(text: str) -> Union[int, str]:
136135
return int(text) if text.isdigit() else text
137136

138137
return [_convert(x) for x in re.split(r'(\d+)', key) if x]
139138

140139

141-
def serialize_common(serializable: Any, output_directory: str, uuid: str, long_type: str, short_type: str) -> None:
140+
def serialize_common(
141+
serializable: Any, output_directory: str, uuid: str, long_type: str, short_type: str
142+
) -> None:
142143
"""
143144
Centralized serialize() implementation shared between Component, Symbol, Device, Package
144145
"""

dfn_configs.py

Lines changed: 188 additions & 103 deletions
Large diffs are not rendered by default.

entities/attribute.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def get_name(self) -> str:
99

1010

1111
class UnitlessUnit(AttributeUnit):
12-
NONE = "none"
12+
NONE = 'none'
1313

1414

1515
class AttributeType(EnumValue):
@@ -26,16 +26,24 @@ def get_name(self) -> str:
2626
return 'type'
2727

2828

29-
class Attribute():
30-
def __init__(self, name: str, value: Union[Value, str], attribute_type: AttributeType, unit: Optional[AttributeUnit]) -> None:
29+
class Attribute:
30+
def __init__(
31+
self,
32+
name: str,
33+
value: Union[Value, str],
34+
attribute_type: AttributeType,
35+
unit: Optional[AttributeUnit],
36+
) -> None:
3137
self.name = name
3238

3339
self.value = Value(value) if isinstance(value, str) else value
3440
self.unit = unit or UnitlessUnit.NONE
3541
self.attribute_type = attribute_type
3642

3743
def __str__(self) -> str:
38-
return '(attribute "{}" {} {} {})'.format(self.name, self.attribute_type, self.unit, self.value)
44+
return '(attribute "{}" {} {} {})'.format(
45+
self.name, self.attribute_type, self.unit, self.value
46+
)
3947

4048

4149
class CapacitanceUnit(AttributeUnit):

entities/common.py

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313

1414
class EnumValue(Enum):
1515
"""Helper class to represent enumeration like values"""
16+
1617
def get_name(self) -> str:
1718
raise NotImplementedError('Override get_name in subclass')
1819

1920
def __str__(self) -> str:
2021
return '({} {})'.format(self.get_name(), self.value)
2122

2223

23-
class DateValue():
24+
class DateValue:
2425
"""Helper class to represent a single named date value"""
26+
2527
def __init__(self, name: str, date: str):
2628
self.name = name
2729
self.date = date
@@ -30,8 +32,9 @@ def __str__(self) -> str:
3032
return '({} {})'.format(self.name, self.date)
3133

3234

33-
class UUIDValue():
35+
class UUIDValue:
3436
"""Helper class to represent a single named UUID value"""
37+
3538
def __init__(self, name: str, uuid: str):
3639
self.name = name
3740
self.uuid = uuid
@@ -40,8 +43,9 @@ def __str__(self) -> str:
4043
return '({} {})'.format(self.name, self.uuid)
4144

4245

43-
class BoolValue():
46+
class BoolValue:
4447
"""Helper class to represent a single named boolean value"""
48+
4549
def __init__(self, name: str, value: bool):
4650
self.name = name
4751
self.value = str(value).lower()
@@ -50,8 +54,9 @@ def __str__(self) -> str:
5054
return '({} {})'.format(self.name, self.value)
5155

5256

53-
class StringValue():
57+
class StringValue:
5458
"""Helper class to represent a single named string value"""
59+
5560
def __init__(self, name: str, value: str):
5661
self.name = name
5762
self.value = value
@@ -60,8 +65,9 @@ def __str__(self) -> str:
6065
return '({} "{}")'.format(self.name, escape_string(self.value))
6166

6267

63-
class FloatValue():
68+
class FloatValue:
6469
"""Helper class to represent a single named float value"""
70+
6571
def __init__(self, name: str, value: float):
6672
self.name = name
6773
self.value = value
@@ -115,7 +121,7 @@ def __init__(self, category: str):
115121
super().__init__('category', category)
116122

117123

118-
class Position():
124+
class Position:
119125
def __init__(self, x: float, y: float):
120126
self.x = x
121127
self.y = y
@@ -124,7 +130,7 @@ def __str__(self) -> str:
124130
return '(position {} {})'.format(format_float(self.x), format_float(self.y))
125131

126132

127-
class Position3D():
133+
class Position3D:
128134
def __init__(self, x: float, y: float, z: float):
129135
self.x = x
130136
self.y = y
@@ -135,15 +141,17 @@ def zero() -> 'Position3D':
135141
return Position3D(0.0, 0.0, 0.0)
136142

137143
def __str__(self) -> str:
138-
return '(3d_position {} {} {})'.format(format_float(self.x), format_float(self.y), format_float(self.z))
144+
return '(3d_position {} {} {})'.format(
145+
format_float(self.x), format_float(self.y), format_float(self.z)
146+
)
139147

140148

141149
class Rotation(FloatValue):
142150
def __init__(self, rotation: float):
143151
super().__init__('rotation', rotation)
144152

145153

146-
class Rotation3D():
154+
class Rotation3D:
147155
def __init__(self, x: float, y: float, z: float):
148156
self.x = x
149157
self.y = y
@@ -154,7 +162,9 @@ def zero() -> 'Rotation3D':
154162
return Rotation3D(0.0, 0.0, 0.0)
155163

156164
def __str__(self) -> str:
157-
return '(3d_rotation {} {} {})'.format(format_float(self.x), format_float(self.y), format_float(self.z))
165+
return '(3d_rotation {} {} {})'.format(
166+
format_float(self.x), format_float(self.y), format_float(self.z)
167+
)
158168

159169

160170
class Length(FloatValue):
@@ -187,7 +197,7 @@ def __init__(self, grab_area: bool):
187197
super().__init__('grab_area', grab_area)
188198

189199

190-
class Vertex():
200+
class Vertex:
191201
def __init__(self, position: Position, angle: Angle):
192202
self.position = position
193203
self.angle = angle
@@ -196,17 +206,24 @@ def __str__(self) -> str:
196206
return '(vertex {} {})'.format(self.position, self.angle)
197207

198208

199-
class Layer():
209+
class Layer:
200210
def __init__(self, layer: str):
201211
self.layer = layer
202212

203213
def __str__(self) -> str:
204214
return '(layer {})'.format(self.layer)
205215

206216

207-
class Polygon():
208-
def __init__(self, uuid: str, layer: Layer, width: Width, fill: Fill,
209-
grab_area: GrabArea, vertices: Optional[List[Vertex]] = None):
217+
class Polygon:
218+
def __init__(
219+
self,
220+
uuid: str,
221+
layer: Layer,
222+
width: Width,
223+
fill: Fill,
224+
grab_area: GrabArea,
225+
vertices: Optional[List[Vertex]] = None,
226+
):
210227
self.uuid = uuid
211228
self.layer = layer
212229
self.width = width
@@ -218,8 +235,9 @@ def add_vertex(self, vertex: Vertex) -> None:
218235
self.vertices.append(vertex)
219236

220237
def __str__(self) -> str:
221-
ret = '(polygon {} {}\n'.format(self.uuid, self.layer) +\
222-
' {} {} {}\n'.format(self.width, self.fill, self.grab_area)
238+
ret = '(polygon {} {}\n'.format(self.uuid, self.layer) + ' {} {} {}\n'.format(
239+
self.width, self.fill, self.grab_area
240+
)
223241
ret += indent_entities(self.vertices)
224242
ret += ')'
225243
return ret
@@ -270,9 +288,17 @@ def __init__(self, diameter: float):
270288
super().__init__('diameter', diameter)
271289

272290

273-
class Circle():
274-
def __init__(self, uuid: str, layer: Layer, width: Width, fill: Fill,
275-
grab_area: GrabArea, diameter: Diameter, position: Position):
291+
class Circle:
292+
def __init__(
293+
self,
294+
uuid: str,
295+
layer: Layer,
296+
width: Width,
297+
fill: Fill,
298+
grab_area: GrabArea,
299+
diameter: Diameter,
300+
position: Position,
301+
):
276302
self.uuid = uuid
277303
self.layer = layer
278304
self.width = width
@@ -283,8 +309,9 @@ def __init__(self, uuid: str, layer: Layer, width: Width, fill: Fill,
283309

284310
def __str__(self) -> str:
285311
ret = '(circle {} {}\n'.format(self.uuid, self.layer)
286-
ret += ' {} {} {} {} {}\n'.format(self.width, self.fill, self.grab_area,
287-
self.diameter, self.position)
312+
ret += ' {} {} {} {} {}\n'.format(
313+
self.width, self.fill, self.grab_area, self.diameter, self.position
314+
)
288315
ret += ')'
289316
return ret
290317

@@ -294,16 +321,25 @@ def __init__(self, value: str):
294321
super().__init__('value', value)
295322

296323

297-
class Align():
324+
class Align:
298325
def __init__(self, align: str):
299326
self.align = align
300327

301328
def __str__(self) -> str:
302329
return '(align {})'.format(self.align)
303330

304331

305-
class Text():
306-
def __init__(self, uuid: str, layer: Layer, value: Value, align: Align, height: Height, position: Position, rotation: Rotation):
332+
class Text:
333+
def __init__(
334+
self,
335+
uuid: str,
336+
layer: Layer,
337+
value: Value,
338+
align: Align,
339+
height: Height,
340+
position: Position,
341+
rotation: Rotation,
342+
):
307343
self.uuid = uuid
308344
self.layer = layer
309345
self.value = value
@@ -313,18 +349,24 @@ def __init__(self, uuid: str, layer: Layer, value: Value, align: Align, height:
313349
self.rotation = rotation
314350

315351
def __str__(self) -> str:
316-
return '(text {} {} {}\n'.format(self.uuid, self.layer, self.value) +\
317-
' {} {} {} {}\n'.format(self.align, self.height, self.position, self.rotation) +\
318-
')'
352+
return (
353+
'(text {} {} {}\n'.format(self.uuid, self.layer, self.value)
354+
+ ' {} {} {} {}\n'.format(self.align, self.height, self.position, self.rotation)
355+
+ ')'
356+
)
319357

320358

321-
class Resource():
359+
class Resource:
322360
def __init__(self, name: str, mediatype: str, url: str):
323361
self.name = name
324362
self.mediatype = mediatype
325363
self.url = url
326364

327365
def __str__(self) -> str:
328-
return '(resource "{}" (mediatype "{}")\n'.format(escape_string(self.name), escape_string(self.mediatype)) +\
329-
' (url "{}")\n'.format(escape_string(self.url)) +\
330-
')'
366+
return (
367+
'(resource "{}" (mediatype "{}")\n'.format(
368+
escape_string(self.name), escape_string(self.mediatype)
369+
)
370+
+ ' (url "{}")\n'.format(escape_string(self.url))
371+
+ ')'
372+
)

0 commit comments

Comments
 (0)