Skip to content

Commit

Permalink
load_module: add missing parameters for ly_ctx_load_module
Browse files Browse the repository at this point in the history
Add parameters to define Yang model revision and features that shall be enabled.

Closes: #101
Signed-off-by: Matthias Breuninger <[email protected]>
  • Loading branch information
rbu9fe authored and rjarry committed Feb 17, 2025
1 parent bdd4cea commit c5af681
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions libyang/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: MIT

import os
from typing import IO, Any, Callable, Iterator, Optional, Tuple, Union
from typing import IO, Any, Callable, Iterator, Optional, Sequence, Tuple, Union

from _libyang import ffi, lib
from .data import (
Expand Down Expand Up @@ -340,10 +340,19 @@ def parse_module_file(
def parse_module_str(self, s: str, fmt: str = "yang", features=None) -> Module:
return self.parse_module(s, IOType.MEMORY, fmt, features)

def load_module(self, name: str) -> Module:
def load_module(
self,
name: str,
revision: Optional[str] = None,
enabled_features: Sequence[str] = (),
) -> Module:
if self.cdata is None:
raise RuntimeError("context already destroyed")
mod = lib.ly_ctx_load_module(self.cdata, str2c(name), ffi.NULL, ffi.NULL)
if enabled_features:
features = tuple([str2c(f) for f in enabled_features] + [ffi.NULL])
else:
features = ffi.NULL
mod = lib.ly_ctx_load_module(self.cdata, str2c(name), str2c(revision), features)
if mod == ffi.NULL:
raise self.error("cannot load module")

Expand Down

0 comments on commit c5af681

Please sign in to comment.