Skip to content

Commit

Permalink
Merge pull request #94 from Wakoma/keyword-only-args
Browse files Browse the repository at this point in the history
Move to keyword only arguments to improve readability
  • Loading branch information
julianstirling authored Oct 24, 2024
2 parents d7f1d8b + 92a0e89 commit fa0d083
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 28 deletions.
33 changes: 29 additions & 4 deletions nimble_build_system/cad/fasteners.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ class Fastener:
_fastener_type = "iso7380_1"
_direction_axis = "-Z"

def __init__(self, name, position, explode_translation, size, fastener_type, direction_axis):
def __init__(
self,
name:str,
*,
position:tuple[float, float, float]=(0.0, 0.0, 0.0),
explode_translation:tuple[float, float, float]=(0.0, 0.0, 0.0),
size:str="M3-0.5",
fastener_type:str="iso7380_1",
direction_axis:str="-Z"
):
"""
Generic fastener constructor that sets common attributes for all faster types.
"""
Expand Down Expand Up @@ -80,15 +89,31 @@ class Screw(Fastener):
"""
_length = 6 # mm

def __init__(self, name, position, explode_translation, size, fastener_type, axis, length):
def __init__(
self,
name:str,
*,
position:tuple[float, float, float]=(0.0, 0.0, 0.0),
explode_translation:tuple[float, float, float]=(0.0, 0.0, 0.0),
size:str="M3-0.5",
fastener_type:str="iso7380_1",
axis:str="-Z",
length:float=6.0
):
"""
Screw constructor that additionally sets the length of the screw.
"""
# pylint: disable=too-many-arguments

self._length = length

super().__init__(name, position, explode_translation, size, fastener_type, axis)
super().__init__(
name,
position=position,
explode_translation=explode_translation,
size=size,
fastener_type=fastener_type,
direction_axis=axis
)

@property
def length(self):
Expand Down
1 change: 1 addition & 0 deletions nimble_build_system/cad/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def cut_w_pattern(body: cad.Body,
size_y: cad.DimensionDefinitionType,
padding_x: float,
padding_y: float,
*,
min_spacing: float = 0,
cut_depth: float = 10,
) -> 'cad.Body':
Expand Down
40 changes: 24 additions & 16 deletions nimble_build_system/cad/shelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""

# pylint: disable=unused-import
# pylint: disable=too-many-positional-arguments

import os
import posixpath
Expand All @@ -31,6 +30,7 @@


def create_shelf_for(device_id: str,
*,
assembly_key: str='Shelf',
position: tuple[float, float, float]=(0,0,0),
color: str='dodgerblue1',
Expand Down Expand Up @@ -75,10 +75,10 @@ def create_shelf_for(device_id: str,
kwargs = {}
return shelf_class(
device,
assembly_key,
position,
color,
rack_params,
assembly_key=assembly_key,
position=position,
color=color,
rack_params=rack_params,
**kwargs
)

Expand Down Expand Up @@ -127,13 +127,13 @@ class Shelf():

def __init__(self,
device: Device,
*,
assembly_key: str,
position: tuple[float, float, float],
color: str,
rack_params: RackParameters
):

# pylint: disable=too-many-arguments

self._rack_params = rack_params

Expand Down Expand Up @@ -516,13 +516,18 @@ class StuffShelf(Shelf):
##TODO: Perhaps make a "dummy" device for "stuff"?
def __init__(self,
device: Device,
*,
assembly_key: str,
position: tuple[float, float, float],
color: str,
rack_params: RackParameters,
thin: bool=False):

super().__init__(device, assembly_key, position, color, rack_params)
super().__init__(device,
assembly_key=assembly_key,
position=position,
color=color,
rack_params=rack_params)
self.thin = thin

def generate_shelf_model(self) -> cadscript.Body:
Expand Down Expand Up @@ -551,7 +556,7 @@ def generate_shelf_model(self) -> cadscript.Body:
builder = ShelfBuilder(
self.height_in_u, width="broad", depth="standard", front_type="full"
)
builder.cut_opening("<Y", builder.inner_width, 4)
builder.cut_opening("<Y", builder.inner_width, offset_y=4)
builder.make_tray(sides="w-pattern", back="open")
builder.add_mounting_hole_to_bottom(x_pos=0, y_pos=35, base_thickness=4, hole_type="M3cs")
builder.add_mounting_hole_to_bottom(x_pos=0, y_pos=120, base_thickness=4, hole_type="M3cs")
Expand All @@ -569,7 +574,7 @@ def generate_shelf_model(self) -> cadscript.Body:
builder = ShelfBuilder(
self.height_in_u, width="standard", depth=119.5, front_type="full"
)
builder.cut_opening("<Y", builder.inner_width, 4)
builder.cut_opening("<Y", builder.inner_width, offset_y=4)
builder.make_tray(sides="w-pattern", back="open")
# add 2 mounting bars on the bottom plate
sketch = cadscript.make_sketch()
Expand Down Expand Up @@ -624,6 +629,7 @@ class AnkerShelf(Shelf):
"""
def __init__(self,
device: Device,
*,
assembly_key: str,
position: tuple[float, float, float],
color: str,
Expand All @@ -633,9 +639,11 @@ def __init__(self,
internal_height: float = 25,
front_cutout_width: float = 53):

#pylint: disable=too-many-arguments

super().__init__(device, assembly_key, position, color, rack_params)
super().__init__(device,
assembly_key=assembly_key,
position=position,
color=color,
rack_params=rack_params)
self.internal_width = internal_width
self.internal_depth = internal_depth
self.internal_height = internal_height
Expand Down Expand Up @@ -811,10 +819,10 @@ def __init__(self,
}

super().__init__(device,
assembly_key,
position,
color,
rack_params)
assembly_key=assembly_key,
position=position,
color=color,
rack_params=rack_params)


