Auto include template args#103
Merged
Merged
Conversation
auto_includes previously resolved headers only for project types named in a class's wrapped method/constructor signatures. A type used solely as a template argument of an instantiation - e.g. the CELL_CYCLE_MODEL in pychaste's CellsGenerator<CELL_CYCLE_MODEL, DIM> - never appears in a signature, so its header still had to be listed by hand under source_includes. Extend resolve_auto_includes() to also resolve the project types named in class_info.template_arg_lists (the instantiation arguments), reusing the existing type->header map. Numeric args (dimensions) and library types resolve to nothing, and the class's own header is dropped as before. Folded into the existing auto_includes flag - no new config. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a header-only CellFactory<CELL_TYPE, DIM> to the cells example that mirrors pychaste's CellsGenerator: CELL_TYPE is used only inside CreateCell() and never appears in the wrapped interface, so cppwg sees it only as a template argument. Wrapped via template_substitutions with [[Cell, 2], [Cell, 3]]; the package-level auto_includes resolves Cell.hpp from those arguments, so the generated wrapper (which odr-uses CreateCell and needs the complete Cell) compiles. Includes the regenerated dynamic/wrappers (CellFactory.cppwg.* auto-includes Cell.hpp; main + header collection register the two instantiations), the CellFactory alias in pycells/__init__.py, and a test asserting the instantiations import and work. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Extends cppwg’s auto_includes dependency resolution to also consider project types that appear only in a class’s template instantiation arguments (not in wrapped method/constructor signatures), addressing cases like Foo<Bar, DIM> where Bar.hpp is still required for the generated wrapper to compile.
Changes:
- Update
PackageInfo.resolve_auto_includes()to resolve headers for project-type template arguments found inclass_info.template_arg_lists. - Add unit test coverage ensuring template-argument-only project types are auto-included while numeric args and the class’s own header are ignored.
- Expand the
examples/cellspackage to include aCellFactory<Cell, DIM>case that depends on template-argument auto-includes, with updated wrappers and Python exports.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
cppwg/info/package_info.py |
Implements template-argument scanning in resolve_auto_includes() to auto-include headers for project types referenced only via instantiation args. |
tests/test_package_info.py |
Adds a unit test asserting template-argument project types resolve to their headers and numeric args resolve to nothing. |
README.md |
Documents that auto_includes now scans both wrapped signatures and template instantiation arguments. |
examples/cells/src/cpp/cell/CellFactory.hpp |
Introduces a minimal header-only templated factory to exercise the new auto-include behavior in an example package. |
examples/cells/dynamic/config.yaml |
Wrap configuration for CellFactory with template substitutions used by the example. |
examples/cells/dynamic/wrappers/wrapper_header_collection.cppwg.hpp |
Includes and instantiates CellFactory<Cell, DIM> in the example wrapper header collection. |
examples/cells/dynamic/wrappers/all/CellFactory.cppwg.hpp |
Adds the generated wrapper declarations for the new example template instantiations. |
examples/cells/dynamic/wrappers/all/CellFactory.cppwg.cpp |
Adds the generated pybind11 bindings for CellFactory<Cell, 2> and CellFactory<Cell, 3>. |
examples/cells/dynamic/wrappers/all/_pycells_all.main.cppwg.cpp |
Registers the new CellFactory bindings with the example module. |
examples/cells/src/py/pycells/__init__.py |
Exposes CellFactory via TemplateClassDict so CellFactory[Cell, DIM] works in Python. |
examples/cells/tests/test_cells.py |
Adds an integration-style test that imports and uses CellFactory[Cell, DIM], validating wrapper compilation and runtime behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
kwabenantim
marked this pull request as ready for review
July 23, 2026 20:02
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.
Extends #97 by including args in template signatures that never appear in method signatures.