-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bindings CHANGE add new python CFFI bindings
This is the integration of https://github.com/rjarry/libyang-cffi In the long term, it is intended to replace the existing SWIG bindings. Some highlights: * Uses CFFI for interaction with libyang.so. * More "pythonic" API. Should be easier to use for Python developers. * All high-level code is in Python. Should ease maintenance. * Virtualenv/pip friendly. * Schema diff feature. * New "print" data format: python dict. To enable the generation, add the -DGEN_PYTHON_CFFI_BINDINGS=ON cmake option. It does not depend on SWIG nor on the CPP bindings. It may be enabled even if -DGEN_LANGUAGE_BINDINGS is OFF. Signed-off-by: Robin Jarry <[email protected]>
- Loading branch information
Showing
40 changed files
with
4,545 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,20 @@ Source: @PACKAGE@ | |
Maintainer: CESNET <[email protected]> | ||
Priority: extra | ||
Standards-Version: 3.8.2 | ||
Build-Depends: debhelper (>= 9), gcc | ||
Build-Depends: | ||
debhelper (>= 9), | ||
dh-python, | ||
make, | ||
gcc, | ||
g++, | ||
doxygen, | ||
cmake, | ||
pkg-config, | ||
libpcre3-dev, | ||
libcmocka-dev, | ||
python3 (>= 3.5), | ||
python3-cffi, | ||
python3-setuptools, | ||
Homepage: https://github.com/CESNET/libyang | ||
|
||
Package: @PACKAGE@ | ||
|
@@ -40,3 +53,19 @@ Depends: @CPP_PACKAGE@ (=@LIBYANG_VERSION@) | |
Section: debug | ||
Architecture: any | ||
Description: Debug symbols of C++ bidings of libyang library. | ||
|
||
Package: @PYTHON_CFFI_PACKAGE@ | ||
Depends: | ||
${misc:Depends}, | ||
${python3:Depends}, | ||
python3-cffi, | ||
@PACKAGE@ (=@LIBYANG_VERSION@), | ||
Section: libs | ||
Architecture: any | ||
Description: CFFI bindings of libyang library to Python language. | ||
|
||
Package: @PYTHON_CFFI_PACKAGE@-dbg | ||
Depends: @PYTHON_CFFI_PACKAGE@ (=@LIBYANG_VERSION@) | ||
Section: debug | ||
Architecture: any | ||
Description: Debug symbols of Python CFFI bindings of libyang library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
usr/lib/python3*/dist-packages/* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
Format: 3.0 (quilt) | ||
Source: @PACKAGE@ | ||
Binary: @PACKAGE@, @PACKAGE@-dbg, @PACKAGE@-dev, @CPP_PACKAGE@, @CPP_PACKAGE@-dev, @CPP_PACKAGE@-dbg | ||
Binary: | ||
@PACKAGE@, | ||
@PACKAGE@-dbg, | ||
@PACKAGE@-dev, | ||
@CPP_PACKAGE@, | ||
@CPP_PACKAGE@-dev, | ||
@CPP_PACKAGE@-dbg, | ||
@PYTHON_CFFI_PACKAGE@, | ||
@PYTHON_CFFI_PACKAGE@-dbg, | ||
Maintainer: CESNET <[email protected]> | ||
Version: @LIBYANG_VERSION@ | ||
Architecture: any | ||
Standards-Version: 3.8.2 | ||
Homepage: https://github.com/CESNET/libyang | ||
Vcs-Git: https://github.com/CESNET/libyang | ||
Build-Depends: debhelper (>= 9), make, gcc, doxygen, cmake, pkg-config, libpcre3-dev, libcmocka-dev, g++ | ||
Build-Depends: | ||
debhelper (>= 9), | ||
dh-python, | ||
make, | ||
gcc, | ||
g++, | ||
doxygen, | ||
cmake, | ||
pkg-config, | ||
libpcre3-dev, | ||
libcmocka-dev, | ||
python3 (>= 3.5), | ||
python3-cffi, | ||
python3-setuptools, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ cp "@PROJECT_SOURCE_DIR@/packages/debian.@[email protected]" debian/@[email protected] | |
cp "@PROJECT_SOURCE_DIR@/packages/debian.@[email protected]" debian/@[email protected] | ||
cp "@PROJECT_SOURCE_DIR@/packages/debian.@[email protected]" debian/@[email protected] | ||
cp "@PROJECT_SOURCE_DIR@/packages/debian.@[email protected]" debian/@[email protected] | ||
cp "@PROJECT_SOURCE_DIR@/packages/debian.@PYTHON_PACKAGE@.install" debian/@PYTHON_PACKAGE@.install | ||
cp "@PROJECT_SOURCE_DIR@/packages/debian.@PYTHON_CFFI_PACKAGE@.install" debian/@PYTHON_CFFI_PACKAGE@.install | ||
echo -e "@PACKAGE@ (@LIBYANG_VERSION@) stable; urgency=low\n" >debian/changelog | ||
git log -10 --pretty=format:' * %s (%aN)%n' 2>/dev/null >>debian/changelog || echo -e " * unknown changes \n" >>debian/changelog | ||
git log -1 --pretty=format:'%n -- %aN <%aE> %aD%n' >>debian/changelog 2>/dev/null || echo " -- ${USER} <${USER}@`hostname`> `date -R`" >>debian/changelog | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
if(NOT ${GEN_PYTHON_VERSION} EQUAL "3") | ||
message(FATAL_ERROR "Python cffi bindings only support python 3.") | ||
endif() | ||
|
||
unset(PYTHON_LIBRARY CACHE) | ||
unset(PYTHON_EXECUTABLE CACHE) | ||
unset(PYTHON_INCLUDE_DIR CACHE) | ||
|
||
find_package(PythonInterp 3 REQUIRED) | ||
find_package(PythonLibs 3 REQUIRED) | ||
foreach(dep setuptools cffi) | ||
execute_process( | ||
COMMAND ${PYTHON_EXECUTABLE} -B -c "import ${dep}" | ||
RESULT_VARIABLE PYTHON_DEP_RESULT) | ||
if(NOT ${PYTHON_DEP_RESULT} EQUAL 0) | ||
message(FATAL_ERROR "Missing required python module: ${dep}") | ||
endif() | ||
endforeach() | ||
|
||
set(PYTHON_MODULE_PATH_CMD " | ||
from distutils.sysconfig import get_python_lib | ||
print(get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}', plat_specific=True)) | ||
") | ||
execute_process( | ||
COMMAND ${PYTHON_EXECUTABLE} -B -c "${PYTHON_MODULE_PATH_CMD}" | ||
OUTPUT_VARIABLE PYTHON_MODULE_PATH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
set(PYTHON_LIB_BUILDDIR_CMD " | ||
import sys | ||
from distutils.util import get_platform | ||
print('lib.' + get_platform() + '-{}.{}'.format(*sys.version_info[:2])) | ||
") | ||
execute_process( | ||
COMMAND ${PYTHON_EXECUTABLE} -B -c "${PYTHON_LIB_BUILDDIR_CMD}" | ||
OUTPUT_VARIABLE PYTHON_LIB_BUILDDIR | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
configure_file(pydistutils.cfg.in .pydistutils.cfg @ONLY) | ||
# Cmake does not support exporting specific environment variables for | ||
# custom_target commands. The only way is to use a shell script. | ||
configure_file(run_python.sh.in run_python.sh @ONLY) | ||
configure_file( | ||
${CMAKE_SOURCE_DIR}/src/libyang.h.in | ||
${CMAKE_CURRENT_BINARY_DIR}/include/libyang/libyang.h @ONLY) | ||
foreach(header ${headers}) | ||
configure_file( | ||
${CMAKE_SOURCE_DIR}/${header} | ||
${CMAKE_CURRENT_BINARY_DIR}/include/libyang/ COPYONLY) | ||
endforeach() | ||
|
||
add_custom_target( | ||
python_cffi ALL | ||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/run_python.sh ./setup.py build | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
DEPENDS yang ${EXTENSIONS_LIST} ${USER_TYPE_LIST}) | ||
add_custom_target( | ||
python_cffi_sdist | ||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/run_python.sh ./setup.py sdist | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
if(ENABLE_BUILD_TESTS) | ||
set(PYTHON_TESTS | ||
tests/test_context.py | ||
tests/test_data.py | ||
tests/test_diff.py | ||
tests/test_schema.py) | ||
foreach(test_file ${PYTHON_TESTS}) | ||
string( | ||
REGEX REPLACE "tests/test_([a-z]+)\\.py" "test_python_\\1" | ||
test_name ${test_file}) | ||
add_test( | ||
NAME ${test_name} | ||
COMMAND ${PYTHON_EXECUTABLE} -B -m unittest -cv ${test_file} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | ||
set_property( | ||
TEST ${test_name} | ||
PROPERTY ENVIRONMENT | ||
PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/${PYTHON_LIB_BUILDDIR} | ||
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR} | ||
LIBYANG_EXTENSIONS_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/extensions | ||
LIBYANG_USER_TYPES_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/user_types) | ||
endforeach() | ||
endif() | ||
|
||
install(CODE " | ||
execute_process( | ||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/run_python.sh ./setup.py install --root=\$ENV{DESTDIR}/ | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | ||
") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
graft cffi | ||
graft clib | ||
prune clib/.git | ||
prune clib/doc | ||
prune clib/python | ||
prune clib/swig | ||
prune clib/tests | ||
prune clib/tools/lint/examples | ||
graft libyang | ||
prune libyang/_lib | ||
prune libyang/_include | ||
include build-so.sh | ||
include setup.py | ||
include setup.cfg | ||
include LICENSE | ||
include README.md | ||
global-exclude *.py[co] | ||
global-exclude *.so | ||
global-exclude *.o | ||
global-exclude *.a |
Oops, something went wrong.