verify-print 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ """Pre-print STL + CAD verification pipeline.
2
+
3
+ Modules:
4
+ - mesh_integrity: trimesh-based watertight/manifold/shells, wall thickness, orientation
5
+ - mesh_info: fast bbox / volume / build-volume fit / mass estimate
6
+ - param_linter: AST-based orphan and ghost param key detector
7
+ - slicer_simulate: Bambu Studio + OrcaSlicer CLI wrappers with profile-aware
8
+ print time / filament / volumetric-speed bottleneck detection
9
+ - project_check: pre-print gate for 3MF projects
10
+ - iteration_compare: diff two JSON reports
11
+ - mesh_repair: PyMeshLab self-intersection detection + repair (optional extra)
12
+ - feature_color: CadQuery Assembly multi-color export (optional extra)
13
+ """
14
+
15
+ __version__ = "0.5.0"
16
+
17
+ from verify_print.iteration_compare import CompareReport, compare_reports
18
+ from verify_print.mesh_info import MeshInfoReport, mesh_info
19
+ from verify_print.mesh_integrity import (
20
+ IntegrityReport,
21
+ OrientationReport,
22
+ WallThicknessReport,
23
+ check_mesh,
24
+ check_orientation,
25
+ check_wall_thickness,
26
+ )
27
+ from verify_print.param_linter import LinterReport, OrphanKey, GhostReference, lint_params
28
+ from verify_print.slicer_simulate import SliceReport, slice_stl
29
+
30
+ __all__ = [
31
+ "CompareReport",
32
+ "compare_reports",
33
+ "IntegrityReport",
34
+ "MeshInfoReport",
35
+ "OrientationReport",
36
+ "WallThicknessReport",
37
+ "check_mesh",
38
+ "check_orientation",
39
+ "check_wall_thickness",
40
+ "mesh_info",
41
+ "LinterReport",
42
+ "OrphanKey",
43
+ "GhostReference",
44
+ "lint_params",
45
+ "SliceReport",
46
+ "slice_stl",
47
+ ]
@@ -0,0 +1,44 @@
1
+ """Bounded reads from 3MF (zip) archives.
2
+
3
+ 3MF projects are often downloaded from model sites, so treat them as untrusted:
4
+ never read an archive member whole into memory without a size limit (zip bombs),
5
+ and do not trust the size in the zip header alone.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ import zipfile
10
+
11
+ # Settings / metadata members are kilobytes in real projects; 64 MB is far above that.
12
+ MAX_MEMBER_BYTES = 64 * 1024 * 1024
13
+ _CHUNK = 1024 * 1024
14
+
15
+
16
+ class MemberTooLarge(ValueError):
17
+ """An archive member is larger than the allowed limit."""
18
+
19
+
20
+ def read_member(zf: zipfile.ZipFile, name: str, limit: int = MAX_MEMBER_BYTES) -> bytes:
21
+ """Read one member, refusing anything over `limit` bytes (declared or actual)."""
22
+ info = zf.getinfo(name)
23
+ if info.file_size > limit:
24
+ raise MemberTooLarge(f"{name}: declared size {info.file_size} bytes exceeds limit {limit}")
25
+ with zf.open(info) as f:
26
+ data = f.read(limit + 1) # the header can lie; cap the real read too
27
+ if len(data) > limit:
28
+ raise MemberTooLarge(f"{name}: actual size exceeds limit {limit}")
29
+ return data
30
+
31
+
32
+ def read_head_tail(zf: zipfile.ZipFile, name: str, n: int = 200_000) -> tuple[bytes, bytes]:
33
+ """Stream a (possibly huge) member and keep only its first and last `n` bytes."""
34
+ head = b""
35
+ tail = b""
36
+ with zf.open(name) as f:
37
+ while True:
38
+ chunk = f.read(_CHUNK)
39
+ if not chunk:
40
+ break
41
+ if len(head) < n:
42
+ head += chunk[: n - len(head)]
43
+ tail = (tail + chunk)[-n:]
44
+ return head, tail
verify_print/cli.py ADDED
@@ -0,0 +1,547 @@
1
+ """CLI entry point — `verify-print` command.
2
+
3
+ Subcommands:
4
+ mesh <stl> — mesh integrity (trimesh)
5
+ params <params.py> <code...> — param hygiene (AST)
6
+ repair <stl> — PyMeshLab deep checks / repair
7
+ slice <stl> --filament/--process/--machine — headless slice + bottleneck gate (Bambu Studio CLI default; --slicer orca)
8
+ project <file.3mf> [--slice] — pre-print gate on a Bambu/Orca project: time-multiplier settings, what changed vs stock, per-plate time
9
+ all <directory> — orchestrate above
10
+
11
+ Global flag:
12
+ --json — emit machine-readable JSON
13
+ instead of human format
14
+
15
+ Exit codes: 0 pass · 1 fail · 2 usage error.
16
+ """
17
+ from __future__ import annotations
18
+
19
+ import argparse
20
+ import json
21
+ import sys
22
+ import zipfile
23
+ from dataclasses import asdict, is_dataclass
24
+ from pathlib import Path
25
+ from typing import Any
26
+
27
+ from verify_print.iteration_compare import compare_reports
28
+ from verify_print.mesh_info import mesh_info
29
+ from verify_print.mesh_integrity import (
30
+ check_mesh,
31
+ check_orientation,
32
+ check_wall_thickness,
33
+ )
34
+ from verify_print.param_linter import lint_params
35
+ from verify_print.slicer_simulate import slice_stl
36
+ from verify_print.project_check import check_project, report_to_dict
37
+ from verify_print._safezip import MemberTooLarge
38
+
39
+ try:
40
+ from verify_print.mesh_repair import check_and_repair
41
+ _MESH_REPAIR_AVAILABLE = True
42
+ except ImportError:
43
+ _MESH_REPAIR_AVAILABLE = False
44
+
45
+
46
+ def _make_json_safe(obj: Any) -> Any:
47
+ """Recursively convert sets/Paths/non-primitives to JSON-serializable types."""
48
+ if isinstance(obj, dict):
49
+ return {str(k): _make_json_safe(v) for k, v in obj.items()}
50
+ if isinstance(obj, (list, tuple)):
51
+ return [_make_json_safe(x) for x in obj]
52
+ if isinstance(obj, set):
53
+ try:
54
+ return sorted(_make_json_safe(x) for x in obj)
55
+ except TypeError:
56
+ return list(_make_json_safe(x) for x in obj)
57
+ if isinstance(obj, Path):
58
+ return str(obj)
59
+ if is_dataclass(obj):
60
+ return _make_json_safe(asdict(obj))
61
+ return obj
62
+
63
+
64
+ def _emit(report: Any, *, as_json: bool) -> None:
65
+ if as_json:
66
+ payload = _make_json_safe(asdict(report) if is_dataclass(report) else report)
67
+ # Include `passed` boolean for downstream parsing
68
+ if hasattr(report, "passed"):
69
+ payload["passed"] = report.passed
70
+ print(json.dumps(payload, indent=2))
71
+ else:
72
+ print(report.format())
73
+
74
+
75
+ def _cmd_mesh(args: argparse.Namespace) -> int:
76
+ report = check_mesh(
77
+ Path(args.stl),
78
+ max_disconnected_shells=args.max_shells,
79
+ min_volume_mm3=args.min_volume,
80
+ )
81
+ _emit(report, as_json=args.json)
82
+ return 0 if report.passed else 1
83
+
84
+
85
+ def _cmd_params(args: argparse.Namespace) -> int:
86
+ report = lint_params(
87
+ Path(args.params_file),
88
+ [Path(p) for p in args.code_files],
89
+ )
90
+ _emit(report, as_json=args.json)
91
+ return 0 if report.passed else 1
92
+
93
+
94
+ def _cmd_info(args: argparse.Namespace) -> int:
95
+ bv = None
96
+ if args.build_volume:
97
+ parts = [float(x) for x in args.build_volume.split(",")]
98
+ if len(parts) != 3:
99
+ msg = f"--build-volume expects 3 comma-separated values, got {args.build_volume!r}"
100
+ if args.json:
101
+ print(json.dumps({"error": msg, "passed": False}))
102
+ else:
103
+ print(f"error: {msg}", file=sys.stderr)
104
+ return 2
105
+ bv = tuple(parts)
106
+ report = mesh_info(
107
+ Path(args.stl),
108
+ build_volume_mm=bv,
109
+ material_density=args.density,
110
+ )
111
+ _emit(report, as_json=args.json)
112
+ return 0 if report.passed else 1
113
+
114
+
115
+ def _cmd_compare(args: argparse.Namespace) -> int:
116
+ report = compare_reports(Path(args.before), Path(args.after))
117
+ _emit(report, as_json=args.json)
118
+ return 0 if report.passed else 1
119
+
120
+
121
+ def _cmd_thickness(args: argparse.Namespace) -> int:
122
+ report = check_wall_thickness(
123
+ Path(args.stl),
124
+ threshold_mm=args.threshold,
125
+ sample_count=args.samples,
126
+ seed=args.seed,
127
+ )
128
+ _emit(report, as_json=args.json)
129
+ return 0 if report.passed else 1
130
+
131
+
132
+ def _cmd_orientation(args: argparse.Namespace) -> int:
133
+ normal = tuple(float(x) for x in args.normal.split(","))
134
+ if len(normal) != 3:
135
+ msg = f"--normal expects 3 comma-separated values, got {args.normal!r}"
136
+ if args.json:
137
+ print(json.dumps({"error": msg, "passed": False}))
138
+ else:
139
+ print(f"error: {msg}", file=sys.stderr)
140
+ return 2
141
+ report = check_orientation(
142
+ Path(args.stl),
143
+ expected_face_normal=normal,
144
+ feature_name=args.feature,
145
+ min_hole_area_mm2=args.min_area,
146
+ alignment_threshold=args.alignment,
147
+ )
148
+ _emit(report, as_json=args.json)
149
+ return 0 if report.passed else 1
150
+
151
+
152
+ def _cmd_repair(args: argparse.Namespace) -> int:
153
+ if not _MESH_REPAIR_AVAILABLE:
154
+ msg = "mesh_repair requires pymeshlab. Install: python3 -m pip install -e \".[mesh-repair]\""
155
+ if args.json:
156
+ print(json.dumps({"error": msg, "passed": False}))
157
+ else:
158
+ print(f"error: {msg}", file=sys.stderr)
159
+ return 2
160
+ report = check_and_repair(
161
+ Path(args.stl),
162
+ repair=args.repair,
163
+ output_path=Path(args.output) if args.output else None,
164
+ )
165
+ _emit(report, as_json=args.json)
166
+ return 0 if report.passed else 1
167
+
168
+
169
+ def _cmd_slice(args: argparse.Namespace) -> int:
170
+ """Slice one or more STLs. Returns 0 only if ALL slices pass."""
171
+ # Expand directories: if any arg is a directory, glob for *.stl
172
+ stls: List[Path] = []
173
+ for s in args.stls:
174
+ p = Path(s)
175
+ if p.is_dir():
176
+ stls.extend(sorted(p.glob("*.stl")))
177
+ elif p.exists():
178
+ stls.append(p)
179
+ else:
180
+ msg = f"STL not found: {p}"
181
+ if args.json:
182
+ print(json.dumps({"error": msg, "passed": False}))
183
+ else:
184
+ print(f"error: {msg}", file=sys.stderr)
185
+ return 2
186
+
187
+ if not stls:
188
+ msg = "no STL files matched"
189
+ if args.json:
190
+ print(json.dumps({"error": msg, "passed": False}))
191
+ else:
192
+ print(f"error: {msg}", file=sys.stderr)
193
+ return 2
194
+
195
+ reports = []
196
+ failures = 0
197
+ for stl in stls:
198
+ report = slice_stl(
199
+ stl,
200
+ slicer=args.slicer,
201
+ filament_profile=Path(args.filament),
202
+ process_profile=Path(args.process),
203
+ machine_profile=Path(args.machine),
204
+ output_dir=Path(args.output_dir),
205
+ timeout_seconds=args.timeout,
206
+ max_print_time_hours=args.max_hours,
207
+ max_filament_grams=args.max_grams,
208
+ min_volumetric_speed=args.min_speed,
209
+ )
210
+ reports.append(report)
211
+ if not report.passed:
212
+ failures += 1
213
+
214
+ if args.json:
215
+ entries = []
216
+ for r in reports:
217
+ entry = _make_json_safe(asdict(r))
218
+ entry["passed"] = r.passed
219
+ entries.append(entry)
220
+ print(json.dumps({"slices": entries, "failures": failures, "passed": failures == 0}, indent=2))
221
+ else:
222
+ for r in reports:
223
+ print(r.format())
224
+ print()
225
+ if failures:
226
+ print(f"FAILED — {failures} slice(s) had issues")
227
+ else:
228
+ print("ALL SLICES PASSED")
229
+ return 0 if failures == 0 else 1
230
+
231
+
232
+ def _cmd_project(args: argparse.Namespace) -> int:
233
+ """Pre-print gate on a 3MF project. Returns 0 if no FAIL findings."""
234
+ threemf = Path(args.threemf)
235
+ if not threemf.exists():
236
+ msg = f"3MF not found: {threemf}"
237
+ print(json.dumps({"error": msg, "passed": False}) if args.json else f"error: {msg}", file=sys.stdout if args.json else sys.stderr)
238
+ return 2
239
+ try:
240
+ report = check_project(
241
+ threemf,
242
+ expected_printer=args.printer,
243
+ do_slice=args.slice,
244
+ max_hours=args.max_hours,
245
+ timeout_seconds=args.timeout,
246
+ )
247
+ except (zipfile.BadZipFile, MemberTooLarge, ValueError) as e:
248
+ msg = f"cannot read 3MF {threemf}: {e}"
249
+ print(json.dumps({"error": msg, "passed": False}) if args.json else f"error: {msg}", file=sys.stdout if args.json else sys.stderr)
250
+ return 2
251
+ if args.json:
252
+ print(json.dumps(_make_json_safe(report_to_dict(report)), indent=2))
253
+ else:
254
+ print(report.format())
255
+ return 0 if report.passed else 1
256
+
257
+
258
+ def _cmd_all(args: argparse.Namespace) -> int:
259
+ root = Path(args.directory)
260
+ if not root.is_dir():
261
+ msg = f"{root} is not a directory"
262
+ if args.json:
263
+ print(json.dumps({"error": msg, "passed": False}))
264
+ else:
265
+ print(f"error: {msg}", file=sys.stderr)
266
+ return 2
267
+
268
+ params_file = root / "params.py"
269
+ code_files = [
270
+ p for p in root.glob("*.py")
271
+ if p.name != "params.py" and not p.name.startswith("_")
272
+ ]
273
+ # Recursive STL search but de-duplicate
274
+ stl_files = sorted({p.resolve() for p in root.glob("**/*.stl")})
275
+
276
+ # Determine which checks to run
277
+ run_slice = bool(args.filament and args.process and args.machine)
278
+ run_repair = args.include_repair and _MESH_REPAIR_AVAILABLE
279
+
280
+ results = {
281
+ "directory": str(root),
282
+ "params_file": str(params_file) if params_file.exists() else None,
283
+ "code_files_scanned": len(code_files),
284
+ "stl_files_found": len(stl_files),
285
+ "include_repair": run_repair,
286
+ "include_slice": run_slice,
287
+ "params": None,
288
+ "mesh": [],
289
+ "repair": [],
290
+ "slice": [],
291
+ }
292
+ failures = 0
293
+
294
+ # 1) Param linter
295
+ if params_file.exists():
296
+ p_report = lint_params(params_file, code_files)
297
+ results["params"] = _make_json_safe(asdict(p_report))
298
+ results["params"]["passed"] = p_report.passed
299
+ if not p_report.passed:
300
+ failures += 1
301
+
302
+ # 2) Mesh integrity
303
+ for stl in stl_files:
304
+ m_report = check_mesh(
305
+ stl,
306
+ max_disconnected_shells=args.max_shells,
307
+ min_volume_mm3=args.min_volume,
308
+ )
309
+ entry = _make_json_safe(asdict(m_report))
310
+ entry["passed"] = m_report.passed
311
+ results["mesh"].append(entry)
312
+ if not m_report.passed:
313
+ failures += 1
314
+
315
+ # 3) Mesh repair (opt-in)
316
+ if run_repair:
317
+ for stl in stl_files:
318
+ r_report = check_and_repair(stl)
319
+ entry = _make_json_safe(asdict(r_report))
320
+ entry["passed"] = r_report.passed
321
+ results["repair"].append(entry)
322
+ if not r_report.passed:
323
+ failures += 1
324
+
325
+ # 4) Slicer simulation (opt-in — requires --filament/--process/--machine)
326
+ if run_slice:
327
+ for stl in stl_files:
328
+ s_report = slice_stl(
329
+ stl,
330
+ slicer=args.slicer,
331
+ filament_profile=Path(args.filament),
332
+ process_profile=Path(args.process),
333
+ machine_profile=Path(args.machine),
334
+ output_dir=Path(args.output_dir),
335
+ timeout_seconds=args.timeout,
336
+ max_print_time_hours=args.max_hours,
337
+ max_filament_grams=args.max_grams,
338
+ min_volumetric_speed=args.min_speed,
339
+ )
340
+ entry = _make_json_safe(asdict(s_report))
341
+ entry["passed"] = s_report.passed
342
+ results["slice"].append(entry)
343
+ if not s_report.passed:
344
+ failures += 1
345
+
346
+ results["failures"] = failures
347
+ results["passed"] = failures == 0
348
+
349
+ if args.json:
350
+ print(json.dumps(results, indent=2))
351
+ else:
352
+ print("=" * 60)
353
+ print(f"verify-print all — {root}")
354
+ print(f" params: {'found' if params_file.exists() else 'not found'} "
355
+ f"({len(code_files)} code files)")
356
+ print(f" STLs: {len(stl_files)}")
357
+ print(f" repair: {'on' if run_repair else 'off'} "
358
+ f"slice: {'on' if run_slice else 'off'}")
359
+ print("=" * 60)
360
+
361
+ if results["params"]:
362
+ print("\n[params]")
363
+ print("-" * 60)
364
+ p_report = lint_params(params_file, code_files)
365
+ print(p_report.format())
366
+
367
+ for entry in results["mesh"]:
368
+ print(f"\n[mesh] {entry['file']}")
369
+ print("-" * 60)
370
+ print(check_mesh(
371
+ Path(entry["file"]),
372
+ max_disconnected_shells=args.max_shells,
373
+ min_volume_mm3=args.min_volume,
374
+ ).format())
375
+
376
+ if run_repair:
377
+ for entry in results["repair"]:
378
+ print(f"\n[repair] {entry['file']}")
379
+ print("-" * 60)
380
+ print(check_and_repair(Path(entry["file"])).format())
381
+
382
+ if run_slice:
383
+ for entry in results["slice"]:
384
+ print(f"\n[slice] {entry['file']}")
385
+ print("-" * 60)
386
+ # Reconstruct human format from JSON entry
387
+ _print_slice_entry(entry)
388
+
389
+ print("\n" + "=" * 60)
390
+ if failures == 0:
391
+ print("ALL CHECKS PASSED")
392
+ else:
393
+ print(f"FAILED — {failures} check(s) had issues")
394
+
395
+ return 0 if failures == 0 else 1
396
+
397
+
398
+ def _print_slice_entry(entry: dict) -> None:
399
+ """Pretty-print a slice JSON entry — used by _cmd_all human mode."""
400
+ print(f" slicer: {entry.get('slicer')}")
401
+ print(f" invocation: {'success' if entry.get('success') else 'FAILED'}")
402
+ if entry.get("print_time_human"):
403
+ print(f" estimated time: {entry['print_time_human']} ({entry.get('print_time_seconds')}s)")
404
+ if entry.get("filament_grams") is not None:
405
+ print(f" filament: {entry['filament_grams']:.1f} g")
406
+ if entry.get("layer_count") is not None:
407
+ print(f" layers: {entry['layer_count']}")
408
+ if entry.get("max_volumetric_speed") is not None:
409
+ print(f" max volumetric: {entry['max_volumetric_speed']:.2f} mm^3/s")
410
+ if entry.get("bbox_mm"):
411
+ bx, by, bz = entry["bbox_mm"]
412
+ print(f" bbox (mm): {bx:.2f} x {by:.2f} x {bz:.2f}")
413
+ for w in entry.get("warnings", []):
414
+ print(f" warning: {w}")
415
+ for i in entry.get("issues", []):
416
+ print(f" ISSUE: {i}")
417
+
418
+
419
+ def main(argv: list[str] | None = None) -> int:
420
+ parser = argparse.ArgumentParser(
421
+ prog="verify-print",
422
+ description="Pre-print STL + CAD verification for FDM 3D printing",
423
+ )
424
+
425
+ # Parent parser supplies --json to every subcommand
426
+ parent = argparse.ArgumentParser(add_help=False)
427
+ parent.add_argument(
428
+ "--json",
429
+ action="store_true",
430
+ help="emit machine-readable JSON instead of human format",
431
+ )
432
+
433
+ subparsers = parser.add_subparsers(dest="command", required=True)
434
+
435
+ p_mesh = subparsers.add_parser("mesh", parents=[parent], help="Mesh integrity (trimesh)")
436
+ p_mesh.add_argument("stl")
437
+ p_mesh.add_argument("--max-shells", type=int, default=1)
438
+ p_mesh.add_argument("--min-volume", type=float, default=1.0)
439
+ p_mesh.set_defaults(func=_cmd_mesh)
440
+
441
+ p_params = subparsers.add_parser("params", parents=[parent], help="Param hygiene (AST)")
442
+ p_params.add_argument("params_file")
443
+ p_params.add_argument("code_files", nargs="+")
444
+ p_params.set_defaults(func=_cmd_params)
445
+
446
+ p_thickness = subparsers.add_parser(
447
+ "thickness",
448
+ parents=[parent],
449
+ help="Wall thickness sampling via inward ray-casting",
450
+ )
451
+ p_thickness.add_argument("stl")
452
+ p_thickness.add_argument("--threshold", type=float, default=0.8,
453
+ help="min wall thickness (default 0.8mm for 0.4mm nozzle)")
454
+ p_thickness.add_argument("--samples", type=int, default=1000)
455
+ p_thickness.add_argument("--seed", type=int, default=42)
456
+ p_thickness.set_defaults(func=_cmd_thickness)
457
+
458
+ p_orient = subparsers.add_parser(
459
+ "orientation",
460
+ parents=[parent],
461
+ help="Check that the largest hole faces an expected direction",
462
+ )
463
+ p_orient.add_argument("stl")
464
+ p_orient.add_argument("--normal", required=True,
465
+ help="expected face normal as 'x,y,z' (e.g. '0,-1,0' for -Y back)")
466
+ p_orient.add_argument("--feature", default="largest_hole")
467
+ p_orient.add_argument("--min-area", type=float, default=100.0,
468
+ help="min hole area mm^2 to consider (default 100)")
469
+ p_orient.add_argument("--alignment", type=float, default=0.7,
470
+ help="min cosine alignment (default 0.7, ~45 deg tolerance)")
471
+ p_orient.set_defaults(func=_cmd_orientation)
472
+
473
+ p_repair = subparsers.add_parser("repair", parents=[parent], help="PyMeshLab deep checks / repair")
474
+ p_repair.add_argument("stl")
475
+ p_repair.add_argument("--repair", action="store_true")
476
+ p_repair.add_argument("--output")
477
+ p_repair.set_defaults(func=_cmd_repair)
478
+
479
+ p_info = subparsers.add_parser(
480
+ "info",
481
+ parents=[parent],
482
+ help="Fast STL inspection: bbox, volume, fits-build-volume, mass estimate (no slicer)",
483
+ )
484
+ p_info.add_argument("stl")
485
+ p_info.add_argument("--build-volume",
486
+ help="build volume as 'W,D,H' (Bambu P1S = '256,256,256')")
487
+ p_info.add_argument("--density", type=float, default=None,
488
+ help="material density g/cm^3 (PETG=1.27, PLA=1.24, ABS=1.04)")
489
+ p_info.set_defaults(func=_cmd_info)
490
+
491
+ p_compare = subparsers.add_parser(
492
+ "compare",
493
+ parents=[parent],
494
+ help="Diff two `verify-print all --json` outputs (iteration regression check)",
495
+ )
496
+ p_compare.add_argument("before", help="path to earlier --json report")
497
+ p_compare.add_argument("after", help="path to current --json report")
498
+ p_compare.set_defaults(func=_cmd_compare)
499
+
500
+ p_slice = subparsers.add_parser("slice", parents=[parent], help="Headless slice with bottleneck gate (multi-STL)")
501
+ p_slice.add_argument("stls", nargs="+", help="STL file(s) or director(y/ies) containing *.stl")
502
+ p_slice.add_argument("--slicer", choices=["orca", "bambu"], default="bambu")
503
+ p_slice.add_argument("--filament", required=True)
504
+ p_slice.add_argument("--process", required=True)
505
+ p_slice.add_argument("--machine", required=True)
506
+ p_slice.add_argument("--output-dir", default="./verify_print_slicedata")
507
+ p_slice.add_argument("--timeout", type=int, default=900)
508
+ p_slice.add_argument("--max-hours", type=float, default=None)
509
+ p_slice.add_argument("--max-grams", type=float, default=None)
510
+ p_slice.add_argument("--min-speed", type=float, default=None)
511
+ p_slice.set_defaults(func=_cmd_slice)
512
+
513
+ p_project = subparsers.add_parser("project", parents=[parent],
514
+ help="Pre-print gate on a Bambu Studio / Orca 3MF project (time-multiplier settings)")
515
+ p_project.add_argument("threemf", help="project .3mf (unsliced is fine)")
516
+ p_project.add_argument("--slice", action="store_true",
517
+ help="also slice every plate with Bambu Studio CLI for time + feature breakdown")
518
+ p_project.add_argument("--printer", default=None,
519
+ help='expected printer preset, e.g. "Bambu Lab P1S 0.4 nozzle" (R8)')
520
+ p_project.add_argument("--max-hours", type=float, default=None, help="FAIL if any plate exceeds (needs --slice)")
521
+ p_project.add_argument("--timeout", type=int, default=900)
522
+ p_project.set_defaults(func=_cmd_project)
523
+
524
+ p_all = subparsers.add_parser("all", parents=[parent], help="Run all checks on a directory")
525
+ p_all.add_argument("directory")
526
+ p_all.add_argument("--max-shells", type=int, default=1)
527
+ p_all.add_argument("--min-volume", type=float, default=1.0)
528
+ p_all.add_argument("--include-repair", action="store_true",
529
+ help="also run PyMeshLab repair pass (requires [mesh-repair])")
530
+ # Slicer args — optional. If filament/process/machine all provided, run slice on every STL.
531
+ p_all.add_argument("--slicer", choices=["orca", "bambu"], default="bambu")
532
+ p_all.add_argument("--filament", default=None)
533
+ p_all.add_argument("--process", default=None)
534
+ p_all.add_argument("--machine", default=None)
535
+ p_all.add_argument("--output-dir", default="./verify_print_slicedata")
536
+ p_all.add_argument("--timeout", type=int, default=900)
537
+ p_all.add_argument("--max-hours", type=float, default=None)
538
+ p_all.add_argument("--max-grams", type=float, default=None)
539
+ p_all.add_argument("--min-speed", type=float, default=None)
540
+ p_all.set_defaults(func=_cmd_all)
541
+
542
+ args = parser.parse_args(argv)
543
+ return args.func(args)
544
+
545
+
546
+ if __name__ == "__main__":
547
+ sys.exit(main())