Skip to content

Commit e81acb5

Browse files
committed
fix: ruff I001 import sorting and float(usable_height) unit mismatch
Add [tool.ruff.lint.isort] known-third-party config so FreeCAD, FreeCADGui, and Part are classified consistently on macOS and Linux. Revert import reordering to alphabetical within a single block. Remove float() wrappers from usable_height in make_scoop() which stripped FreeCAD Quantity units, causing "Unit mismatch in plus operation" at runtime. Use targeted type: ignore[arg-type] comments for the freecad-stubs false positives instead.
1 parent 48b79c8 commit e81acb5

4 files changed

Lines changed: 35 additions & 23 deletions

File tree

freecad/gridfinity_workbench/feature_construction.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Module containing gridfinity feature constructions."""
22

3+
from __future__ import annotations
4+
35
import math
46
from typing import Literal
57

@@ -187,8 +189,24 @@ def scoop_properties(obj: fc.DocumentObject, *, scoop_default: bool) -> None:
187189
).Scoop = scoop_default
188190

189191

190-
def make_scoop(obj: fc.DocumentObject) -> Part.Shape:
191-
"""Create scoop."""
192+
def make_scoop(
193+
obj: fc.DocumentObject,
194+
*,
195+
usable_height: None | fc.Units.Quantity = None,
196+
) -> Part.Shape:
197+
"""Create scoop.
198+
199+
Args:
200+
obj: The object onto which to add the scoop.
201+
usable_height: Override the obj's UsableHeight value (for EcoBins).
202+
203+
EcoBins are constructed in such a way that when the scoop is added, the
204+
proper usable height (for correct geometry) has to be provided separately.
205+
206+
"""
207+
if usable_height is None:
208+
usable_height = obj.UsableHeight
209+
192210
scooprad1 = obj.ScoopRadius + unitmm
193211
scooprad2 = obj.ScoopRadius + unitmm
194212
scooprad3 = obj.ScoopRadius + unitmm
@@ -203,8 +221,8 @@ def make_scoop(obj: fc.DocumentObject) -> Part.Shape:
203221
scooprad1 = xdivscoop - unitmm
204222
if obj.ScoopRadius > xcomp_w and obj.xDividers > 0:
205223
scooprad2 = xcomp_w - 2 * unitmm
206-
if obj.ScoopRadius > obj.UsableHeight > 0:
207-
scooprad3 = obj.UsableHeight - obj.LabelShelfStackingOffset
224+
if obj.ScoopRadius > usable_height > 0:
225+
scooprad3 = usable_height - obj.LabelShelfStackingOffset
208226

209227
scooprad = min(obj.ScoopRadius, scooprad1, scooprad2, scooprad3)
210228

@@ -214,17 +232,17 @@ def make_scoop(obj: fc.DocumentObject) -> Part.Shape:
214232
v1 = fc.Vector(
215233
obj.xTotalWidth + obj.Clearance - obj.WallThickness,
216234
0,
217-
-obj.UsableHeight + scooprad,
235+
-usable_height + scooprad,
218236
)
219237
v2 = fc.Vector(
220238
obj.xTotalWidth + obj.Clearance - obj.WallThickness,
221239
0,
222-
-obj.UsableHeight,
240+
-usable_height, # type: ignore[arg-type]
223241
)
224242
v3 = fc.Vector(
225243
obj.xTotalWidth + obj.Clearance - obj.WallThickness - scooprad,
226244
0,
227-
-obj.UsableHeight,
245+
-usable_height, # type: ignore[arg-type]
228246
)
229247

230248
l1 = Part.LineSegment(v1, v2)
@@ -237,7 +255,7 @@ def make_scoop(obj: fc.DocumentObject) -> Part.Shape:
237255
- scooprad
238256
+ scooprad * math.sin(math.pi / 4),
239257
0,
240-
-obj.UsableHeight + scooprad - scooprad * math.sin(math.pi / 4),
258+
-usable_height + scooprad - scooprad * math.sin(math.pi / 4),
241259
)
242260

243261
c1 = Part.Arc(v1, vc1, v3)
@@ -268,7 +286,7 @@ def make_scoop(obj: fc.DocumentObject) -> Part.Shape:
268286
scoopbox = Part.makeBox(
269287
stacking_lip_offset.Value,
270288
obj.yTotalWidth - obj.WallThickness * 2,
271-
obj.UsableHeight,
289+
usable_height, # type: ignore[arg-type]
272290
fc.Vector(
273291
obj.xTotalWidth + obj.Clearance - obj.WallThickness,
274292
obj.Clearance + obj.WallThickness,
@@ -280,7 +298,7 @@ def make_scoop(obj: fc.DocumentObject) -> Part.Shape:
280298
edges = [
281299
edge
282300
for edge in funcfuse.Edges
283-
if abs(edge.Vertexes[0].Z - edge.Vertexes[1].Z) == obj.UsableHeight
301+
if abs(edge.Vertexes[0].Z - edge.Vertexes[1].Z) == usable_height
284302
and edge.Vertexes[0].X == edge.Vertexes[1].X
285303
]
286304

freecad/gridfinity_workbench/features.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
from abc import abstractmethod
66

7-
import Part
8-
97
import FreeCAD as fc # noqa: N813
8+
import Part
109

1110
from . import baseplate_feature_construction as baseplate_feat
1211
from . import const, grid_initial_layout, label_shelf, utils
@@ -315,11 +314,7 @@ def generate_gridfinity_shape(self, obj: fc.DocumentObject) -> Part.Shape:
315314

316315
# Now add scoop, but only where eco compartments exist (reversed logic)
317316
if obj.Scoop:
318-
# Store original UsableHeight and adjust for eco bin's deeper compartment
319-
original_usable_height = obj.UsableHeight
320-
obj.UsableHeight = obj.TotalHeight - obj.BaseWallThickness
321-
scoop = feat.make_scoop(obj)
322-
obj.UsableHeight = original_usable_height # Restore original value
317+
scoop = feat.make_scoop(obj, usable_height=obj.TotalHeight - obj.BaseWallThickness)
323318
# Only add scoop where compartments exist - use intersection to constrain
324319
scoop_constrained = scoop.common(eco_compartments)
325320
fuse_total = fuse_total.fuse(scoop_constrained)
@@ -679,11 +674,7 @@ def generate_gridfinity_shape(self, obj: fc.DocumentObject) -> Part.Shape:
679674

680675
# Now add scoop, but only where eco compartments exist (reversed logic)
681676
if obj.Scoop:
682-
# Store original UsableHeight and adjust for eco bin's deeper compartment
683-
original_usable_height = obj.UsableHeight
684-
obj.UsableHeight = obj.TotalHeight - obj.BaseWallThickness
685-
scoop = feat.make_scoop(obj)
686-
obj.UsableHeight = original_usable_height # Restore original value
677+
scoop = feat.make_scoop(obj, usable_height=obj.TotalHeight - obj.BaseWallThickness)
687678
# Only add scoop where compartments exist - use intersection to constrain
688679
scoop_constrained = scoop.common(compartments)
689680
fuse_total = fuse_total.fuse(scoop_constrained)

freecad/gridfinity_workbench/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import math
1010
from typing import TYPE_CHECKING
1111

12-
import FreeCAD as fc # noqa:N813
12+
import FreeCAD as fc # noqa: N813
1313
import FreeCADGui as fcg # noqa: N813
1414
import Part
1515

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ ignore = ["ANN003", "EM101", "EM102", "RET504", "TRY003", "S101", "SIM300"]
3333
# PT009 - pytest-unittest-assertion: we use unittest framework, not pytest
3434
"**/tests/*" = ["INP001", "D100", "D101", "D102", "PT027", "PT009"]
3535
"freecad/gridfinity_workbench/test_gridfinity.py" = ["D100", "D101", "D102", "PT027", "PT009"]
36+
37+
[tool.ruff.lint.isort]
38+
known-third-party = ["FreeCAD", "FreeCADGui", "Part"]

0 commit comments

Comments
 (0)