-
Couldn't load subscription status.
- Fork 16
Add Python bindings for libvillas #884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 11 commits
40c9103
7302be2
3703c20
76ec913
24abdb7
640e815
862d498
c48be8f
73ce98f
168df21
e710de5
b1e9a2f
365f88b
6806d24
c5026a2
9216366
2d7628f
07cffec
d9d12de
a146ecb
22714fe
052f419
be2b770
5b887a4
279eb80
66e1f14
f73fc67
124a1f5
f023f4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,4 +5,5 @@ | |
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| add_subdirectory(opal-rt/rtlab-asyncip) | ||
| add_subdirectory(python-wrapper) | ||
|
||
| add_subdirectory(shmem) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Python-wrapper CMakeLists. | ||
| # | ||
| # Author: Kevin Vu te Laar <[email protected]> | ||
| # SPDX-FileCopyrightText: 2014-2025 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| cmake_minimum_required(VERSION 3.15...3.29) | ||
|
||
| project(villas-python-wrapper LANGUAGES CXX) | ||
|
|
||
| set(PYBIND11_FINDPYTHON ON) | ||
| find_package(pybind11 CONFIG) | ||
|
|
||
| if(pybind11_FOUND) | ||
| find_package(Python3 REQUIRED COMPONENTS Interpreter Development) | ||
|
|
||
| execute_process( | ||
| COMMAND "${Python3_EXECUTABLE}" -c "import sysconfig; print(sysconfig.get_path('stdlib') + '/lib-dynload')" | ||
| OUTPUT_VARIABLE PYTHON_LIB_DYNLOAD_DIR | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ) | ||
|
|
||
| message(STATUS "Found Python version: ${Python_VERSION}") | ||
| message(STATUS "Python major version: ${Python_VERSION_MAJOR}") | ||
| message(STATUS "Python minor version: ${Python_VERSION_MINOR}") | ||
| message(STATUS "Python .so install directory: ${PYTHON_LIB_DYNLOAD_DIR}") | ||
|
|
||
| pybind11_add_module(python-wrapper villas-python-wrapper.cpp) | ||
| set_target_properties(python-wrapper PROPERTIES OUTPUT_NAME villas_node) | ||
| target_link_libraries(python-wrapper PUBLIC villas) | ||
|
|
||
| install( | ||
| TARGETS python-wrapper | ||
| COMPONENT lib | ||
| RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
| LIBRARY DESTINATION ${PYTHON_LIB_DYNLOAD_DIR} | ||
| ) | ||
| else() | ||
| message(STATUS "pybind11 not found. Skipping Python wrapper build.") | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,246 @@ | ||||||||||||||||||||||||
| /* Python-wrapper. | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| /* Python-wrapper. | |
| /* Python bindings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in: 365f88b
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please separate headers in the following three sections:
- System headers
- Third-party library headers
- VILLASnode headers
| #include <jansson.h> | |
| #include <pybind11/pybind11.h> | |
| #include <uuid/uuid.h> | |
| #include <villas/node.hpp> | |
| #include <villas/sample.hpp> | |
| #include <jansson.h> | |
| #include <pybind11/pybind11.h> | |
| #include <uuid/uuid.h> | |
| #include <villas/node.hpp> | |
| #include <villas/sample.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in: 365f88b
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,10 @@ RUN apt-get update && \ | |
| liblua5.3-dev \ | ||
| libhiredis-dev \ | ||
| libnice-dev \ | ||
| libmodbus-dev | ||
| libmodbus-dev \ | ||
| python3 \ | ||
|
||
| python3-dev \ | ||
| python3-pybind11 | ||
|
|
||
| # Add local and 64-bit locations to linker paths | ||
| ENV echo /usr/local/lib >> /etc/ld.so.conf && \ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,10 @@ RUN apt-get update && \ | |
| libusb-1.0-0-dev:${ARCH} \ | ||
| liblua5.3-dev:${ARCH} \ | ||
| libhiredis-dev:${ARCH} \ | ||
| libmodbus-dev:${ARCH} | ||
| libmodbus-dev:${ARCH} \ | ||
| python3:${ARCH} \ | ||
|
||
| python3-dev:${ARCH} \ | ||
| python3-pybind11:${ARCH} | ||
|
|
||
| # Add local and 64-bit locations to linker paths | ||
| ENV echo /usr/local/lib >> /etc/ld.so.conf && \ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,10 @@ RUN apt-get update && \ | |
| libmodbus-dev \ | ||
| libre2-dev \ | ||
| libglib2.0-dev \ | ||
| libcriterion-dev | ||
| libcriterion-dev \ | ||
| python3 \ | ||
|
||
| python3-dev \ | ||
| python3-pybind11 | ||
|
|
||
| # Add local and 64-bit locations to linker paths | ||
| ENV echo /usr/local/lib >> /etc/ld.so.conf && \ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,5 +35,14 @@ add_custom_target(run-unit-tests | |
| USES_TERMINAL | ||
| ) | ||
|
|
||
| find_package(Python3 REQUIRED COMPONENTS Interpreter) | ||
|
||
| add_custom_target(run-python-wrapper-tests | ||
| COMMAND | ||
| ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/unit/python_wrapper.py | ||
| DEPENDS | ||
| python-wrapper | ||
| USES_TERMINAL | ||
| ) | ||
|
|
||
| add_dependencies(tests unit-tests) | ||
| add_dependencies(run-tests run-unit-tests) | ||
| add_dependencies(run-tests run-unit-tests run-python-wrapper-tests) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.