Skip to content

Commit

Permalink
split helpers module in tools.codegenerator subdirectory package …
Browse files Browse the repository at this point in the history
…part 1 (#548)

* add `namespaces` to `codegenerator` package
- split `helpers` into `helpers_` and `namespaces`
- import stuffs from `namespaces` into `codegenerator`

* add `packing` to `codegenerator` package
- split `helpers_` into `_helpers` and `packing`
- import stuffs from `namespaces` into `codegenerator`

* add `modulenamer` to `codegenerator` package
- split `_helpers` into `helpers_` and `modulenamer`
- import stuffs from `modulenamer` into `codegenerator`
  • Loading branch information
junkmd authored May 22, 2024
1 parent 825349d commit 9a83390
Show file tree
Hide file tree
Showing 6 changed files with 2,027 additions and 15 deletions.
2 changes: 1 addition & 1 deletion comtypes/tools/codegenerator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from comtypes.tools.codegenerator.helpers import ( # noqa
from comtypes.tools.codegenerator.modulenamer import ( # noqa
name_friendly_module,
name_wrapper_module,
)
Expand Down
24 changes: 10 additions & 14 deletions comtypes/tools/codegenerator/codegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@
import comtypes
from comtypes import typeinfo
from comtypes.tools import tlbparser, typedesc
from comtypes.tools.codegenerator.helpers import (
from comtypes.tools.codegenerator import namespaces
from comtypes.tools.codegenerator import packing
from comtypes.tools.codegenerator.modulenamer import name_wrapper_module
from comtypes.tools.codegenerator.helpers_ import (
get_real_type,
ASSUME_STRINGS,
calc_packing,
PackingError,
dont_assert_size,
name_wrapper_module,
ComMethodGenerator,
DispMethodGenerator,
DispPropertyGenerator,
TypeNamer,
ImportedNamespaces,
DeclaredNamespaces,
EnumerationNamespaces,
)
from comtypes.tools.codegenerator import typeannotator

Expand All @@ -51,9 +47,9 @@
class CodeGenerator(object):
def __init__(self, known_symbols=None, known_interfaces=None) -> None:
self.stream = io.StringIO()
self.imports = ImportedNamespaces()
self.declarations = DeclaredNamespaces()
self.enums = EnumerationNamespaces()
self.imports = namespaces.ImportedNamespaces()
self.declarations = namespaces.DeclaredNamespaces()
self.enums = namespaces.EnumerationNamespaces()
self.unnamed_enum_members: List[Tuple[str, int]] = []
self._to_type_name = TypeNamer()
self.known_symbols = known_symbols or {}
Expand Down Expand Up @@ -464,11 +460,11 @@ def StructureBody(self, body: typedesc.StructureBody) -> None:
# on COM interfaces:
if not methods:
try:
pack = calc_packing(body.struct, fields)
pack = packing.calc_packing(body.struct, fields)
if pack is not None:
self.last_item_class = False
print("%s._pack_ = %s" % (body.struct.name, pack), file=self.stream)
except PackingError as details:
except packing.PackingError as details:
# if packing fails, write a warning comment to the output.
import warnings

Expand Down Expand Up @@ -525,7 +521,7 @@ def StructureBody(self, body: typedesc.StructureBody) -> None:
"# The size and alignment check for %s is skipped."
)
print(msg % body.struct.name, file=self.stream)
elif body.struct.name not in dont_assert_size:
elif body.struct.name not in packing.dont_assert_size:
print(file=self.stream)
size = body.struct.size // 8
print(
Expand Down
File renamed without changes.
Loading

0 comments on commit 9a83390

Please sign in to comment.