Skip to content

feat: preserve OpenSCAD Customizer comments for 3D printing site uploads#6

Merged
tbjers merged 2 commits into
mainfrom
feat/openscad-customizer-support
Jun 5, 2026
Merged

feat: preserve OpenSCAD Customizer comments for 3D printing site uploads#6
tbjers merged 2 commits into
mainfrom
feat/openscad-customizer-support

Conversation

@tbjers

@tbjers tbjers commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Why this exists: 3D printing sites (Printables, Thingiverse, MakerWorld) support parametric OpenSCAD models via the Customizer, but only accept a single .scad file. Creators using BOSL2 or similar libraries need everything inlined. This PR makes the packed output work seamlessly with the Customizer.
  • Comment preservation: Entry file is pre-processed to strip // comments inside ()/[] expression contexts (which trip the parser), then re-parsed with include_comments=True so statement-level magic annotations (// [min:max], /* [Section] */) survive into the output. Library files remain comment-free.
  • Inline annotation placement: var = val; // [min:max] is emitted on one line (as Customizer requires). The parser splits these into separate nodes; _merge_inline_comments post-processes the output string to stitch them back together using source position data.
  • Output ordering: Parametric assignments and comments are placed before tree-shaken library definitions, and geometry calls come last. OpenSCAD's declarative semantics mean this reordering has no effect on rendering, but the Customizer needs variables near the top of the file to expose them in its UI.
  • CLI flag: --preserve-comments/--no-preserve-comments (default: on). Falls back gracefully with a stderr warning if the pre-processed source still can't be parsed with comments.
  • README: Added ## Why? section explaining the 3D printing site motivation.

Test plan

  • Run uv run pytest — 138 tests, 99% branch coverage, all pass
  • Pack a real parametric model (uv run openscad-packer pack model.scad -o packed.scad) and open in OpenSCAD — Customizer should show all parameter sections and sliders/dropdowns
  • Verify --no-preserve-comments strips comments cleanly
  • Verify models with inline expression comments (e.g. cube([10, // width\n 20])) pack without warnings

🤖 Generated with Claude Code

… printing sites

- Add `--preserve-comments/--no-preserve-comments` CLI flag (default: on)
- Pre-process entry file with `_strip_expression_comments` to remove `//` inside
  `()`/`[]` before parsing with `include_comments=True`, so statement-level magic
  comments (`// [min:max]`, `/* [Section] */`) survive without tripping the parser
- Merge inline CommentLine annotations back onto the same output line as their
  assignment via `_merge_inline_comments` (Customizer requires `var = val; // [x]`
  on one line)
- Reorder packed output: parametric assignments/comments first, library definitions
  second, geometry calls last — so Customizer finds variables at the top of the file
- Add `## Why?` section to README explaining the 3D printing site use case
- 138 tests, 99% branch coverage

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.03846% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.59%. Comparing base (c28e402) to head (873a436).

Files with missing lines Patch % Lines
openscad_packer/packer.py 99.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main       #6      +/-   ##
===========================================
- Coverage   100.00%   99.59%   -0.41%     
===========================================
  Files            6        6              
  Lines          146      244      +98     
  Branches        29       53      +24     
===========================================
+ Hits           146      243      +97     
- Partials         0        1       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread tests/test_packer.py Fixed
Comment thread tests/test_packer.py Fixed
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@tbjers tbjers merged commit 3d6c0aa into main Jun 5, 2026
7 of 9 checks passed
@tbjers tbjers deleted the feat/openscad-customizer-support branch June 5, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant