All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v2 1/1] package/python-libyang: new package
@ 2026-04-16 10:24 Vincent Cruz
  2026-05-30 14:19 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 2+ messages in thread
From: Vincent Cruz @ 2026-04-16 10:24 UTC (permalink / raw)
  To: buildroot; +Cc: Vincent Jardin, James Hilliard, Thomas Petazzoni, Vincent Cruz

From: Vincent Jardin <vjardin@free.fr>

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
Signed-off-by: Vincent Jardin <vjardin@free.fr>
Signed-off-by: Vincent Cruz <mooz@blockos.org>

---
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

diff --git a/DEVELOPERS b/DEVELOPERS
index b20cf7d93c..d8fe4e8093 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -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 <vincent.prince.fr@gmail.com>
diff --git a/package/Config.in b/package/Config.in
index d0f148699b..de7900eefe 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -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"
diff --git a/package/python-libyang/Config.in b/package/python-libyang/Config.in
new file mode 100644
index 0000000000..c314beb0ea
--- /dev/null
+++ b/package/python-libyang/Config.in
@@ -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
diff --git a/package/python-libyang/python-libyang.hash b/package/python-libyang/python-libyang.hash
new file mode 100644
index 0000000000..077d97cdd8
--- /dev/null
+++ b/package/python-libyang/python-libyang.hash
@@ -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
diff --git a/package/python-libyang/python-libyang.mk b/package/python-libyang/python-libyang.mk
new file mode 100644
index 0000000000..2e4d1f3b90
--- /dev/null
+++ b/package/python-libyang/python-libyang.mk
@@ -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))
diff --git a/support/testing/tests/package/sample_python_libyang.py b/support/testing/tests/package/sample_python_libyang.py
new file mode 100644
index 0000000000..36ca8915cf
--- /dev/null
+++ b/support/testing/tests/package/sample_python_libyang.py
@@ -0,0 +1,41 @@
+# test from https://github.com/CESNET/libyang-python/blob/master/README.rst
+
+import libyang
+
+ctx = libyang.Context()
+
+module = ctx.parse_module_str('''
+module example {
+  namespace "urn:example";
+  prefix "ex";
+  container data {
+    list interface {
+      key name;
+      leaf name {
+        type string;
+      }
+      leaf address {
+        type string;
+      }
+    }
+    leaf hostname {
+      type string;
+    }
+  }
+}
+''')
+
+node = module.parse_data_dict({
+    'data': {
+        'hostname': 'foobar',
+        'interface': [
+            {'name': 'eth0', 'address': '1.2.3.4/24'},
+            {'name': 'lo', 'address': '127.0.0.1'},
+        ],
+    },
+})
+
+print(node.print_mem('xml', pretty=True))
+
+node.free()
+ctx.destroy()
diff --git a/support/testing/tests/package/test_python_libyang.py b/support/testing/tests/package/test_python_libyang.py
new file mode 100644
index 0000000000..c485de2a67
--- /dev/null
+++ b/support/testing/tests/package/test_python_libyang.py
@@ -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)
-- 
2.51.0
:x
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-30 14:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-16 10:24 [Buildroot] [PATCH v2 1/1] package/python-libyang: new package Vincent Cruz
2026-05-30 14:19 ` Thomas Petazzoni via buildroot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.