Skip to content

Emit __all__ in shared-split _generated.py package files - #128

Merged
kwabenantim merged 3 commits into
developfrom
102-genpackage-all-exports
Aug 14, 2026
Merged

Emit __all__ in shared-split _generated.py package files#128
kwabenantim merged 3 commits into
developfrom
102-genpackage-all-exports

Conversation

@kwabenantim

Copy link
Copy Markdown
Member

Follow up to #102

The shared-module-split layout writes each subpackage's _generated.py with
an explicit `from <package>.<ext> import (...)` list re-exported by the
sibling __init__'s `from ._generated import *`. Without an __all__, static
analysis flagged the imported names as unused and the wildcard re-export as
namespace-polluting.

Emit a sorted __all__ of the re-exported names (imported extension names plus
the TemplateClass stub base names), mirroring the top-level flatten file which
already did this. The TemplateClass helper is no longer leaked. The
module-per-subpackage layout re-exports a whole extension via `import *`, whose
names are not all known here, so it emits no __all__ (unchanged).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.68%. Comparing base (ec97fb4) to head (11a9e32).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #128   +/-   ##
========================================
  Coverage    99.68%   99.68%           
========================================
  Files           31       31           
  Lines         2536     2563   +27     
  Branches       545      551    +6     
========================================
+ Hits          2528     2555   +27     
  Misses           7        7           
  Partials         1        1           
Flag Coverage Δ
cells 70.98% <0.00%> (-0.76%) ⬇️
shapes 71.16% <0.00%> (-0.76%) ⬇️
unit 93.20% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cppwg/genpackage.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

kwabenantim and others added 2 commits August 14, 2026 19:19
Switch the module-per-subpackage _generated.py from `from .<module> import *`
to an explicit name list, matching the shared-module split. This makes the
emitted __all__ exact for both layouts (so `from ._generated import *` in the
hand-written __init__.py is non-polluting and never leaks TemplateClass or
silently re-exports a hand-written extension binding), and lets the layout's
`exclude` list be honored here too: an excluded class/enum/free function is held
out of the imports and __all__ while staying registered in the extension.

Demonstrate exclude in the shapes example by hiding the abstract AbstractShape/
AbstractPolygon bases while their concrete subclass RegularPolygon stays exposed
and still inherits their bindings. Update the package-layer docs accordingly.

Regenerated the shapes/cells _generated.py; genpackage unit tests at 100%.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Both generators (module-per-subpackage and shared-module split) always pass an
exact export_names now, so the optional `= None` default and the "emit no
__all__" branch were production-dead — kept alive only by the render tests. Drop
the default (moving export_names ahead of the two defaulted params) and always
emit __all__; an empty module emits `__all__ = []`. Generated output is
unchanged (shapes/cells regenerate byte-identical).

Drop the now-obsolete omits-all test; genpackage unit tests stay at 100%.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Generates explicit package exports to prevent namespace pollution and configuration drift, following issue #102.

Changes:

  • Adds explicit extension imports and sorted __all__ declarations.
  • Supports exclude in module-per-subpackage layouts.
  • Updates examples, documentation, and tests.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cppwg/genpackage.py Generates explicit imports, exports, and exclusions.
tests/test_genpackage.py Tests imports, __all__, exclusions, and empty modules.
doc/python-packages.md Documents explicit exports and exclude.
examples/shapes/wrapper/package_layout.yaml Excludes abstract shape bases.
examples/shapes/src/py/tests/test_classes.py Verifies excluded bases and inherited behavior.
examples/shapes/src/py/pyshapes/primitives/_generated.py Curates primitive exports.
examples/shapes/src/py/pyshapes/math_funcs/_generated.py Curates function exports.
examples/shapes/src/py/pyshapes/geometry/_generated.py Curates geometry exports.
examples/shapes/src/py/pyshapes/composites/_generated.py Curates composite exports.
examples/cells/src/py/pycells/_generated.py Curates cell package exports.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kwabenantim
kwabenantim marked this pull request as ready for review August 14, 2026 18:52
@kwabenantim
kwabenantim merged commit ef46fbf into develop Aug 14, 2026
18 checks passed
@kwabenantim
kwabenantim deleted the 102-genpackage-all-exports branch August 14, 2026 18:54
@kwabenantim kwabenantim linked an issue Aug 14, 2026 that may be closed by this pull request
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.

Generate the Python package from the wrapper config

2 participants