From 48d3b517add953884cf5ee91efe8f7586dd06c29 Mon Sep 17 00:00:00 2001 From: Jeremie Leska Date: Thu, 15 Oct 2026 16:35:28 +0200 Subject: [PATCH] context: add the path to internal libyang modules The ly_ctx_new requires the internal libyang modules to create a context. Add the ly_yang_module_dir function to the cffi. In context.py, pass the result of this function to the ly_ctx_new calls. Signed-off-by: Jeremie Leska --- cffi/cdefs.h | 1 + libyang/context.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/cffi/cdefs.h b/cffi/cdefs.h index afabe26..333abb2 100644 --- a/cffi/cdefs.h +++ b/cffi/cdefs.h @@ -40,6 +40,7 @@ typedef enum { LY_ERR ly_ctx_new(const char *, uint16_t, struct ly_ctx **); void ly_ctx_destroy(struct ly_ctx *); int ly_ctx_set_searchdir(struct ly_ctx *, const char *); +const char *ly_yang_module_dir(void); typedef enum { diff --git a/libyang/context.py b/libyang/context.py index d0309d7..f446651 100644 --- a/libyang/context.py +++ b/libyang/context.py @@ -251,6 +251,11 @@ def __init__( search_paths.extend(search_path.strip(": \t\r\n'\"").split(":")) search_paths = [path for path in search_paths if os.path.isdir(path)] + + module_dir = c2str(lib.ly_yang_module_dir()) + if module_dir: + search_paths.insert(0, module_dir) + search_path = ":".join(search_paths) if search_paths else None if yanglib_path is None: