Skip to content

Commit

Permalink
fix code_to_adapted_unit
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Dec 15, 2023
1 parent 9a2f7d4 commit 4b4006a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/litgen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations
from litgen.options import LitgenOptions, TemplateClassOptions, TemplateFunctionsOptions

from litgen.code_to_adapted_unit import code_to_adapted_unit
from litgen.code_to_adapted_unit import code_to_adapted_unit, code_to_adapted_unit_in_context
from litgen.internal.cpp_to_python import (
standard_type_replacements,
standard_value_replacements,
Expand All @@ -25,6 +25,7 @@
"TemplateFunctionsOptions",
"generate_code",
"code_to_adapted_unit",
"code_to_adapted_unit_in_context",
"write_generated_code_for_file",
"write_generated_code_for_files",
# When it is needed to have different options per c++ header file
Expand Down
11 changes: 10 additions & 1 deletion packages/litgen/code_to_adapted_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
LitgenContext,
)

from litgen.options import LitgenOptions

def code_to_adapted_unit(

def code_to_adapted_unit_in_context(
lg_context: LitgenContext,
code: Optional[str] = None,
filename: Optional[str] = None,
Expand All @@ -19,3 +21,10 @@ def code_to_adapted_unit(
adapted_unit = AdaptedUnit(lg_context, cpp_unit)

return adapted_unit


def code_to_adapted_unit(
options: LitgenOptions, code: Optional[str] = None, filename: Optional[str] = None
) -> AdaptedUnit:
lg_context = LitgenContext(options)
return code_to_adapted_unit_in_context(lg_context, code, filename)
8 changes: 4 additions & 4 deletions packages/litgen/litgen_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from srcmlcpp.internal.code_to_srcml import _SRCML_CALLER

from litgen import LitgenOptions
from litgen.code_to_adapted_unit import code_to_adapted_unit
from litgen.code_to_adapted_unit import code_to_adapted_unit_in_context
from litgen.internal import boxed_python_type, cpp_to_python
from litgen.internal.context.litgen_context import LitgenContext

Expand Down Expand Up @@ -130,9 +130,9 @@ def _boxed_types_cpp_code(self) -> CppCode:

def process_cpp_code(self, code: str, filename: str) -> None:
if len(filename) > 0:
adapted_unit = code_to_adapted_unit(self.lg_context, code, filename)
adapted_unit = code_to_adapted_unit_in_context(self.lg_context, code, filename)
else:
adapted_unit = code_to_adapted_unit(self.lg_context, code)
adapted_unit = code_to_adapted_unit_in_context(self.lg_context, code)
stub_code = adapted_unit.str_stub()
pydef_code = adapted_unit.str_pydef()
self.lg_context.clear_namespaces_code_tree()
Expand All @@ -150,7 +150,7 @@ def _boxed_types_generated_code(self) -> _GeneratedCode | None:
standalone_options.cpp_indent_size = self.options().cpp_indent_size
standalone_options.cpp_indent_with_tabs = self.options().cpp_indent_with_tabs

adapted_unit = code_to_adapted_unit(LitgenContext(standalone_options), boxed_types_cpp_code)
adapted_unit = code_to_adapted_unit_in_context(LitgenContext(standalone_options), boxed_types_cpp_code)

stub_code = adapted_unit.str_stub()
pydef_code = adapted_unit.str_pydef()
Expand Down

0 comments on commit 4b4006a

Please sign in to comment.