Skip to content

Commit db6f126

Browse files
committed
bindings: moved to seperate dir, added first unit test
1 parent 3d74d5f commit db6f126

21 files changed

+144
-19
lines changed

.devcontainer/arch-linux/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RUN pacman -Syu --noconfirm \
1717
boost crypto++ xorg \
1818
ttf-ubuntu-font-family \
1919
ninja \
20-
&& pip install --break-system-packages conan \
20+
&& pip install --break-system-packages conan pytest \
2121
&& paccache -r -k 0
2222

2323
###############

.devcontainer/debian/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
88
libopenscenegraph-dev libproj-dev libqt5opengl5-dev libxerces-c-dev \
99
ninja-build qtbase5-dev sudo \
1010
&& apt-get clean && rm -rf /var/lib/apt/lists/*
11-
RUN pip install --break-system-packages conan
11+
RUN pip install --break-system-packages conan pytest
1212

1313
###############
1414
# Build stage #

src/artery/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,7 @@ if(WITH_STORYBOARD)
163163
endif()
164164

165165
if(WITH_PYTHON_BINDINGS)
166-
add_artery_feature(python_bindings)
167-
target_sources(python_bindings PRIVATE
168-
application/PythonItsG5Service.cc
169-
application/bindings/VanetzaNetBindings.cc
170-
)
171-
target_link_libraries(python_bindings PRIVATE pybind11)
172-
target_compile_definitions(python_bindings PRIVATE
173-
$<$<CONFIG:Debug>:PREFER_LOCAL_PYTHON_STUBS>
174-
)
166+
add_subdirectory(bindings)
175167
endif()
176168

177169
if(WITH_TRANSFUSION)

src/artery/bindings/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
4+
5+
add_artery_feature(python_bindings)
6+
7+
target_sources(python_bindings PRIVATE
8+
PythonItsG5Service.cc
9+
VanetzaNetBindings.cc
10+
)
11+
12+
target_link_libraries(python_bindings PRIVATE pybind11)
13+
14+
target_compile_definitions(python_bindings PRIVATE
15+
$<$<CONFIG:Debug>:PREFER_LOCAL_PYTHON_STUBS>
16+
)
17+
18+
add_custom_target(test-bindings
19+
COMMAND ${Python3_EXECUTABLE} -m pytest -v
20+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
21+
COMMENT "python bindings: tests"
22+
)
23+
24+
add_test(NAME test_python_bindings
25+
COMMAND ${Python3_EXECUTABLE} -m pytest -v tests
26+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
27+
)

src/artery/application/PythonItsG5Service.cc renamed to src/artery/bindings/PythonItsG5Service.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#include "artery/application/PythonItsG5Service.h"
1+
#include "artery/bindings/PythonItsG5Service.h"
22

3-
#include "artery/application/ItsG5BaseService.h"
43
#include "omnetpp/cexception.h"
54
#include "pybind11/detail/common.h"
65
#include "pybind11/embed.h"
@@ -9,7 +8,6 @@
98

109
#include <omnetpp/cconfiguration.h>
1110

12-
#include <cstddef>
1311
#include <filesystem>
1412
#include <memory>
1513

@@ -109,7 +107,7 @@ void PythonItsG5Service::initializeModules()
109107

110108
#ifdef PREFER_LOCAL_PYTHON_STUBS
111109
using path = std::filesystem::path;
112-
auto localStubsBaseDir = path(__FILE__).parent_path() / "python";
110+
auto localStubsBaseDir = path(__FILE__) / "python";
113111
extendPythonPath(localStubsBaseDir.string());
114112
#endif
115113
// Otherwise python stubs must be provided by system.

src/artery/application/PythonItsG5Service.ned renamed to src/artery/bindings/PythonItsG5Service.ned

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
package artery.application;
1+
package artery.bindings;
2+
3+
import artery.application.ItsG5Service;
24

35
simple PythonItsG5Service like ItsG5Service {
46
parameters:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from .byte_buffer_convertible import ByteBufferConvertible
2+
from .chunk_packet import ChunkPacket
3+
from .cohesive_packet import CohesivePacket
4+
5+
from .osi_layer import (
6+
OsiLayer,
7+
OsiLayers,
8+
osi_layer_iterable,
9+
osi_layer_list,
10+
max_osi_layer,
11+
min_osi_layer,
12+
num_osi_layers
13+
)
14+
15+
16+
__all__ = [
17+
ByteBufferConvertible,
18+
ChunkPacket,
19+
CohesivePacket,
20+
OsiLayer,
21+
OsiLayers,
22+
osi_layer_iterable,
23+
osi_layer_list,
24+
max_osi_layer,
25+
min_osi_layer,
26+
num_osi_layers
27+
] # type: ignore

0 commit comments

Comments
 (0)