Skip to content

Commit

Permalink
#12 Add PackageWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
kwabenantim committed Sep 22, 2024
1 parent 5fa3f0b commit 1567eac
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
19 changes: 8 additions & 11 deletions cppwg/generators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Contains the main interface for generating Python wrappers."""
"""The main interface for generating Python wrappers."""

import logging
import os
Expand All @@ -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:
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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()
42 changes: 42 additions & 0 deletions cppwg/writers/package_writer.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 1567eac

Please sign in to comment.