From e0012c675ef8f5326b42c34e005c427c418618e8 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Mon, 17 Feb 2025 14:19:41 +0100 Subject: [PATCH 1/3] ci: fix issue status check For some reason, storing the output of curl into a bash variable breaks UTF-8 encoding. Use a shell pipeline to prevent any encoding from happening. Signed-off-by: Robin Jarry --- .github/workflows/ci.yml | 4 ++-- check-commits.sh | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7797c88..27efc7dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,11 +30,11 @@ jobs: check-commits: if: ${{ github.event.pull_request.commits }} - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 env: LYPY_COMMIT_RANGE: "HEAD~${{ github.event.pull_request.commits }}.." steps: - - run: sudo apt-get install git make + - run: sudo apt-get install git make jq curl - uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/check-commits.sh b/check-commits.sh index acf322d9..936236cf 100755 --- a/check-commits.sh +++ b/check-commits.sh @@ -42,11 +42,10 @@ err() { } check_issue() { - json=$(curl -f -X GET -L --no-progress-meter \ + curl -f -X GET -L --no-progress-meter \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - "$api_url/issues/${1##*/}") || return 1 - test $(echo "$json" | jq -r .state) = open + "$api_url/issues/${1##*/}" | jq -r .state | grep -Fx open } for rev in $revisions; do From 8d15d11a91bfe0cfb6ed2730515fa522e5a748a6 Mon Sep 17 00:00:00 2001 From: Matthias Breuninger Date: Mon, 17 Feb 2025 11:57:15 +0100 Subject: [PATCH 2/3] load_module: add missing parameters for ly_ctx_load_module Add parameters to define Yang model revision and features that shall be enabled. Closes: https://github.com/CESNET/libyang-python/issues/101 Signed-off-by: Matthias Breuninger --- libyang/context.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libyang/context.py b/libyang/context.py index fb4a330d..f9bd5a57 100644 --- a/libyang/context.py +++ b/libyang/context.py @@ -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 ( @@ -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") From 672e050d95727133a3fa056165a0ec4bc56d5862 Mon Sep 17 00:00:00 2001 From: Matthias Breuninger Date: Mon, 17 Feb 2025 12:04:55 +0100 Subject: [PATCH 3/3] tests: add test to enable all features Expects that all features are enabled due to the "*" input. Closes: https://github.com/CESNET/libyang-python/issues/101 Signed-off-by: Matthias Breuninger --- tests/test_context.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_context.py b/tests/test_context.py index 8a0412e2..db03c329 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -63,6 +63,13 @@ def test_ctx_load_module(self): mod = ctx.load_module("yolo-system") self.assertIsInstance(mod, Module) + def test_ctx_load_module_with_features(self): + with Context(YANG_DIR) as ctx: + mod = ctx.load_module("yolo-system", None, ["*"]) + self.assertIsInstance(mod, Module) + for f in list(mod.features()): + self.assertTrue(f.state()) + def test_ctx_get_module(self): with Context(YANG_DIR) as ctx: ctx.load_module("yolo-system")