[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot]
2025-04-08 10:15:00 +00:00
committed by jalapenopuzzle
parent 9298ad8ad0
commit c7773b5d4d
2 changed files with 64 additions and 75 deletions

View File

@@ -126,9 +126,7 @@ M5
self.assertEqual(gcode, expected_body)
# test body without comments
gcode = self.get_gcode(
[], "--machine=A350 --toolhead=50W_CNC --no-header --no-comments"
)
gcode = self.get_gcode([], "--machine=A350 --toolhead=50W_CNC --no-header --no-comments")
expected = "".join(
[line for line in expected_body.splitlines(keepends=True) if not line.startswith(";")]
)
@@ -139,9 +137,7 @@ M5
command = Path.Command("G0 X10 Y20 Z30")
expected = "G0 X10.000 Y20.000 Z30.000"
gcode = self.get_gcode(
[command], "--machine=A350 --toolhead=50W_CNC --no-header"
)
gcode = self.get_gcode([command], "--machine=A350 --toolhead=50W_CNC --no-header")
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
@@ -195,9 +191,7 @@ M5
# test inches conversion
expected = "G0 X0.3937 Y0.7874 Z1.1811"
gcode = self.get_gcode(
[command], "--machine=A350 --toolhead=50W_CNC --no-header --inches"
)
gcode = self.get_gcode([command], "--machine=A350 --toolhead=50W_CNC --no-header --inches")
self.assertEqual(gcode.splitlines()[3], "G20")
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
@@ -230,9 +224,7 @@ M5
c0 = Path.Command("M6 T2")
c1 = Path.Command("M3 S3000")
gcode = self.get_gcode(
[c0, c1], "--machine=A350 --toolhead=50W_CNC --no-header"
)
gcode = self.get_gcode([c0, c1], "--machine=A350 --toolhead=50W_CNC --no-header")
self.assertEqual(gcode.splitlines()[19:22], ["M5", "M76", "M6 T2"])
self.assertEqual(
gcode.splitlines()[22], "M3 P25"
@@ -330,8 +322,8 @@ M5
)
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"],[])
self.assertEqual(self.post.values["BOUNDARIES"],dict(X=90, Y=90, Z=50))
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"], [])
self.assertEqual(self.post.values["BOUNDARIES"], dict(X=90, Y=90, Z=50))
gcode = self.get_gcode(
[command],
@@ -339,8 +331,8 @@ M5
)
# I don't understand why export returns the arguments
# if snapmaker_process_arguments fails.
self.assertTrue(isinstance(gcode,argparse.Namespace))
self.assertFalse(isinstance(gcode,str))
self.assertTrue(isinstance(gcode, argparse.Namespace))
self.assertFalse(isinstance(gcode, str))
gcode = self.get_gcode(
[command],
@@ -348,8 +340,8 @@ M5
)
# I don't understand why export returns the arguments
# if snapmaker_process_arguments fails.
self.assertTrue(isinstance(gcode,argparse.Namespace))
self.assertFalse(isinstance(gcode,str))
self.assertTrue(isinstance(gcode, argparse.Namespace))
self.assertFalse(isinstance(gcode, str))
gcode = self.get_gcode(
[command],
@@ -357,8 +349,8 @@ M5
)
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"],[])
self.assertEqual(self.post.values["BOUNDARIES"],dict(X=400, Y=400, Z=400))
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"], [])
self.assertEqual(self.post.values["BOUNDARIES"], dict(X=400, Y=400, Z=400))
gcode = self.get_gcode(
[command],
@@ -366,8 +358,8 @@ M5
)
# I don't understand why export returns the arguments
# if snapmaker_process_arguments fails.
self.assertTrue(isinstance(gcode,argparse.Namespace))
self.assertFalse(isinstance(gcode,str))
self.assertTrue(isinstance(gcode, argparse.Namespace))
self.assertFalse(isinstance(gcode, str))
gcode = self.get_gcode(
[command],
@@ -375,8 +367,8 @@ M5
)
# I don't understand why export returns the arguments
# if snapmaker_process_arguments fails.
self.assertTrue(isinstance(gcode,argparse.Namespace))
self.assertFalse(isinstance(gcode,str))
self.assertTrue(isinstance(gcode, argparse.Namespace))
self.assertFalse(isinstance(gcode, str))
gcode = self.get_gcode(
[command],
@@ -384,8 +376,8 @@ M5
)
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"],["BK"])
self.assertEqual(self.post.values["BOUNDARIES"],dict(X=160, Y=148, Z=84))
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"], ["BK"])
self.assertEqual(self.post.values["BOUNDARIES"], dict(X=160, Y=148, Z=84))
gcode = self.get_gcode(
[command],
@@ -393,8 +385,8 @@ M5
)
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"],["QS"])
self.assertEqual(self.post.values["BOUNDARIES"],dict(X=160, Y=145, Z=75))
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"], ["QS"])
self.assertEqual(self.post.values["BOUNDARIES"], dict(X=160, Y=145, Z=75))
gcode = self.get_gcode(
[command],
@@ -402,8 +394,8 @@ M5
)
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"],["QS","BK"])
self.assertEqual(self.post.values["BOUNDARIES"],dict(X=230, Y=223, Z=159))
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"], ["QS", "BK"])
self.assertEqual(self.post.values["BOUNDARIES"], dict(X=230, Y=223, Z=159))
gcode = self.get_gcode(
[command],
@@ -411,8 +403,8 @@ M5
)
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"],["QS"])
self.assertEqual(self.post.values["BOUNDARIES"],dict(X=230, Y=235, Z=165))
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"], ["QS"])
self.assertEqual(self.post.values["BOUNDARIES"], dict(X=230, Y=235, Z=165))
gcode = self.get_gcode(
[command],
@@ -420,8 +412,8 @@ M5
)
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"],["QS","BK"])
self.assertEqual(self.post.values["BOUNDARIES"],dict(X=320, Y=323, Z=254))
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"], ["QS", "BK"])
self.assertEqual(self.post.values["BOUNDARIES"], dict(X=320, Y=323, Z=254))
gcode = self.get_gcode(
[command],
@@ -429,8 +421,8 @@ M5
)
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"],["QS","BK"])
self.assertEqual(self.post.values["BOUNDARIES"],dict(X=320, Y=323, Z=254))
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"], ["QS", "BK"])
self.assertEqual(self.post.values["BOUNDARIES"], dict(X=320, Y=323, Z=254))
gcode = self.get_gcode(
[command],
@@ -438,8 +430,8 @@ M5
)
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"],["QS","BK"])
self.assertEqual(self.post.values["BOUNDARIES"],dict(X=320, Y=310, Z=254))
self.assertEqual(self.post.values["MOD_KITS_INSTALLED"], ["QS", "BK"])
self.assertEqual(self.post.values["BOUNDARIES"], dict(X=320, Y=310, Z=254))
def test_toolhead_selection(self):
"""Test automatic selection of toolhead where appropriate"""
@@ -454,19 +446,19 @@ M5
)
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
self.assertEqual(self.post.values["TOOLHEAD_NAME"],"Original CNC module")
self.assertEqual(self.post.values["TOOLHEAD_NAME"], "Original CNC module")
gcode = self.get_gcode(
[command],
"--machine=A350 --no-header",
)
self.assertFalse(isinstance(gcode,str))
self.assertFalse(isinstance(gcode, str))
gcode = self.get_gcode(
[command],
"--machine=A350T --no-header",
)
self.assertFalse(isinstance(gcode,str))
self.assertFalse(isinstance(gcode, str))
# check succeed with artisan (which base is bigger)
gcode = self.get_gcode(
@@ -475,7 +467,7 @@ M5
)
result = gcode.splitlines()[18]
self.assertEqual(result, expected)
self.assertEqual(self.post.values["TOOLHEAD_NAME"],"200W CNC module")
self.assertEqual(self.post.values["TOOLHEAD_NAME"], "200W CNC module")
def test_spindle_percent_rpm_auto_select(self):
"""Test automatic selection of spindle speed rpm vs percent"""
@@ -483,29 +475,21 @@ M5
command = Path.Command("M3 S2100")
# test original toolhead
gcode = self.get_gcode(
[command], "--machine=Original --no-header"
)
gcode = self.get_gcode([command], "--machine=Original --no-header")
self.assertEqual(gcode.splitlines()[18], "M3 P30")
command = Path.Command("M3 S3600")
# test 50W toolhead
gcode = self.get_gcode(
[command], "--machine=A350 --toolhead=50W_CNC --no-header"
)
gcode = self.get_gcode([command], "--machine=A350 --toolhead=50W_CNC --no-header")
self.assertEqual(gcode.splitlines()[18], "M3 P30")
# test 200W toolhead
gcode = self.get_gcode(
[command], "--machine=A350 --toolhead=200W_CNC --no-header"
)
gcode = self.get_gcode([command], "--machine=A350 --toolhead=200W_CNC --no-header")
self.assertEqual(gcode.splitlines()[18], "M3 S3600")
# test 200W toolhead
gcode = self.get_gcode(
[command], "--machine=Artisan --no-header"
)
gcode = self.get_gcode([command], "--machine=Artisan --no-header")
self.assertEqual(gcode.splitlines()[18], "M3 S3600")
def test_spindle_percent(self):

View File

@@ -46,14 +46,16 @@ if DEBUG := False:
else:
Path.Log.setLevel(Path.Log.Level.INFO, Path.Log.thisModule())
def convert_option_to_attr(option_name):
# transforms argparse options into identifiers
if option_name.startswith('--'):
if option_name.startswith("--"):
option_name = option_name[2:]
elif option_name.startswith('-'):
elif option_name.startswith("-"):
option_name = option_name[1:]
return option_name.replace('-','_')
return option_name.replace("-", "_")
SNAPMAKER_MACHINES = dict(
Original=dict(
@@ -61,56 +63,56 @@ SNAPMAKER_MACHINES = dict(
name="Snapmaker Original",
boundaries=dict(X=90, Y=90, Z=50),
compatible_toolheads={"Original_CNC"},
lead=dict(X=8, Y=8, Z=8), # Linear module screw pitch (mm/turn)
lead=dict(X=8, Y=8, Z=8), # Linear module screw pitch (mm/turn)
),
Original_Z_Extension=dict(
key="Original_Z_Extension",
name="Snapmaker Original with Z extension",
boundaries=dict(X=90, Y=90, Z=146),
compatible_toolheads={"Original_CNC"},
lead=dict(X=8, Y=8, Z=8), # Linear module screw pitch (mm/turn)
lead=dict(X=8, Y=8, Z=8), # Linear module screw pitch (mm/turn)
),
A150=dict(
key="A150",
name="Snapmaker 2 A150",
boundaries=dict(X=160, Y=160, Z=90),
compatible_toolheads={"50W_CNC"},
lead=dict(X=8, Y=8, Z=8), # Linear module screw pitch (mm/turn)
lead=dict(X=8, Y=8, Z=8), # Linear module screw pitch (mm/turn)
),
A250=dict(
key="A250",
name="Snapmaker 2 A250",
boundaries=dict(X=230, Y=250, Z=180),
compatible_toolheads={"50W_CNC", "200W_CNC"},
lead=dict(X=8, Y=8, Z=8), # Linear module screw pitch (mm/turn)
lead=dict(X=8, Y=8, Z=8), # Linear module screw pitch (mm/turn)
),
A250T=dict(
key="A250T",
name="Snapmaker 2 A250T",
boundaries=dict(X=230, Y=250, Z=180),
compatible_toolheads={"50W_CNC", "200W_CNC"},
lead=dict(X=20, Y=20, Z=8), # Linear module screw pitch (mm/turn)
lead=dict(X=20, Y=20, Z=8), # Linear module screw pitch (mm/turn)
),
A350=dict(
key="A350",
name="Snapmaker 2 A350",
boundaries=dict(X=320, Y=350, Z=275),
compatible_toolheads={"50W_CNC", "200W_CNC"},
lead=dict(X=8, Y=8, Z=8), # Linear module screw pitch (mm/turn)
lead=dict(X=8, Y=8, Z=8), # Linear module screw pitch (mm/turn)
),
A350T=dict(
key="A350T",
name="Snapmaker 2 A350T",
boundaries=dict(X=320, Y=350, Z=275),
compatible_toolheads={"50W_CNC", "200W_CNC"},
lead=dict(X=20, Y=20, Z=8), # Linear module screw pitch (mm/turn)
lead=dict(X=20, Y=20, Z=8), # Linear module screw pitch (mm/turn)
),
Artisan=dict(
key="Artisan",
name="Snapmaker Artisan",
boundaries=dict(X=400, Y=413, Z=400),
compatible_toolheads={"200W_CNC"},
lead=dict(X=40, Y=40, Z=8), # Linear module screw pitch (mm/turn)
lead=dict(X=40, Y=40, Z=8), # Linear module screw pitch (mm/turn)
),
)
@@ -122,7 +124,7 @@ SNAPMAKER_MOD_KITS = {
name="Quick Swap Kit",
option_name="--quick-swap",
option_help_text="Indicates that the quick swap kit is installed. Only compatible with Snapmaker 2 machines.",
compatible_machines={"A150","A250","A250T","A350","A350T"},
compatible_machines={"A150", "A250", "A250T", "A350", "A350T"},
boundaries_delta=dict(X=0, Y=-15, Z=-15),
),
"BK": dict(
@@ -130,7 +132,7 @@ SNAPMAKER_MOD_KITS = {
name="Bracing Kit",
option_name="--bracing-kit",
option_help_text="Indicates that the bracing kit is installed. Only compatible with Snapmaker 2 machines.",
compatible_machines={"A150","A250","A250T","A350","A350T"},
compatible_machines={"A150", "A250", "A250T", "A350", "A350T"},
boundaries_delta=dict(X=0, Y=-12, Z=-6),
),
}
@@ -440,7 +442,9 @@ class Snapmaker(Path.Post.Processor.PostProcessor):
return parser
def snapmaker_process_arguments(self, filename: str = "-") -> Tuple[bool, str | argparse.Namespace]:
def snapmaker_process_arguments(
self, filename: str = "-"
) -> Tuple[bool, str | argparse.Namespace]:
"""Process any arguments to the postprocessor."""
(flag, args) = Path.Post.UtilsArguments.process_shared_arguments(
self.values, self.parser, self._job.PostProcessorArgs, self.visible_parser, filename
@@ -459,7 +463,8 @@ class Snapmaker(Path.Post.Processor.PostProcessor):
if args.toolhead not in machine["compatible_toolheads"]:
FreeCAD.Console.PrintError(
f"Selected --toolhead={args.toolhead} is not compatible with machine {machine['name']}."
+f" Choose from [{machine['compatible_toolheads']}]\n")
+ f" Choose from [{machine['compatible_toolheads']}]\n"
)
flag = False
return (flag, args)
toolhead = self.values["TOOLHEADS"][args.toolhead]
@@ -488,21 +493,21 @@ class Snapmaker(Path.Post.Processor.PostProcessor):
else:
FreeCAD.Console.PrintError(
f"Requested spindle speed in percent, but toolhead {toolhead['name']}"
+" does not support speed as percent.\n"
+ " does not support speed as percent.\n"
)
flag = False
return (flag, args)
else:
# Prefer speed S over percent P
self.values["SPINDLE_PERCENT"] = toolhead['has_percent'] and not toolhead['has_speed_s']
self.values["SPINDLE_PERCENT"] = (
toolhead["has_percent"] and not toolhead["has_speed_s"]
)
if self.values["SPINDLE_PERCENT"]:
FreeCAD.Console.PrintWarning(
"Spindle speed will be controlled using using percentages.\n"
)
else:
FreeCAD.Console.PrintWarning(
"Spindle speed will be controlled using using RPM.\n"
)
FreeCAD.Console.PrintWarning("Spindle speed will be controlled using using RPM.\n")
self.values["MOD_KITS_INSTALLED"] = []
if args.boundaries: # may override machine boundaries, which is expected