Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
40c9103
Build system for python-wrapper
Mar 14, 2025
7302be2
Added wrapper dependencies to Dockerfiles
Mar 14, 2025
3703c20
Python-Wrapper bindings
Mar 14, 2025
76ec913
Added Tests for the Python-Wrapper
Mar 14, 2025
24abdb7
node.cpp Bugfix
Mar 14, 2025
640e815
CMake Python-Wrapper test integration, build fix
Mar 24, 2025
862d498
Applied changes as per feedback.
Mar 24, 2025
c48be8f
Merge branch 'master' into python-wrapper
al3xa23 Apr 7, 2025
73ce98f
Fixed typo
Apr 8, 2025
168df21
Explicitly disallowed copy and assignment
Apr 8, 2025
e710de5
CMakeLists.txt fix
Apr 8, 2025
b1e9a2f
Removed unnecessary dockerfile dependencies
May 14, 2025
365f88b
Renamed wrapper -> binding, LLVM format
May 14, 2025
6806d24
Changes for pipeline test integration
May 14, 2025
c5026a2
Merge branch 'master' into python-wrapper
al3xa23 May 15, 2025
9216366
Binding test formatted with black
May 15, 2025
2d7628f
Format Python binding test with black-jupyter
May 22, 2025
07cffec
Align python-devel package for consistency
Jun 12, 2025
d9d12de
Moved clients/python-binding/ to python/binding/
Jul 17, 2025
a146ecb
python-binding unit test split, socket fixes
Jul 17, 2025
22714fe
unit tests: add test and enable test discovery
Sep 8, 2025
052f419
integration tests: added and enable test discovery
Sep 8, 2025
be2b770
python binding: add wrapper and binding tweaks
Sep 9, 2025
5b887a4
binding tests: add binding wrapper tests
Sep 9, 2025
279eb80
binding tests: CI fix and reformat
Sep 9, 2025
66e1f14
binding wrapper: CI/build fix, add binding stubs
Sep 10, 2025
f73fc67
binding stubs: add missing SPDX header
Sep 12, 2025
124a1f5
python binding: install and fix CI
Sep 12, 2025
f023f4d
Merge branch 'master' into python-wrapper
Sep 12, 2025
1af1e49
Rework Binding Wrapper
Dec 15, 2025
d47ef14
Update stubs to match changes
Dec 15, 2025
d075db1
Update tests to match binding changes
Dec 15, 2025
3f00208
Merge branch 'master' into python-wrapper
Dec 16, 2025
f0c4eb8
Enforce pre-commit formatting
Dec 16, 2025
00b6528
Replace C with C++ casting, sample pack/unpack fix
Dec 16, 2025
b999f86
fix(ci): prevent mypy package root ambiguity
Dec 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand All @@ -182,6 +182,28 @@ test:cppcheck:
- cppcheck.log
expose_as: cppcheck

test:python_unit_integration:
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}
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.15)

project(villas-node
VERSION 1.1.0
Expand Down
5 changes: 3 additions & 2 deletions include/villas/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#pragma once
#include <cstdint>

#include <jansson.h>
#include <stdbool.h>
Expand Down Expand Up @@ -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,
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,
struct timespec *ts_received, int *flags, unsigned *len,
double *values);

Expand Down
2 changes: 1 addition & 1 deletion lib/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ Node *NodeFactory::make(json_t *json, const uuid_t &id,
std::string type;
Node *n;

if (json_is_object(json))
if (!json_is_object(json))
throw ConfigError(json, "node-config-node",
"Node configuration must be an object");

Expand Down
6 changes: 3 additions & 3 deletions lib/node_capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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;
Expand All @@ -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,
struct timespec *ts_received, int *flags, unsigned *len,
double *values) {
auto *smp = (Sample *)s;
Expand Down
26 changes: 24 additions & 2 deletions lib/nodes/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ int villas::node::socket_init(NodeCompat *n) {
auto *s = n->getData<struct Socket>();

s->formatter = nullptr;
s->sd = -1;
s->in.buf = nullptr;
s->out.buf = nullptr;

return 0;
}
Expand All @@ -77,6 +80,17 @@ int villas::node::socket_destroy(NodeCompat *n) {
if (s->formatter)
delete s->formatter;

if (s->in.buf != nullptr) {
memset(s->in.buf, 0, s->in.buflen);
delete[] s->in.buf;
s->in.buf = nullptr;
}
if (s->out.buf != nullptr) {
memset(s->out.buf, 0, s->out.buflen);
delete[] s->out.buf;
s->out.buf = nullptr;
}

return 0;
}

Expand Down Expand Up @@ -355,8 +369,16 @@ int villas::node::socket_stop(NodeCompat *n) {
return ret;
}

delete[] s->in.buf;
delete[] s->out.buf;
if (s->in.buf != nullptr) {
memset(s->in.buf, 0, s->in.buflen);
delete[] s->in.buf;
s->in.buf = nullptr;
}
if (s->out.buf != nullptr) {
memset(s->out.buf, 0, s->out.buflen);
delete[] s->out.buf;
s->out.buf = nullptr;
}

return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions packaging/docker/Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ RUN apt-get update && \
libssl-dev \
libusb-1.0-0-dev \
libzmq3-dev \
python3-dev \
python3-pybind11 \
uuid-dev

# Install unpackaged dependencies from source
Expand Down
2 changes: 2 additions & 0 deletions packaging/docker/Dockerfile.debian-multiarch
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ RUN apt-get update && \
libssl-dev:${ARCH} \
libusb-1.0-0-dev:${ARCH} \
libzmq3-dev:${ARCH} \
python3-dev:${ARCH} \
python3-pybind11:${ARCH} \
uuid-dev:${ARCH}

ADD cmake/toolchains/debian-${ARCH}.cmake /
Expand Down
3 changes: 2 additions & 1 deletion packaging/docker/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN dnf -y install \
openssh-clients \
jq nmap-ncat \
iproute iproute-tc \
python python-devel python-pip \
python-devel python-pip \
gdb gdb-gdbserver \
cppcheck \
xmlto dblatex rubygem-asciidoctor \
Expand Down Expand Up @@ -63,6 +63,7 @@ RUN dnf -y install \
openssl-devel \
protobuf-c-devel \
protobuf-devel \
pybind11-devel \
spdlog-devel \
zeromq-devel

Expand Down
4 changes: 3 additions & 1 deletion packaging/docker/Dockerfile.rocky
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ RUN dnf -y install \
nanomsg-devel \
libnice-devel \
libre-devel \
libwebsockets-devel
libwebsockets-devel \
python-devel \
pybind11-devel

# Install unpackaged dependencies from source
ADD packaging/patches /deps/patches
Expand Down
2 changes: 2 additions & 0 deletions packaging/docker/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ RUN apt-get update && \
libusb-1.0-0-dev \
libwebsockets-dev \
libzmq3-dev \
python3-dev \
python3-pybind11 \
uuid-dev

# Install unpackaged dependencies from source
Expand Down
2 changes: 2 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(binding)

if(DEFINED PROTOBUF_COMPILER AND PROTOBUF_FOUND)
add_custom_command(
OUTPUT
Expand Down
33 changes: 33 additions & 0 deletions python/binding/CMakeLists.txt
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()
Loading