Skip to content

Commit

Permalink
context: add disable_searchdirs options
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
steweg authored and samuel-gauthier committed Aug 2, 2024
1 parent 32165ef commit f437bfb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libyang/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,8 @@ def test_context_dict(self):
handle = ctx.add_to_dict(orig_str)
self.assertEqual(orig_str, c2str(handle))
ctx.remove_from_dict(orig_str)

def test_ctx_disable_searchdirs(self):
with Context(YANG_DIR, disable_searchdirs=True) as ctx:
with self.assertRaises(LibyangError):
ctx.load_module("yolo-nodetypes")

0 comments on commit f437bfb

Please sign in to comment.