Skip to content

Commit 7fe5e73

Browse files
committed
Format code with ruff
1 parent 33538aa commit 7fe5e73

32 files changed

+4757
-3052
lines changed

cadquery_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ 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(self, body: cq.Workplane, name: str, color: cq.Color, location: Optional[cq.Location] = None) -> None:
3333
"""
3434
Add a body to the assembly.
3535

common.py

Lines changed: 4 additions & 5 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 os.path
@@ -18,7 +19,7 @@
1819
('\r', '\\r'),
1920
('\t', '\\t'),
2021
('\v', '\\v'),
21-
('"', '\\"'),
22+
('"', '\\"'),
2223
)
2324

2425

@@ -150,10 +151,7 @@ def get_pad_uuids(base_lib_path: str, pkg_uuid: str) -> Dict[str, str]:
150151
"""
151152
with open(os.path.join(base_lib_path, 'pkg', pkg_uuid, 'package.lp'), 'r') as f:
152153
lines = f.readlines()
153-
opt_matches = [
154-
re.match(r' \(pad ([^\s]*) \(name "([^"]*)"\)\)$', line)
155-
for line in lines
156-
]
154+
opt_matches = [re.match(r' \(pad ([^\s]*) \(name "([^"]*)"\)\)$', line) for line in lines]
157155
matches = list(filter(None, opt_matches))
158156
mapping = {}
159157
for match in matches:
@@ -169,6 +167,7 @@ def human_sort_key(key: str) -> List[Any]:
169167
Function that can be used for natural sorting, where "PB2" comes before
170168
"PB10" and after "PA3".
171169
"""
170+
172171
def _convert(text: str) -> Union[int, str]:
173172
return int(text) if text.isdigit() else text
174173

dfn_configs.py

Lines changed: 83 additions & 73 deletions
Large diffs are not rendered by default.

entities/attribute.py

Lines changed: 5 additions & 3 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,8 +26,10 @@ 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, name: str, value: Union[Value, str], attribute_type: AttributeType, unit: Optional[AttributeUnit]
32+
) -> None:
3133
self.name = name
3234

3335
self.value = Value(value) if isinstance(value, str) else value

entities/common.py

Lines changed: 58 additions & 26 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
@@ -143,7 +149,7 @@ def __init__(self, rotation: float):
143149
super().__init__('rotation', rotation)
144150

145151

146-
class Rotation3D():
152+
class Rotation3D:
147153
def __init__(self, x: float, y: float, z: float):
148154
self.x = x
149155
self.y = y
@@ -187,7 +193,7 @@ def __init__(self, grab_area: bool):
187193
super().__init__('grab_area', grab_area)
188194

189195

190-
class Vertex():
196+
class Vertex:
191197
def __init__(self, position: Position, angle: Angle):
192198
self.position = position
193199
self.angle = angle
@@ -196,17 +202,24 @@ def __str__(self) -> str:
196202
return '(vertex {} {})'.format(self.position, self.angle)
197203

198204

199-
class Layer():
205+
class Layer:
200206
def __init__(self, layer: str):
201207
self.layer = layer
202208

203209
def __str__(self) -> str:
204210
return '(layer {})'.format(self.layer)
205211

206212

207-
class Polygon():
208-
def __init__(self, uuid: str, layer: Layer, width: Width, fill: Fill,
209-
grab_area: GrabArea, vertices: Optional[List[Vertex]] = None):
213+
class Polygon:
214+
def __init__(
215+
self,
216+
uuid: str,
217+
layer: Layer,
218+
width: Width,
219+
fill: Fill,
220+
grab_area: GrabArea,
221+
vertices: Optional[List[Vertex]] = None,
222+
):
210223
self.uuid = uuid
211224
self.layer = layer
212225
self.width = width
@@ -218,8 +231,9 @@ def add_vertex(self, vertex: Vertex) -> None:
218231
self.vertices.append(vertex)
219232

220233
def __str__(self) -> str:
221-
ret = '(polygon {} {}\n'.format(self.uuid, self.layer) +\
222-
' {} {} {}\n'.format(self.width, self.fill, self.grab_area)
234+
ret = '(polygon {} {}\n'.format(self.uuid, self.layer) + ' {} {} {}\n'.format(
235+
self.width, self.fill, self.grab_area
236+
)
223237
ret += indent_entities(self.vertices)
224238
ret += ')'
225239
return ret
@@ -270,9 +284,17 @@ def __init__(self, diameter: float):
270284
super().__init__('diameter', diameter)
271285

272286

273-
class Circle():
274-
def __init__(self, uuid: str, layer: Layer, width: Width, fill: Fill,
275-
grab_area: GrabArea, diameter: Diameter, position: Position):
287+
class Circle:
288+
def __init__(
289+
self,
290+
uuid: str,
291+
layer: Layer,
292+
width: Width,
293+
fill: Fill,
294+
grab_area: GrabArea,
295+
diameter: Diameter,
296+
position: Position,
297+
):
276298
self.uuid = uuid
277299
self.layer = layer
278300
self.width = width
@@ -283,8 +305,7 @@ def __init__(self, uuid: str, layer: Layer, width: Width, fill: Fill,
283305

284306
def __str__(self) -> str:
285307
ret = '(circle {} {}\n'.format(self.uuid, self.layer)
286-
ret += ' {} {} {} {} {}\n'.format(self.width, self.fill, self.grab_area,
287-
self.diameter, self.position)
308+
ret += ' {} {} {} {} {}\n'.format(self.width, self.fill, self.grab_area, self.diameter, self.position)
288309
ret += ')'
289310
return ret
290311

@@ -294,16 +315,25 @@ def __init__(self, value: str):
294315
super().__init__('value', value)
295316

296317

297-
class Align():
318+
class Align:
298319
def __init__(self, align: str):
299320
self.align = align
300321

301322
def __str__(self) -> str:
302323
return '(align {})'.format(self.align)
303324

304325

305-
class Text():
306-
def __init__(self, uuid: str, layer: Layer, value: Value, align: Align, height: Height, position: Position, rotation: Rotation):
326+
class Text:
327+
def __init__(
328+
self,
329+
uuid: str,
330+
layer: Layer,
331+
value: Value,
332+
align: Align,
333+
height: Height,
334+
position: Position,
335+
rotation: Rotation,
336+
):
307337
self.uuid = uuid
308338
self.layer = layer
309339
self.value = value
@@ -313,6 +343,8 @@ def __init__(self, uuid: str, layer: Layer, value: Value, align: Align, height:
313343
self.rotation = rotation
314344

315345
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-
')'
346+
return (
347+
'(text {} {} {}\n'.format(self.uuid, self.layer, self.value)
348+
+ ' {} {} {} {}\n'.format(self.align, self.height, self.position, self.rotation)
349+
+ ')'
350+
)

0 commit comments

Comments
 (0)