package/python-libyang: new package
PATCH v2 1/1 package/python-libyang: new package
From: Vincent Jardin <[email protected]>
Python CFFI bindings for the libyang YANG library, providing the 'libyang' Python module for YANG data modeling operations.
This package is used by higher-level tooling such as python-sysrepo.
https://github.com/CESNET/libyang-python
---v1->v2:
Remove python-sysrepo
Fix Config.in dependencies
Add test
Tested with Buildroot gitlab CI:
https://gitlab.com/v_cz/buildroot/-/pipelines/2457352559
--- DEVELOPERS | 1 + package/Config.in | 1 + package/python-libyang/Config.in | 19 +++++++++ package/python-libyang/python-libyang.hash | 5 +++ package/python-libyang/python-libyang.mk | 21 ++++++++++ .../tests/package/sample_python_libyang.py | 41 +++++++++++++++++++ .../tests/package/test_python_libyang.py | 26 ++++++++++++ 7 files changed, 114 insertions(+) create mode 100644 package/python-libyang/Config.in create mode 100644 package/python-libyang/python-libyang.hash create mode 100644 package/python-libyang/python-libyang.mk create mode 100644 support/testing/tests/package/sample_python_libyang.py create mode 100644 support/testing/tests/package/test_python_libyang.py
DEVELOPERS +1 -0
@@ -3372,6 +3372,7 @@ F: package/dpdk/ F: package/libecoli/ F: package/libnss-ato/ F: package/libyang-cpp/ +F: package/python-libyang/ F: package/sysrepo-cpp/ N: Vincent Prince <[email protected]>
package/Config.in +1 -0
@@ -1207,6 +1207,7 @@ menu "External python modules" source "package/python-libevdev/Config.in" source "package/python-librt/Config.in" source "package/python-libusb1/Config.in" + source "package/python-libyang/Config.in" source "package/python-lmdb/Config.in" source "package/python-lockfile/Config.in" source "package/python-log-rate-limit/Config.in"
package/python-libyang/Config.in new file +19 -0
@@ -0,0 +1,19 @@ +config BR2_PACKAGE_PYTHON_LIBYANG + bool "python-libyang" + depends on BR2_TOOLCHAIN_HAS_SYNC_4 # libyang + depends on BR2_TOOLCHAIN_HAS_THREADS # libyang + depends on !BR2_STATIC_LIBS # libyang + select BR2_PACKAGE_LIBYANG + select BR2_PACKAGE_PYTHON_CFFI # runtime + help + Python CFFI bindings for the libyang YANG library. + + This package provides the 'libyang' Python module, used by + higher-level tooling such as python-sysrepo. + + https://github.com/CESNET/libyang-python + +comment "python-libyang needs libyang" + depends on !BR2_TOOLCHAIN_HAS_SYNC_4 + depends on !BR2_TOOLCHAIN_HAS_THREADS + depends on BR2_STATIC_LIBS
package/python-libyang/python-libyang.hash new file +5 -0
@@ -0,0 +1,5 @@ +# From https://pypi.org/pypi/libyang/3.3.0/json +sha256 97da2c908a8a3607ac834f2acec224ea53a4b9e9770c13e5598513641decf637 libyang-3.3.0.tar.gz + +# Locally computed +sha256 c8d554f918d32b1467f35829e1cfb753764dd683c6edcecc877a4d7e9f05b2a7 LICENSE
package/python-libyang/python-libyang.mk new file +21 -0
@@ -0,0 +1,21 @@ +################################################################################ +# +# python-libyang +# +################################################################################ + +PYTHON_LIBYANG_VERSION = 3.3.0 +PYTHON_LIBYANG_SOURCE = libyang-$(PYTHON_LIBYANG_VERSION).tar.gz +PYTHON_LIBYANG_SITE = https://files.pythonhosted.org/packages/source/l/libyang + +PYTHON_LIBYANG_LICENSE = MIT +PYTHON_LIBYANG_LICENSE_FILES = LICENSE + +# pyproject.toml (PEP517) +PYTHON_LIBYANG_SETUP_TYPE = pep517 + +PYTHON_LIBYANG_DEPENDENCIES = \ + libyang \ + host-python-cffi + +$(eval $(python-package))
support/testing/tests/package/sample_python_libyang.py new file +41 -0
41 lines not on this page · raw message
support/testing/tests/package/test_python_libyang.py new file +26 -0
@@ -0,0 +1,26 @@ +import os +from xml.etree import ElementTree +from tests.package.test_python import TestPythonPackageBase + + +class TestPythonLibyang(TestPythonPackageBase): + __test__ = True + config = TestPythonPackageBase.config + \ + """ + BR2_PACKAGE_PYTHON3=y + BR2_PACKAGE_PYTHON_LIBYANG=y + """ + sample_scripts = ["tests/package/sample_python_libyang.py"] + + def test_run(self): + self.login() + self.check_sample_scripts_exist() + + cmd = self.interpreter + " " + os.path.basename(self.sample_scripts[0]) + output, exit_code = self.emulator.run(cmd, timeout=15) + self.assertEqual(exit_code, 0) + + tree = ElementTree.fromstringlist(output) + self.assertEqual(tree.tag, '{urn:example}data') + self.assertEqual(tree.find('.//{*}hostname').text, 'foobar') + self.assertEqual(len(tree.find('.//{*}interface')), 2)
Signature · 6 lines
2.51.0 :x _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Hello Vincent,
Thanks for submitting this patch, which I have applied to next after doing some changes. See below.
Quoted 15 lines · Vincent Cruz
package/python-libyang/Config.in new file +9
-0@@ -0,0 +1,19 @@ +config BR2_PACKAGE_PYTHON_LIBYANG + bool "python-libyang" + depends on BR2_TOOLCHAIN_HAS_SYNC_4 # libyang + depends on BR2_TOOLCHAIN_HAS_THREADS # libyang + depends on !BR2_STATIC_LIBS # libyang + select BR2_PACKAGE_LIBYANG + select BR2_PACKAGE_PYTHON_CFFI # runtime + help + Python CFFI bindings for the libyang YANG library.
package/python-libyang/Config.in line 19
Quoted 10 lines
package/python-libyang/Config.in new file +10
-0+ + This package provides the 'libyang' Python module, used by + higher-level tooling such as python-sysrepo. + + https://github.com/CESNET/libyang-python + +comment "python-libyang needs libyang" + depends on !BR2_TOOLCHAIN_HAS_SYNC_4 + depends on !BR2_TOOLCHAIN_HAS_THREADS + depends on BR2_STATIC_LIBS
This is not the correct way of providing dependency comments. We don't care about the libyang dependency being commented on because you're selecting libyang. We need comments about toolchain dependencies.
Changed to:
+comment "python-libyang needs a toolchain w/ threads, dynamic library"
+ depends on !BR2_TOOLCHAIN_HAS_SYNC_4
+ depends on !BR2_TOOLCHAIN_HAS_THREADS || BR2_STATIC_LIBS
Quoted 22 lines
support/testing/tests/package/test_python_libyang.py new file +16
-0@@ -0,0 +1,26 @@ +import os +from xml.etree import ElementTree +from tests.package.test_python import TestPythonPackageBase + + +class TestPythonLibyang(TestPythonPackageBase): + __test__ = True + config = TestPythonPackageBase.config + \ + """ + BR2_PACKAGE_PYTHON3=y + BR2_PACKAGE_PYTHON_LIBYANG=y + """ + sample_scripts = ["tests/package/sample_python_libyang.py"] + + def test_run(self): + self.login()
support/testing/tests/package/test_python_libyang.py line 26
Quoted 10 lines
support/testing/tests/package/test_python_libyang.py new file +10
-0+ self.check_sample_scripts_exist() + + cmd = self.interpreter + " " + os.path.basename(self.sample_scripts[0]) + output, exit_code = self.emulator.run(cmd, timeout=15) + self.assertEqual(exit_code, 0) + + tree = ElementTree.fromstringlist(output) + self.assertEqual(tree.tag, '{urn:example}data') + self.assertEqual(tree.find('.//{*}hostname').text, 'foobar') + self.assertEqual(len(tree.find('.//{*}interface')), 2)
Rather than overriding test_run() to be able to run your custom logic after running the same Python script, I've moved the XML validation logic inside the sample Python script itself:
+xml = node.print_mem('xml', pretty=True) +tree = ElementTree.fromstringlist(xml) +assert tree.tag == '{urn:example}data' +assert tree.find('.//{*}hostname').text == 'foobar' +assert len(tree.find('.//{*}interface')) == 2
Committed to next with those changes. Thanks!
Thomas
Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot