Skip to content

Commit f437bfb

Browse files
stewegsamuel-gauthier
authored andcommitted
context: add disable_searchdirs options
This patch adds support to disable searching of local directories during loading of module. Signed-off-by: Stefan Gula <[email protected]> Signed-off-by: Samuel Gauthier <[email protected]>
1 parent 32165ef commit f437bfb

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

libyang/context.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Context:
2626
def __init__(
2727
self,
2828
search_path: Optional[str] = None,
29+
disable_searchdirs: bool = False,
2930
disable_searchdir_cwd: bool = True,
3031
explicit_compile: Optional[bool] = False,
3132
leafref_extended: bool = False,
@@ -38,6 +39,8 @@ def __init__(
3839
return # already initialized
3940

4041
options = 0
42+
if disable_searchdirs:
43+
options |= lib.LY_CTX_DISABLE_SEARCHDIRS
4144
if disable_searchdir_cwd:
4245
options |= lib.LY_CTX_DISABLE_SEARCHDIR_CWD
4346
if explicit_compile:

tests/test_context.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,8 @@ def test_context_dict(self):
119119
handle = ctx.add_to_dict(orig_str)
120120
self.assertEqual(orig_str, c2str(handle))
121121
ctx.remove_from_dict(orig_str)
122+
123+
def test_ctx_disable_searchdirs(self):
124+
with Context(YANG_DIR, disable_searchdirs=True) as ctx:
125+
with self.assertRaises(LibyangError):
126+
ctx.load_module("yolo-nodetypes")

0 commit comments

Comments
 (0)