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]>
  • Loading branch information
steweg committed Apr 6, 2024
1 parent ae31525 commit 8fd20a5
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 @@ -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")

0 comments on commit 8fd20a5

Please sign in to comment.