auto include headers#98
Merged
Merged
Conversation
Add an opt-in auto_includes flag (tri-state, inherits package/module/class, off by default). When enabled for a class, cppwg scans its wrapped method/constructor signatures and adds the header of every project type they reference that the class's own header does not already provide - the MeshFactory<MESH> returning a forward-declared PottsMesh pattern - so those no longer need hand-written source_includes entries. Factor the exclusion-aware member walk out of prune_uninstantiated_dependencies into a shared _iter_wrapped_arg_return_types() generator, used by both pruning and auto-include resolution so they cannot diverge from the writers. Resolve the type->header map by scanning the project's source headers (definition sites), not the parsed namespace - a templated class's instantiation decl reports its location as the generated header collection, not its defining header. Library types and ambiguous names are left for manual source_includes; the option is a no-op with common_include_file. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace MeshFactory's hand-written source_includes: [PottsMesh.hpp] with auto_includes: True. cppwg resolves PottsMesh.hpp from the wrapped generateMesh signature, so the generated wrapper is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a README Tips entry describing auto_includes (what it resolves, that only project types are covered, and the common_include_file / custom_generator caveats), plus a commented reference block in the shapes package_info.yaml. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in auto_includes mechanism to automatically include project headers required by wrapped class signatures when common_include_file is disabled, addressing compilation failures like the one described in issue #97.
Changes:
- Introduces
auto_includes(tri-state, inheritable) and resolves per-classauto_include_headersby scanning wrapped method/constructor arg+return types and mapping referenced project types to defining headers. - Emits resolved headers in generated wrapper include blocks (deduped and ordered before the class’s own header).
- Adds unit tests plus documentation/examples describing the new configuration and behavior.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_package_info.py | Adds tests for header-resolution behavior, opt-in semantics, and ambiguous-type handling. |
| tests/test_package_info_parser.py | Verifies YAML parsing and defaulting for auto_includes. |
| tests/test_class_writer.py | Ensures wrapper include blocks emit and dedupe auto-includes correctly. |
| README.md | Documents auto_includes purpose, constraints, and configuration example. |
| examples/shapes/wrapper/package_info.yaml | Adds commented guidance for enabling auto_includes. |
| examples/cells/dynamic/config.yaml | Updates MeshFactory example to use auto_includes instead of manual source_includes. |
| cppwg/writers/class_writer.py | Emits class_info.auto_include_headers in non-common include mode. |
| cppwg/parsers/package_info_parser.py | Adds auto_includes to the base parsed config so it can be set at package/module/class levels. |
| cppwg/info/package_info.py | Implements type→header mapping and resolve_auto_includes(), plus shared wrapped-signature type iteration. |
| cppwg/info/class_info.py | Adds auto_include_headers storage on class info objects. |
| cppwg/info/base_info.py | Documents and wires auto_includes onto the info tree as a tri-state inheritable option. |
| cppwg/generators.py | Runs auto-include resolution after pruning/sorting so results match the final wrapped set. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Move auto_includes from MeshFactory to the package level so it inherits to every class, demonstrating the option's package-wide use. Beyond MeshFactory<PottsMesh> resolving PottsMesh.hpp, AbstractMesh's AddNode(Node<SPACE_DIM>) signature now resolves Node.hpp (regenerated wrapper). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
kwabenantim
marked this pull request as ready for review
July 21, 2026 13:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #97