From 8fd20a56289feaaaca023cdefdbd81c7eabe2df2 Mon Sep 17 00:00:00 2001 From: Stefan Gula Date: Wed, 28 Feb 2024 13:09:20 +0100 Subject: [PATCH] context: add disable_searchdirs options This patch adds support to disable searching of local directories during loading of module Signed-off-by: Stefan Gula --- libyang/context.py | 3 +++ tests/test_context.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/libyang/context.py b/libyang/context.py index fa5eb5bf..8d2466e2 100644 --- a/libyang/context.py +++ b/libyang/context.py @@ -26,6 +26,7 @@ class Context: def __init__( self, search_path: Optional[str] = None, + disable_searchdirs: bool = False, disable_searchdir_cwd: bool = True, explicit_compile: Optional[bool] = False, leafref_extended: bool = False, @@ -38,6 +39,8 @@ def __init__( return # already initialized options = 0 + if disable_searchdirs: + options |= lib.LY_CTX_DISABLE_SEARCHDIRS if disable_searchdir_cwd: options |= lib.LY_CTX_DISABLE_SEARCHDIR_CWD if explicit_compile: diff --git a/tests/test_context.py b/tests/test_context.py index 59839284..c05f0a6d 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -111,3 +111,8 @@ def test_ctx_leafref_extended(self): with Context(YANG_DIR, leafref_extended=True) as ctx: mod = ctx.load_module("yolo-leafref-extended") self.assertIsInstance(mod, Module) + + def test_ctx_disable_searchdirs(self): + with Context(YANG_DIR, disable_searchdirs=True) as ctx: + with self.assertRaises(LibyangError): + ctx.load_module("yolo-nodetypes")