Skip to content

Commit

Permalink
validate_bindings_compilation: add param enable_hack_code
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Nov 7, 2024
1 parent ba8ff59 commit 9853f71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/litgen/internal/validate_bindings_compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def validate_bindings_compilation(
remove_build_dir_on_success: bool = True,
remove_build_dir_on_failure: bool = False,
show_logs: bool = False,
enable_hack_code: bool = False,
) -> bool:
"""
Validates that the cpp code can be compiled into bindings and that the generated Python bindings work as expected.
Expand Down Expand Up @@ -145,9 +146,10 @@ def validate_bindings_compilation(
if work_dir is None:
work_dir = tempfile.mkdtemp()
else:
if os.path.exists(work_dir):
shutil.rmtree(work_dir)
os.mkdir(work_dir)
if not enable_hack_code:
if os.path.exists(work_dir):
shutil.rmtree(work_dir)
os.mkdir(work_dir)
build_dir = os.path.join(work_dir, "build")
os.makedirs(build_dir, exist_ok=True)

Expand All @@ -156,8 +158,9 @@ def validate_bindings_compilation(
cmake_lists_path = os.path.join(work_dir, "CMakeLists.txt")

# Write the full code to code.cpp
with open(code_cpp_path, "w") as f:
f.write(full_code)
if not enable_hack_code:
with open(code_cpp_path, "w") as f:
f.write(full_code)

# Write the CMake code to CMakeLists.txt
with open(cmake_lists_path, "w") as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ def test_validate_bindings_compilation() -> None:
python_test_code = """
import validate_bindings_compilation
import numpy as np
import pytest
def test_validate_bindings_compilation() -> None:
x = np.array((1.0, 2.0, 3.0))
c = validate_bindings_compilation.templated_mul_inside_buffer(x, 3.0)
assert (x == np.array((3.0, 6.0, 9.0))).all()
# Test that non contiguous arrays are refused
x = np.array((1.0, 2.0, 3.0, 4.0, 5.0, 6.0))[1::2]
with pytest.raises(RuntimeError):
c = validate_bindings_compilation.templated_mul_inside_buffer(x, 3.0)
"""

# for bind_type in litgen.BindLibraryType:
Expand All @@ -39,6 +45,7 @@ def test_validate_bindings_compilation() -> None:
python_test_code=python_test_code,
show_logs=True,
python_module_name="validate_bindings_compilation",
# work_dir="/Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/litgen/src/litgen/tests/internal/ppp"
# work_dir="/Users/pascal/dvp/OpenSource/ImGuiWork/_Bundle/litgen/src/litgen/tests/internal/ppp",
# enable_hack_code=True,
)
assert success

0 comments on commit 9853f71

Please sign in to comment.