Skip to content

Commit 82d7e33

Browse files
authored
Merge pull request #1087 from 6WIND/python
New python bindings using CFFI as an alternative to SWIG generated bindings.
2 parents 18d5137 + 6e6475d commit 82d7e33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4591
-21
lines changed

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ex: ft=dosini
2+
3+
root = true
4+
5+
[*]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
charset = utf-8
9+
indent_style = space
10+
indent_size = 4
11+
12+
[*.yml]
13+
indent_size = 2
14+
15+
[*.yang]
16+
indent_size = 2
17+
18+
[packages/debian.rules.in]
19+
indent_style = tabs
20+
indent_size = 1
21+
tab_width = 8

.travis.yml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,36 @@ before_install:
4444
- cmake .. && make -j2 && sudo make install
4545
- cd ../..
4646
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi
47-
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get update -qq; sudo apt-get install -y valgrind libpcre3-dev python3-dev swig; fi
47+
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get update -qq; sudo apt-get install -y valgrind libpcre3-dev python3-dev swig python3-cffi python3-setuptools twine; fi
4848
- if [ "$TRAVIS_OS_NAME" = "linux" -a "$CC" = "gcc" -a "$TRAVIS_ARCH" = "amd64" ]; then pip install --user codecov; export CFLAGS="-coverage"; fi
4949

5050
script:
5151
- mkdir build && cd build
5252
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then cmake -DENABLE_VALGRIND_TESTS=OFF ..; fi
53-
- if [ "$TRAVIS_OS_NAME" = "linux" -a "$TRAVIS_ARCH" = "amd64" ]; then cmake -DGEN_LANGUAGE_BINDINGS=ON -DENABLE_STATIC=${ENABLE_STATIC:-OFF} ..; fi
54-
- if [ "$TRAVIS_OS_NAME" = "linux" -a "$TRAVIS_ARCH" = "arm64" ]; then cmake -DGEN_LANGUAGE_BINDINGS=ON -DENABLE_VALGRIND_TESTS=OFF ..; fi
53+
- if [ "$TRAVIS_OS_NAME" = "linux" -a "$TRAVIS_ARCH" = "amd64" ]; then cmake -DGEN_LANGUAGE_BINDINGS=ON -DENABLE_STATIC=${ENABLE_STATIC:-OFF} -DGEN_PYTHON_CFFI_BINDINGS=ON ..; fi
54+
- if [ "$TRAVIS_OS_NAME" = "linux" -a "$TRAVIS_ARCH" = "arm64" ]; then cmake -DGEN_LANGUAGE_BINDINGS=ON -DENABLE_VALGRIND_TESTS=OFF -DGEN_PYTHON_CFFI_BINDINGS=ON ..; fi
5555
- make -j2 && ctest --output-on-failure
5656
- cd -
5757

