-
Notifications
You must be signed in to change notification settings - Fork 21
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 all 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
1af1e49
d47ef14
d075db1
3f00208
f0c4eb8
00b6528
b999f86
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 |
|---|---|---|
|
|
@@ -164,7 +164,7 @@ test:python: | |
| - pytest --verbose . | ||
| - black --line-length=90 --extend-exclude=".*(\\.pyi|_pb2.py)$" --check . | ||
| - flake8 --max-line-length=90 --extend-exclude="*.pyi,*_pb2.py" . | ||
| - mypy . | ||
| - mypy --explicit-package-bases . | ||
| image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG} | ||
| needs: | ||
| - job: "build:source: [fedora]" | ||
|
|
@@ -182,6 +182,28 @@ test:cppcheck: | |
| - cppcheck.log | ||
| expose_as: cppcheck | ||
|
|
||
| test:python_unit_integration: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this need to be converted to cibuildwheels and github action |
||
| stage: test | ||
| image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG} | ||
| before_script: | ||
| # dependency from node.py, which gets imported because of __init__.py in node/villas/python/node | ||
| - pip install requests | ||
| script: | ||
| # build binding and symlink to villas.node folder | ||
| # helps with correct imports and compatiblity for CI, binding wrapper and binding install | ||
| - export PYTHONPATH=$PYTHONPATH:${PWD}/python | ||
| - cmake --build build ${CMAKE_BUILD_OPTS} --target python_binding | ||
|
|
||
| - binding_path=$(find ${PWD}/build/python/binding/ -name "python_binding*.so" | head -n1) | ||
| - link_path=${PWD}/python/villas/node/$(basename $binding_path) | ||
| - ln -sf $binding_path $link_path | ||
|
|
||
| - cmake --build build ${CMAKE_BUILD_OPTS} --target run-python-unit-tests run-python-integration-tests | ||
| - rm $link_path | ||
| needs: | ||
| - job: "build:source: [fedora]" | ||
| artifacts: true | ||
|
|
||
| test:unit: | ||
| stage: test | ||
| image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| */ | ||
|
|
||
| #pragma once | ||
| #include <cstdint> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use |
||
|
|
||
| #include <jansson.h> | ||
| #include <stdbool.h> | ||
|
|
@@ -67,11 +68,11 @@ unsigned sample_length(vsample *smp); | |
|
|
||
| void sample_decref(vsample *smp); | ||
|
|
||
| vsample *sample_pack(unsigned seq, struct timespec *ts_origin, | ||
| vsample *sample_pack(uint64_t *seq, struct timespec *ts_origin, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this breaks the C API, is this needed? |
||
| struct timespec *ts_received, unsigned len, | ||
| double *values); | ||
|
|
||
| void sample_unpack(vsample *s, unsigned *seq, struct timespec *ts_origin, | ||
| void sample_unpack(vsample *s, uint64_t *seq, struct timespec *ts_origin, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this breaks the C API, is this needed? |
||
| struct timespec *ts_received, int *flags, unsigned *len, | ||
| double *values); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,12 +152,12 @@ unsigned sample_length(vsample *s) { | |
| return smp->length; | ||
| } | ||
|
|
||
| vsample *sample_pack(unsigned seq, struct timespec *ts_origin, | ||
| vsample *sample_pack(uint64_t *seq, struct timespec *ts_origin, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this breaks the C API, is this needed? |
||
| struct timespec *ts_received, unsigned len, | ||
| double *values) { | ||
| auto *smp = sample_alloc_mem(len); | ||
|
|
||
| smp->sequence = seq; | ||
| smp->sequence = *seq; | ||
| smp->ts.origin = *ts_origin; | ||
| smp->ts.received = *ts_received; | ||
| smp->length = len; | ||
|
|
@@ -169,7 +169,7 @@ vsample *sample_pack(unsigned seq, struct timespec *ts_origin, | |
| return (vsample *)smp; | ||
| } | ||
|
|
||
| void sample_unpack(vsample *s, unsigned *seq, struct timespec *ts_origin, | ||
| void sample_unpack(vsample *s, uint64_t *seq, struct timespec *ts_origin, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this breaks the C API, is this needed? |
||
| struct timespec *ts_received, int *flags, unsigned *len, | ||
| double *values) { | ||
| auto *smp = (Sample *)s; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Python-binding CMakeLists. | ||
| # | ||
| # Author: Kevin Vu te Laar <vu.te@rwth-aachen.de> | ||
| # SPDX-FileCopyrightText: 2014-2025 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| 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('purelib'))" | ||
| OUTPUT_VARIABLE PYTHON_SITE_PACKAGES | ||
| 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}") | ||
|
|
||
| pybind11_add_module(python_binding capi_python_binding.cpp) | ||
| target_link_libraries(python_binding PUBLIC villas) | ||
|
|
||
| install( | ||
| TARGETS python_binding | ||
| COMPONENT lib | ||
| LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES}/villas/node/ | ||
| ) | ||
| else() | ||
| message(STATUS "pybind11 not found. Skipping Python wrapper build.") | ||
| endif() |
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.
pybind provides a way to generate stubs, would we want to do this still with mypy?