Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ruff for formatting #133

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cadquery_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class StepAssembly:
"""
A STEP assembly.
"""

def __init__(self, name: str):
self.assembly = cq.Assembly(name=name)

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

def add_body(self, body: cq.Workplane, name: str, color: cq.Color,
location: Optional[cq.Location] = None) -> None:
def add_body(self, body: cq.Workplane, name: str, color: cq.Color, location: Optional[cq.Location] = None) -> None:
"""
Add a body to the assembly.

Expand Down
9 changes: 4 additions & 5 deletions common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Common functionality for generator scripts.
"""

import collections
import csv
import os.path
Expand All @@ -18,7 +19,7 @@
('\r', '\\r'),
('\t', '\\t'),
('\v', '\\v'),
('"', '\\"'),
('"', '\\"'),
)


Expand Down Expand Up @@ -150,10 +151,7 @@ def get_pad_uuids(base_lib_path: str, pkg_uuid: str) -> Dict[str, str]:
"""
with open(os.path.join(base_lib_path, 'pkg', pkg_uuid, 'package.lp'), 'r') as f:
lines = f.readlines()
opt_matches = [
re.match(r' \(pad ([^\s]*) \(name "([^"]*)"\)\)$', line)
for line in lines
]
opt_matches = [re.match(r' \(pad ([^\s]*) \(name "([^"]*)"\)\)$', line) for line in lines]
matches = list(filter(None, opt_matches))
mapping = {}
for match in matches:
Expand All @@ -169,6 +167,7 @@ def human_sort_key(key: str) -> List[Any]:
Function that can be used for natural sorting, where "PB2" comes before
"PB10" and after "PA3".
"""

def _convert(text: str) -> Union[int, str]:
return int(text) if text.isdigit() else text

Expand Down
156 changes: 83 additions & 73 deletions dfn_configs.py

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions entities/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def get_name(self) -> str:


class UnitlessUnit(AttributeUnit):
NONE = "none"
NONE = 'none'


class AttributeType(EnumValue):
Expand All @@ -26,8 +26,10 @@ def get_name(self) -> str:
return 'type'


class Attribute():
def __init__(self, name: str, value: Union[Value, str], attribute_type: AttributeType, unit: Optional[AttributeUnit]) -> None:
class Attribute:
def __init__(
self, name: str, value: Union[Value, str], attribute_type: AttributeType, unit: Optional[AttributeUnit]
) -> None:
self.name = name

self.value = Value(value) if isinstance(value, str) else value
Expand Down
84 changes: 58 additions & 26 deletions entities/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@

class EnumValue(Enum):
"""Helper class to represent enumeration like values"""

def get_name(self) -> str:
raise NotImplementedError('Override get_name in subclass')

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


class DateValue():
class DateValue:
"""Helper class to represent a single named date value"""

def __init__(self, name: str, date: str):
self.name = name
self.date = date
Expand All @@ -30,8 +32,9 @@ def __str__(self) -> str:
return '({} {})'.format(self.name, self.date)


class UUIDValue():
class UUIDValue:
"""Helper class to represent a single named UUID value"""

def __init__(self, name: str, uuid: str):
self.name = name
self.uuid = uuid
Expand All @@ -40,8 +43,9 @@ def __str__(self) -> str:
return '({} {})'.format(self.name, self.uuid)


class BoolValue():
class BoolValue:
"""Helper class to represent a single named boolean value"""

def __init__(self, name: str, value: bool):
self.name = name
self.value = str(value).lower()
Expand All @@ -50,8 +54,9 @@ def __str__(self) -> str:
return '({} {})'.format(self.name, self.value)


class StringValue():
class StringValue:
"""Helper class to represent a single named string value"""

def __init__(self, name: str, value: str):
self.name = name
self.value = value
Expand All @@ -60,8 +65,9 @@ def __str__(self) -> str:
return '({} "{}")'.format(self.name, escape_string(self.value))


class FloatValue():
class FloatValue:
"""Helper class to represent a single named float value"""

def __init__(self, name: str, value: float):
self.name = name
self.value = value
Expand Down Expand Up @@ -115,7 +121,7 @@ def __init__(self, category: str):
super().__init__('category', category)


class Position():
class Position:
def __init__(self, x: float, y: float):
self.x = x
self.y = y
Expand All @@ -124,7 +130,7 @@ def __str__(self) -> str:
return '(position {} {})'.format(format_float(self.x), format_float(self.y))


class Position3D():
class Position3D:
def __init__(self, x: float, y: float, z: float):
self.x = x
self.y = y
Expand All @@ -143,7 +149,7 @@ def __init__(self, rotation: float):
super().__init__('rotation', rotation)


class Rotation3D():
class Rotation3D:
def __init__(self, x: float, y: float, z: float):
self.x = x
self.y = y
Expand Down Expand Up @@ -187,7 +193,7 @@ def __init__(self, grab_area: bool):
super().__init__('grab_area', grab_area)


class Vertex():
class Vertex:
def __init__(self, position: Position, angle: Angle):
self.position = position
self.angle = angle
Expand All @@ -196,17 +202,24 @@ def __str__(self) -> str:
return '(vertex {} {})'.format(self.position, self.angle)


class Layer():
class Layer:
def __init__(self, layer: str):
self.layer = layer

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


class Polygon():
def __init__(self, uuid: str, layer: Layer, width: Width, fill: Fill,
grab_area: GrabArea, vertices: Optional[List[Vertex]] = None):
class Polygon:
def __init__(
self,
uuid: str,
layer: Layer,
width: Width,
fill: Fill,
grab_area: GrabArea,
vertices: Optional[List[Vertex]] = None,
):
self.uuid = uuid
self.layer = layer
self.width = width
Expand All @@ -218,8 +231,9 @@ def add_vertex(self, vertex: Vertex) -> None:
self.vertices.append(vertex)

def __str__(self) -> str:
ret = '(polygon {} {}\n'.format(self.uuid, self.layer) +\
' {} {} {}\n'.format(self.width, self.fill, self.grab_area)
ret = '(polygon {} {}\n'.format(self.uuid, self.layer) + ' {} {} {}\n'.format(
self.width, self.fill, self.grab_area
)
ret += indent_entities(self.vertices)
ret += ')'
return ret
Expand Down Expand Up @@ -270,9 +284,17 @@ def __init__(self, diameter: float):
super().__init__('diameter', diameter)


class Circle():
def __init__(self, uuid: str, layer: Layer, width: Width, fill: Fill,
grab_area: GrabArea, diameter: Diameter, position: Position):
class Circle:
def __init__(
self,
uuid: str,
layer: Layer,
width: Width,
fill: Fill,
grab_area: GrabArea,
diameter: Diameter,
position: Position,
):
self.uuid = uuid
self.layer = layer
self.width = width
Expand All @@ -283,8 +305,7 @@ def __init__(self, uuid: str, layer: Layer, width: Width, fill: Fill,

def __str__(self) -> str:
ret = '(circle {} {}\n'.format(self.uuid, self.layer)
ret += ' {} {} {} {} {}\n'.format(self.width, self.fill, self.grab_area,
self.diameter, self.position)
ret += ' {} {} {} {} {}\n'.format(self.width, self.fill, self.grab_area, self.diameter, self.position)
ret += ')'
return ret

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


class Align():
class Align:
def __init__(self, align: str):
self.align = align

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


class Text():
def __init__(self, uuid: str, layer: Layer, value: Value, align: Align, height: Height, position: Position, rotation: Rotation):
class Text:
def __init__(
self,
uuid: str,
layer: Layer,
value: Value,
align: Align,
height: Height,
position: Position,
rotation: Rotation,
):
self.uuid = uuid
self.layer = layer
self.value = value
Expand All @@ -313,6 +343,8 @@ def __init__(self, uuid: str, layer: Layer, value: Value, align: Align, height:
self.rotation = rotation

def __str__(self) -> str:
return '(text {} {} {}\n'.format(self.uuid, self.layer, self.value) +\
' {} {} {} {}\n'.format(self.align, self.height, self.position, self.rotation) +\
')'
return (
'(text {} {} {}\n'.format(self.uuid, self.layer, self.value)
+ ' {} {} {} {}\n'.format(self.align, self.height, self.position, self.rotation)
+ ')'
)
Loading
Loading