Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 22
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?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
40c91037302be23703c2076ec91324abdb7640e815862d498c48be8f73ce98f168df21e710de5b1e9a2f365f88b6806d24c5026a292163662d7628f07cffecd9d12dea146ecb22714fe052f419be2b7705b887a4279eb8066e1f14f73fc67124a1f5f023f4d1af1e49d47ef14d075db13f00208f0c4eb800b6528b999f86File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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() |
Uh oh!
There was an error while loading. Please reload this page.
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?