diff --git a/cppwg/generators.py b/cppwg/generators.py index b32c999..46ceb29 100644 --- a/cppwg/generators.py +++ b/cppwg/generators.py @@ -1,4 +1,4 @@ -"""Contains the main interface for generating Python wrappers.""" +"""The main interface for generating Python wrappers.""" import logging import os @@ -20,7 +20,7 @@ CPPWG_HEADER_COLLECTION_FILENAME, ) from cppwg.writers.header_collection_writer import CppHeaderCollectionWriter -from cppwg.writers.module_writer import CppModuleWrapperWriter +from cppwg.writers.package_writer import CppPackageWrapperWriter class CppWrapperGenerator: @@ -240,15 +240,12 @@ def write_header_collection(self) -> None: def write_wrappers(self) -> None: """ - Write all the wrappers required for the package. + Write the wrapper code for the package. """ - for module_info in self.package_info.module_info_collection: - module_writer = CppModuleWrapperWriter( - module_info, - wrapper_templates.template_collection, - self.wrapper_root, - ) - module_writer.write() + package_writer = CppPackageWrapperWriter( + self.package_info, wrapper_templates.template_collection, self.wrapper_root + ) + package_writer.write() def generate_wrappers(self) -> None: """ @@ -275,5 +272,5 @@ def generate_wrappers(self) -> None: # Log list of unknown classes in the source root self.log_unknown_classes() - # Write all the wrappers required + # Write the wrapper code for the package self.write_wrappers() diff --git a/cppwg/writers/package_writer.py b/cppwg/writers/package_writer.py new file mode 100644 index 0000000..b311b43 --- /dev/null +++ b/cppwg/writers/package_writer.py @@ -0,0 +1,42 @@ +"""Wrapper code writer for the package.""" + +from typing import Dict + +from cppwg.writers.module_writer import CppModuleWrapperWriter + + +class CppPackageWrapperWriter: + """ + Class to generates Python bindings for all modules in the package. + + Attributes + ---------- + package_info : PackageInfo + The package information to generate Python bindings for + wrapper_templates : Dict[str, str] + String templates with placeholders for generating wrapper code + wrapper_root : str + The output directory for the generated wrapper code + """ + + def __init__( + self, + package_info: "PackageInfo", # noqa: F821 + wrapper_templates: Dict[str, str], + wrapper_root: str, + ): + self.package_info = package_info + self.wrapper_templates = wrapper_templates + self.wrapper_root = wrapper_root + + def write(self) -> None: + """ + Write all the wrappers required for the package. + """ + for module_info in self.package_info.module_info_collection: + module_writer = CppModuleWrapperWriter( + module_info, + self.wrapper_templates, + self.wrapper_root, + ) + module_writer.write()