Skip to content

Commit d2363c9

Browse files
context: fix creation failure without libyang module dir
Since libyang commit be5a07fea89d ("context UPDATE remove binary internal modules"), ly_ctx_new() reads its internal modules from the search dirs. So creating a context fails when ly_yang_module_dir() is not one of them: >>> libyang.Context() libyang.util.LibyangError: cannot create context Always add this dir at the end of the search path. User dirs are still searched first, and libyang ignores a dir that is given twice. ly_yang_module_dir() was added by the same libyang commit, and the first release with it is v5.8.6, with soversion 5.5.5. So require this version. Closes: #172 Closes: #173 Suggested-by: Pepa Hajek <hajekpepa@gmail.com> Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com>
1 parent 72c3915 commit d2363c9

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎cffi/cdefs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef enum {
4040
LY_ERR ly_ctx_new(const char *, uint16_t, struct ly_ctx **);
4141
void ly_ctx_destroy(struct ly_ctx *);
4242
int ly_ctx_set_searchdir(struct ly_ctx *, const char *);
43+
const char *ly_yang_module_dir(void);
4344
LY_ERR ly_ctx_set_options(struct ly_ctx *, uint32_t);
4445

4546
typedef enum

‎cffi/source.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
#include <libyang/plugins.h>
88
#include <libyang/version.h>
99

10-
#if LY_VERSION_MAJOR * 10000 + LY_VERSION_MINOR * 100 + LY_VERSION_MICRO < 50000
11-
#error "This version of libyang bindings only works with libyang soversion 5.0.0+"
10+
#if LY_VERSION_MAJOR * 10000 + LY_VERSION_MINOR * 100 + LY_VERSION_MICRO < 50505
11+
#error "This version of libyang bindings only works with libyang soversion 5.5.5+"
1212
#endif

‎libyang/context.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ def __init__(
247247
)
248248
if search_path:
249249
search_paths.extend(search_path.strip(": \t\r\n'\"").split(":"))
250+
# libyang loads its internal modules from the search dirs
251+
search_paths.append(c2str(lib.ly_yang_module_dir()))
250252

251253
search_paths = [path for path in search_paths if os.path.isdir(path)]
252254
search_path = ":".join(search_paths) if search_paths else None

0 commit comments

Comments
 (0)