def generate_shelf_model(self):
Expand Down
18 changes: 12 additions & 6 deletions nimble_build_system/cad/shelf_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class ShelfBuilder:
def __init__(
self,
height_in_u: int,
width: Union[Literal["standard", "broad"], float],
depth: Union[Literal["standard"], float],
front_type: Literal["full", "open", "w-pattern", "slots"],
*,
width: Union[Literal["standard", "broad"], float] = "standard",
depth: Union[Literal["standard"], float] = "standard",
front_type: Literal["full", "open", "w-pattern", "slots"] = "full",
base_between_beam_walls: Literal["none", "front-open", "closed"] = "closed",
beam_wall_type: Literal["none", "standard", "ramp"] = "standard",
rack_params=None,
Expand Down Expand Up @@ -399,6 +400,7 @@ def cut_opening(
self,
face: str,
size_x: cad.DimensionDefinitionType,
*,
offset_y: float = 0,
size_y: Optional[cad.DimensionDefinitionType] = None,
depth: float = 999,
Expand All @@ -420,7 +422,8 @@ def add_mounting_hole_to_bottom(
x_pos: float,
y_pos: float,
base_thickness: float,
hole_type: Literal["M3cs", "M3-tightfit", "base-only"],
*,
hole_type: Literal["M3cs", "M3-tightfit", "base-only"] = "M3-tightfit",
base_diameter: float = 15,
) -> None:
"""
Expand All @@ -442,8 +445,9 @@ def add_mounting_hole_to_side(
self,
y_pos: float,
z_pos: float,
hole_type: Literal["M3-tightfit", "HDD"],
side: Literal["left", "right", "both"],
*,
hole_type: Literal["M3-tightfit", "HDD"] = "M3-tightfit",
side: Literal["left", "right", "both"] = "both",
base_diameter: float = 8,
) -> None:
"""
Expand Down Expand Up @@ -506,6 +510,7 @@ def add_cage(
internal_width: float,
internal_depth: float,
internal_height: float = 0,
*,
rear_cutout_width: float = 0,
add_ziptie_channels: bool = True,
):
Expand Down Expand Up @@ -587,6 +592,7 @@ def get_body(self) -> cad.Body:

def ziptie_shelf(
height_in_u: int,
*,
internal_width: Optional[float] = None,
internal_depth: Optional[float] = None,
internal_height: Optional[float] = None,
Expand Down
4 changes: 2 additions & 2 deletions py.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ exclude-too-few-public-methods=
# R0901)
ignored-parents=

## CHANGED FOM DEFAULT: increased due to the way we are passing parameters
## CHANGED FOM DEFAULT: increased to allow lots of key word only-args
# Maximum number of arguments for function / method.
max-args=7
max-args=10

# Maximum number of attributes for a class (see R0902).
max-attributes=7
Expand Down

0 comments on commit fa0d083

Please sign in to comment.