58-
after_success:
59-
- if [ "$TRAVIS_OS_NAME" = "linux" -a "$CC" = "gcc" -a "$TRAVIS_ARCH" = "amd64" -a "$TRAVIS_BRANCH" = "master" ]; then codecov; ./packages/create-package.sh; fi
58+
deploy:
59+
- provider: script
60+
script: codecov
61+
skip_cleanup: true
62+
verbose: true
63+
on:
64+
branch: master
65+
condition: $TRAVIS_OS_NAME = linux && $CC = gcc && $TRAVIS_ARCH = amd64
66+
- provider: script
67+
script: ./packages/create-package.sh
68+
skip_cleanup: true
69+
verbose: true
70+
on:
71+
branch: master
72+
condition: $TRAVIS_OS_NAME = linux && $CC = gcc && $TRAVIS_ARCH = amd64
73+
- provider: script
74+
script: twine upload --skip-existing build/python/dist/*
75+
skip_cleanup: true
76+
verbose: true
77+
on:
78+
branch: master
79+
condition: $TRAVIS_OS_NAME = linux && $CC = gcc && $TRAVIS_ARCH = amd64

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ set(USER_TYPES_PLUGINS_DIR_MACRO "${PLUGINS_DIR}/user_types")
106106
set(GEN_LANGUAGE_BINDINGS 0 CACHE BOOL "Enable language bindings generation.")
107107
set(GEN_CPP_BINDINGS 1 CACHE BOOL "Enable C++ bindings.")
108108
# Python bindings depend on C++ bindings because of SWIG
109-
set(GEN_PYTHON_BINDINGS 1 CACHE BOOL "Enable Python bindings.")
109+
set(GEN_PYTHON_BINDINGS 1 CACHE BOOL "Enable Python SWIG bindings.")
110110
set(GEN_PYTHON_VERSION "3" CACHE STRING "Python version")
111+
set(GEN_PYTHON_CFFI_BINDINGS 0 CACHE BOOL "Enable Python CFFI bindings.")
111112
set(GEN_JAVASCRIPT_BINDINGS 0 CACHE BOOL "Enable JavaScript bindings.")
112113
set(GEN_JAVA_BINDINGS 0 CACHE BOOL "Enable Java bindings.")
113114

@@ -194,6 +195,8 @@ set(headers
194195
# link compat
195196
use_compat()
196197

198+
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
199+
197200
# create static libyang library
198201
if(ENABLE_STATIC)
199202
add_definitions(-DSTATIC)
@@ -214,7 +217,6 @@ if(ENABLE_STATIC)
214217
set(ENABLE_VALGRIND_TESTS OFF)
215218
endif(ENABLE_VALGRIND_TESTS)
216219
else()
217-
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
218220
add_library(yangobj OBJECT ${libsrc})
219221
add_library(yang SHARED $<TARGET_OBJECTS:yangobj> $<TARGET_OBJECTS:compat>)
220222

@@ -375,3 +377,7 @@ endif()
375377
if(GEN_LANGUAGE_BINDINGS AND GEN_CPP_BINDINGS)
376378
add_subdirectory(swig)
377379
endif()
380+
381+
if(GEN_PYTHON_CFFI_BINDINGS)
382+
add_subdirectory(python)
383+
endif()

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,14 @@ More information about the specific binding can be found in their README files.
258258
Currently supported bindings are:
259259

260260
* JavaScript
261-
* cmake option: `JAVASCRIPT_BINDING`
262-
* [README](./swig/javascript/README.md)
261+
- cmake option: `JAVASCRIPT_BINDING`
262+
- [README](./swig/javascript/README.md)
263+
* Python SWIG (uses SWIG, enabled by default if `GEN_LANGUAGE_BINDINGS` is set)
264+
- cmake option: `GEN_PYTHON_BINDINGS` (depends on `GEN_CPP_BINDINGS`)
265+
- [README](./swig/python/README.md)
266+
* Python CFFI (more "pythonic" API, not enabled by default)
267+
- cmake option: `GEN_PYTHON_CFFI_BINDINGS`
268+
- [README](./python/README.md)
263269

264270
## Project Information
265271

packages/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(PACKAGE "libyang")
22
set(CPP_PACKAGE "libyang-cpp")
33
set(PYTHON_PACKAGE "python3-yang")
4+
set(PYTHON_CFFI_PACKAGE "python3-libyang")
45

56
find_program(DEB_BUILDER NAMES debuild)
67
find_program(RPM_BUILDER NAMES rpmbuild)
@@ -25,6 +26,8 @@ configure_file(${PROJECT_SOURCE_DIR}/packages/debian.${CPP_PACKAGE}-dev.install
2526
# no python package for Debian because there is only SWIG 3.10 on Debian 9 :-/
2627
#configure_file(${PROJECT_SOURCE_DIR}/packages/debian.${PYTHON_PACKAGE}.install
2728
# ${PROJECT_BINARY_DIR}/build-packages/debian.${PYTHON_PACKAGE}.install COPYONLY)
29+
configure_file(${PROJECT_SOURCE_DIR}/packages/debian.${PYTHON_CFFI_PACKAGE}.install
30+
${PROJECT_BINARY_DIR}/build-packages/debian.${PYTHON_CFFI_PACKAGE}.install COPYONLY)
2831

2932
if(NOT DEB_BUILDER)
3033
message(STATUS "Missing tools (devscripts, debhelper package) for building DEB package.")

packages/debian.control.in

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@ Source: @PACKAGE@
22
Maintainer: CESNET <[email protected]>
33
Priority: extra
44
Standards-Version: 3.8.2
5-
Build-Depends: debhelper (>= 9), gcc
5+
Build-Depends:
6+
debhelper (>= 9),
7+
dh-python,
8+
make,
9+
gcc,
10+
g++,
11+
doxygen,
12+
cmake,
13+
pkg-config,
14+
libpcre3-dev,
15+
libcmocka-dev,
16+
python3 (>= 3.5),
17+
python3-cffi,
18+
python3-setuptools,
619
Homepage: https://github.com/CESNET/libyang
720

821
Package: @PACKAGE@
@@ -40,3 +53,19 @@ Depends: @CPP_PACKAGE@ (=@LIBYANG_VERSION@)
4053
Section: debug
4154
Architecture: any
4255
Description: Debug symbols of C++ bidings of libyang library.
56+
57+
Package: @PYTHON_CFFI_PACKAGE@
58+
Depends:
59+
${misc:Depends},
60+
${python3:Depends},
61+
python3-cffi,
62+
@PACKAGE@ (=@LIBYANG_VERSION@),
63+
Section: libs
64+
Architecture: any
65+
Description: CFFI bindings of libyang library to Python language.
66+
67+
Package: @PYTHON_CFFI_PACKAGE@-dbg
68+
Depends: @PYTHON_CFFI_PACKAGE@ (=@LIBYANG_VERSION@)
69+
Section: debug
70+
Architecture: any
71+
Description: Debug symbols of Python CFFI bindings of libyang library.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
usr/lib/python3*/dist-packages/*

packages/debian.python3-yang.install

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/debian.rules.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
export DH_VERBOSE=1
55

66
%:
7-
dh $@
7+
dh $@ --with python3
88

99
override_dh_strip:
1010
dh_strip -p@PACKAGE@ --dbg-package=@PACKAGE@-dbg
1111
dh_strip -p@CPP_PACKAGE@ --dbg-package=@CPP_PACKAGE@-dbg
12-
# dh_strip -p@PYTHON_PACKAGE@ --dbg-package=@PYTHON_PACKAGE@-dbg
12+
dh_strip -p@PYTHON_CFFI_PACKAGE@ --dbg-package=@PYTHON_CFFI_PACKAGE@-dbg
1313

1414
override_dh_auto_configure:
1515
cmake -DCMAKE_INSTALL_PREFIX=/usr -DFORCE_INSRC_BUILD=ON -DCMAKE_BUILD_TYPE="Package" -DENABLE_LYD_PRIV=ON \
16-
-DGEN_LANGUAGE_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF .
16+
-DGEN_LANGUAGE_BINDINGS=ON -DGEN_PYTHON_BINDINGS=OFF -DGEN_PYTHON_CFFI_BINDINGS=ON .
1717

1818
override_dh_auto_test:
1919
ctest --output-on-failure

packages/libyang.dsc.in

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
Format: 3.0 (quilt)
22
Source: @PACKAGE@
3-
Binary: @PACKAGE@, @PACKAGE@-dbg, @PACKAGE@-dev, @CPP_PACKAGE@, @CPP_PACKAGE@-dev, @CPP_PACKAGE@-dbg
3+
Binary:
4+
@PACKAGE@,
5+
@PACKAGE@-dbg,
6+
@PACKAGE@-dev,
7+
@CPP_PACKAGE@,
8+
@CPP_PACKAGE@-dev,
9+
@CPP_PACKAGE@-dbg,
10+
@PYTHON_CFFI_PACKAGE@,
11+
@PYTHON_CFFI_PACKAGE@-dbg,
412
Maintainer: CESNET <[email protected]>
513
Version: @LIBYANG_VERSION@
614
Architecture: any
715
Standards-Version: 3.8.2
816
Homepage: https://github.com/CESNET/libyang
917
Vcs-Git: https://github.com/CESNET/libyang
10-
Build-Depends: debhelper (>= 9), make, gcc, doxygen, cmake, pkg-config, libpcre3-dev, libcmocka-dev, g++
18+
Build-Depends:
19+
debhelper (>= 9),
20+
dh-python,
21+
make,
22+
gcc,
23+
g++,
24+
doxygen,
25+
cmake,
26+
pkg-config,
27+
libpcre3-dev,
28+
libcmocka-dev,
29+
python3 (>= 3.5),
30+
python3-cffi,
31+
python3-setuptools,

0 commit comments

Comments
 (0)