80 Commits

Author SHA1 Message Date
Jan Kundrát
32b9ff8813 Port to libyang v3
...along with a bunch of incompatible API/ABI changes.

I had to make a few tweaks in the build process as well, and these
couldn't be made (and tested!) with separate commits. The test suite was
failing on OS X 13, so I decided to upgrade, because "why not".
2025-04-04 20:38:50 -07:00
Jan Kundrát
ee67ef49c5 CI: pin CMake on Windows due to a dlfcn-win32 build error
Bug: https://github.com/actions/runner-images/issues/11926
2025-04-02 16:06:31 -07:00
Jan Kundrát
3c1e0b3db7 CI: Mac OS X v12 is no more on GitHub runners 2025-04-02 16:06:31 -07:00
Jan Kundrát
68f1d861dd CI: switch to upload/download artifacts v4
Just the usual deprecation churn.

Link: https://github.blog/changelog/2024-04-16-deprecation-notice-v3-of-the-artifact-actions/
2025-04-02 16:06:31 -07:00
Jan Kundrát
df2fff52de libyang: the latest v2 of the C library
...along with CESNET/libyang#2266 which fixes a regression on Windows.
2024-07-07 00:37:01 +02:00
Jan Kundrát
9020db5fb0 CI: unbreak OS X 13 builds
First, let's try using GCC 12 on that platform. That's needed because
the GCC13 builds started failing like this:

 /opt/homebrew/bin/gcc-13 -DLIBYANG_BUILD -I/Users/runner/work/oopt-gnpy-libyang/build-libyang/src -I/Users/runner/work/oopt-gnpy-libyang/oopt-gnpy-libyang/libyang/src -I/Users/runner/work/oopt-gnpy-libyang/oopt-gnpy-libyang/libyang/src/plugins_exts -I/Users/runner/work/oopt-gnpy-libyang/build-libyang/compat -I/opt/homebrew/include -DNDEBUG -O2  -Wall -Wextra -Wpedantic -std=c11 -O3 -DNDEBUG -arch arm64 -isysroot /Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -mmacosx-version-min=13.0 -fPIC -fvisibility=hidden -MD -MT CMakeFiles/yangobj.dir/src/dict.c.o -MF CMakeFiles/yangobj.dir/src/dict.c.o.d -o CMakeFiles/yangobj.dir/src/dict.c.o -c /Users/runner/work/oopt-gnpy-libyang/oopt-gnpy-libyang/libyang/src/dict.c
 In file included from /Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/pthread.h:57,
                  from /Users/runner/work/oopt-gnpy-libyang/oopt-gnpy-libyang/libyang/src/dict.c:19:
 /Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/time.h:198:67: error: macro "__API_AVAILABLE3" passed 4 arguments, but takes just 3
   198 | __API_AVAILABLE(macosx(10.15), ios(13.0), tvos(13.0), watchos(6.0))
       |                                                                   ^

This gets fixed by using GCC 12, and with that, we can *build* the
`libyang` project. What we cannot do is *test* it, because the following
stuff started failing, apparently due to a change of `expect` version:

 58/61 Test #61: yangre ............................***Failed    0.16 sec
 Tests running in interp:  /usr/bin/tclsh
 Tests located in:  /Users/runner/work/oopt-gnpy-libyang/oopt-gnpy-libyang/libyang/tests/yangre
 Tests running in:  /Users/runner/work/oopt-gnpy-libyang/build-libyang/tests/yangre
 Temporary files stored in /Users/runner/work/oopt-gnpy-libyang/build-libyang/tests/yangre
 Test files run in separate interpreters
 Running tests that match:  *
 Skipping test files that match:  l.*.test
 Only running test files that match:  *.test
 Tests began at Wed Jun 19 09:48:46 UTC 2024
 arg.test

 ==== arg_empty Missing arguments FAILED
 ==== Contents of test case:

     ly_cmd_err "" "missing <string> parameter to process"

 ---- Test generated error; Return code was: 1
 ---- Return code should have been one of: 0 2
 ---- errorInfo: invalid command name "try"
     while executing
 "try {
         set results [exec -- $TUT {*}$cmd]
         set status 0
     } trap CHILDSTATUS {results options} {
         # return code is not 0
       ..."
     (procedure "ly_exec" line 3)
     invoked from within
 "ly_exec $cmd"
     (procedure "ly_cmd_err" line 3)
     invoked from within
 "ly_cmd_err "" "missing <string> parameter to process""
     ("uplevel" body line 2)
     invoked from within
 "uplevel 1 $script"
 ---- errorCode: NONE
 ==== arg_empty FAILED

Indeed, there's a small difference between these two image/sw versions:

- https://github.com/actions/runner-images/blob/macos-12/20240602.1/images/macos/macos-12-Readme.md
  This one succeeds, and it says it has got a "Tcl/Tk 8.6.14" installed

- https://github.com/actions/runner-images/blob/macos-13/20240616.1/images/macos/macos-13-Readme.md
  This one fails, and there's no mention of Tcl

So, fix this by always installing `tcl-tk` from Homebrew. As a bonus, we
can now drop the manual workaround for libyang tests "without expect".
Yay, one fewer FIXME.

At this point we have `libyang` the C library built, installed and
tested -- yay. It's time to move to the C++ code, which breaks with a
wonderful internal error in the linker:

 FAILED: libyang-cpp.dylib
 : && /usr/local/bin/g++-12 -Wall -Wextra -pedantic -Woverloaded-virtual -Wimplicit-fallthrough -Wsuggest-override  -O3 -DNDEBUG -arch x86_64 -isysroot /Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -mmacosx-version-min=13.0 -dynamiclib -Wl,-headerpad_max_install_names  -o libyang-cpp.dylib -install_name @rpath/libyang-cpp.dylib CMakeFiles/yang-cpp.dir/src/ChildInstantiables.cpp.o CMakeFiles/yang-cpp.dir/src/Context.cpp.o CMakeFiles/yang-cpp.dir/src/DataNode.cpp.o CMakeFiles/yang-cpp.dir/src/Enum.cpp.o CMakeFiles/yang-cpp.dir/src/Collection.cpp.o CMakeFiles/yang-cpp.dir/src/Module.cpp.o CMakeFiles/yang-cpp.dir/src/SchemaNode.cpp.o CMakeFiles/yang-cpp.dir/src/Set.cpp.o CMakeFiles/yang-cpp.dir/src/Type.cpp.o CMakeFiles/yang-cpp.dir/src/Utils.cpp.o CMakeFiles/yang-cpp.dir/src/utils/exception.cpp.o CMakeFiles/yang-cpp.dir/src/utils/ref_count.cpp.o CMakeFiles/yang-cpp.dir/src/utils/newPath.cpp.o  -Wl,-rpath,/Users/runner/work/oopt-gnpy-libyang/target/lib  /Users/runner/work/oopt-gnpy-libyang/target/lib/libyang.dylib && :
 -macosx_version_min has been renamed to -macos_version_min
 0  0x10dd0cf43  __assert_rtn + 64
 1  0x10dc0ef43  ld::AtomPlacement::findAtom(unsigned char, unsigned long long, ld::AtomPlacement::AtomLoc const*&, long long&) const + 1411
 2  0x10dc2b431  ld::InputFiles::SliceParser::parseObjectFile(mach_o::Header const*) const + 19745
 3  0x10dc3bb71  ld::InputFiles::parseAllFiles(void (ld::AtomFile const*) block_pointer)::$_7::operator()(unsigned long, ld::FileInfo const&) const + 657
 4  0x7ff806e9f066  _dispatch_client_callout2 + 8
 5  0x7ff806eb218f  _dispatch_apply_invoke_and_wait + 213
 6  0x7ff806eb1692  _dispatch_apply_with_attr_f + 1207
 7  0x7ff806eb1847  dispatch_apply + 45
 8  0x10dcd4972  ld::AtomFileConsolidator::parseFiles(bool) + 370
 9  0x10dc5bd67  main + 12263
 ld: Assertion failed: (resultIndex < sectData.atoms.size()), function findAtom, file Relocations.cpp, line 1336.
 collect2: error: ld returned 1 exit status

Now, this looks a bug in the particular version of XCode that's used in
this particular release of the Mac OS X GitHub CI runner, and the fix is
apparently just to use a different version. That version however
apparently cannot be the 15.1, because C++ exceptions are apparently
FUBAR in there:

 1/4 Test #1: test_context .....................Subprocess aborted***Exception:   0.02 sec
 libyang[0]: Unexpected end-of-input. (path: Line number 1.)
 terminate called after throwing an instance of 'libyang::ErrorWithCode'
   what():  Can't parse module: LY_EVALID
 [doctest] doctest version is "2.4.11"
 [doctest] run with "--help" for options
 ===============================================================================
 /Users/runner/work/oopt-gnpy-libyang/oopt-gnpy-libyang/libyang-cpp/tests/context.cpp:66:
 TEST CASE:  context
   parseModule
   invalid

 /Users/runner/work/oopt-gnpy-libyang/oopt-gnpy-libyang/libyang-cpp/tests/context.cpp:66: FATAL ERROR: test case CRASHED: SIGABRT - Abort (abnormal termination) signal

 ===============================================================================
 /Users/runner/work/oopt-gnpy-libyang/oopt-gnpy-libyang/libyang-cpp/tests/context.cpp:66:
 TEST CASE:  context

 DEEPEST SUBCASE STACK REACHED (DIFFERENT FROM THE CURRENT ONE):
   parseModule
   invalid

 ===============================================================================
 [doctest] test cases: 1 | 0 passed | 1 failed | 1 skipped
 [doctest] assertions: 4 | 4 passed | 0 failed |
 [doctest] Status: FAILURE!

 2/4 Test #4: test_unsafe ......................***Exception: SegFault  0.02 sec
 libunwind: _Unwind_GetDataRelBase - _Unwind_GetDataRelBase() not implemented

At that point everything builds, but macOS 12 wheels fail to install.
That's because "something" has changed in the CI images, and the
provided Python interpreter does not use the 12_04 tag, but it instead
stops at version 12_0, like this:

 $ pip install -vvv --only-binary :all: --no-index --find-links=${GITHUB_WORKSPACE//\\//}/wheelhouse oopt-gnpy-libyang
 ...
 Skipping link: none of the wheel's tags (cp311-cp311-macosx_12_4_x86_64) are compatible (run pip debug --verbose to show compatible tags): file:///Users/runner/work/oopt-gnpy-libyang/oopt-gnpy-libyang/wheelhouse/oopt_gnpy_libyang-0.0.15.dev1%2Bga16eba9-cp311-cp311-macosx_12_4_x86_64.whl
 ...
 $ pip debug --verbose
 ...
 Compatible tags: 2264
  cp311-cp311-macosx_12_0_x86_64
  cp311-cp311-macosx_12_0_intel
  cp311-cp311-macosx_12_0_fat64
  cp311-cp311-macosx_12_0_fat32
  cp311-cp311-macosx_12_0_universal2
  cp311-cp311-macosx_12_0_universal
 ...

Since there's been no reason given on why we might need version 12.4
instead of just 12.0 in the original commit which added support for Mac
OS buidls in the first place, let's just call this 12.0 and hope that
the ABI overlords which control the C++ STL are on our side.

Bug: https://github.com/actions/runner-images/issues/9997
Bug: https://forums.developer.apple.com/forums/thread/737707
Bug: https://github.com/actions/runner-images/issues/9273
Bug: https://github.com/Homebrew/homebrew-core/issues/145991
Bug: https://stackoverflow.com/questions/78017671/runtime-issues-with-stdoptional-in-gcc-on-m2-mac
2024-06-19 16:30:16 +02:00
Jan Kundrát
26a9f5a559 Sync with upstream v0.0.14 2024-01-24 18:09:40 +01:00
Jan Kundrát
77db42ffa5 API change: sync with upstream repos
Warning, Context.get_module's API changed, the revision no longer
default to `None` because passing `None` explicitly asks for a module
with no associated revision. Use `Context.get_module_latest` when the
previous behavior is needed. This is a deliberate change from the C++
library; only in C++ a compiler catches this :).

See-also: https://gerrit.cesnet.cz/c/CzechLight/libyang-cpp/+/6732
See-also: https://gerrit.cesnet.cz/c/CzechLight/libyang-cpp/+/6733
2024-01-16 11:32:05 +01:00
Jan Kundrát
7859ed6ea3 Mark Python 3.12 as supported v0.0.13 2023-11-15 20:11:38 +01:00
Jan Kundrát
eb4a077bb7 Build on Apple M1 CPUs as well
...so that we can build a native binary wheel for this platform.
Technically speaking, cross-builds should have been possible "for
years", but I was not able to get one running successfully (see that
removed comment). Let's go native.

This CI runner is currently a paid one, so forks of this repo might not
pass all actions.
v0.0.12
2023-11-15 18:45:43 +01:00
Jan Kundrát
2ad9fa8b5d apple: use modern compilers on these machines
...and fix the deployment target, too
2023-11-15 18:43:34 +01:00
Jan Kundrát
5b4d4a0a6c Apple: require newest OS for the newest Python
I think this is a reasonable thing which should limit the number of
wasted CPU cycles. If someone can upgrade to a new enough Python, let's
hope they can update to a new enough OS image to run it.
2023-11-15 18:28:22 +01:00
Jan Kundrát
4082ba4f95 CI: enable Python 3.12 builds 2023-11-15 17:35:16 +01:00
Jan Kundrát
c1543b9255 Sync libyang and libyang-cpp 2023-11-15 17:30:11 +01:00
Jan Kundrát
bf1a2fed8b Sync libayng and libyang-cpp 2023-09-29 14:57:18 +02:00
Jan Kundrát
5ae3a1a909 Sync with upstream v0.0.11 2023-09-05 14:53:53 +02:00
Jan Kundrát
e629297a2d creating new data nodes 2023-09-01 17:59:11 +02:00
Jan Kundrát
2816765c14 Basic schema-level queries 2023-09-01 16:18:11 +02:00
Jan Kundrát
55ee7a14eb Allow easy checking for element existence 2023-09-01 16:18:11 +02:00
Jan Kundrát
96b2178d47 Add support for reading enumerations 2023-09-01 16:18:11 +02:00
Jan Kundrát
f85ec36353 Working with the empty type 2023-09-01 16:18:11 +02:00
Jan Kundrát
feae818234 Add support for reading the decimal64 data type 2023-09-01 16:06:34 +02:00
Jan Kundrát
f7b64f68e4 Add support for relative path lookup starting at root 2023-09-01 15:25:58 +02:00
Jan Kundrát
3a1bc911a8 Export DataNode::findPath with no restrictions on result size 2023-09-01 15:25:58 +02:00
Jan Kundrát
a825729856 use Python's default snake_case naming convention consistently 2023-09-01 15:25:57 +02:00
Jan Kundrát
52d22728df libyang: support backslashes in file names on Windows
There are some failures with `gnpy` on Windows:

 ================================== FAILURES ===================================
 ____________ test_lint_yang[ietf-network-topology@2018-02-26.yang] ____________

 yang_model = WindowsPath('D:/a/oopt-gnpy/oopt-gnpy/gnpy/yang/ext/ietf-network-topology@2018-02-26.yang')

     @pytest.mark.parametrize("yang_model", [x for x in external_path().glob('*.yang')] + [x for x in model_path().glob('*.yang')], ids=_get_basename)
     def test_lint_yang(yang_model):
         '''Run a linter on each YANG model'''
         c = ly.Context(str(external_path()) + os.pathsep + str(model_path()),
                        ly.ContextOptions.NoYangLibrary | ly.ContextOptions.DisableSearchCwd)
         assert c.parse_module(yang_model, ly.SchemaFormat.YANG) is not None
 >       assert c.errors() == []
 E       assert <[TypeError("unhashable type: 'instancemethod'") raised in repr()] list object at 0x1880e5958c0> == []
 E         (pytest_assertion plugin: representation of details failed: C:\hostedtoolcache\windows\Python\3.11.4\x64\Lib\pprint.py:178: TypeError: unhashable type: 'instancemethod'.
 E          Probably an object has a faulty __repr__.)

 tests\test_yang_lint.py:30: AssertionError
 ---------------------------- Captured stderr call -----------------------------
 libyang[1]: File name "D:\a\oopt-gnpy\oopt-gnpy\gnpy\yang\ext\ietf-network-topology@2018-02-26.yang" does not match module name "ietf-network-topology".
 ________________ test_lint_yang[ietf-network@2018-02-26.yang] _________________

That complaint about __repr__ is an impedance mismatch between pybind11
and Python (pybind/pybind11#2722), but in this case that whole thing is
triggered through a bug in libyang which assumes that the directory
separator is always `/`.

Bug: https://github.com/CESNET/libyang/pull/2093
2023-08-31 21:57:01 +02:00
Jan Kundrát
532744ae2c CI: modernize upload to PyPI
...through some magic integration pixie dust, I mean, OIDC short-lived
tokens that should just happen, as per the docs.
v0.0.10
2023-08-31 17:03:25 +02:00
Jan Kundrát
ddec88670a Sync with upstreams v0.0.9 2023-08-31 15:23:17 +02:00
Jan Kundrát
8b4e00627d Sync with upstream v0.0.8 2023-07-13 12:49:43 +02:00
Jan Kundrát
2e66616fc2 Sync with upstream libyang 2023-06-21 13:18:43 +02:00
Jan Kundrát
2cd967652e export log options to Python 2023-06-13 17:03:38 +02:00
Jan Kundrát
0552bb3187 Sync with upstream 2023-06-13 17:03:18 +02:00
Jan Kundrát
2848ca18ca sync with upstream 2023-06-13 01:43:19 +02:00
Jan Kundrát
a4f4c51635 sync with upstream 2023-06-05 13:16:47 +02:00
Jan Kundrát
1addfe4933 sync with upstream v0.0.7 2023-05-30 12:11:55 +02:00
Jan Kundrát
10687e3f28 new validation/parsing flags in libyang-cpp 2023-05-16 23:07:23 +02:00
Jan Kundrát
6bf5a8729b Export libyang version info
There's nothing like that in the libyang-cpp yet, so that one is not
made available.
2023-05-16 19:03:23 +02:00
Jan Kundrát
b6763ba61c explicit module loading without callbacks 2023-05-16 19:03:23 +02:00
Jan Kundrát
9e5914d9c3 clean up obsolete code 2023-05-16 19:03:23 +02:00
Jan Kundrát
3de2a328f2 refactor: py::overload_cast 2023-05-16 19:03:23 +02:00
Jan Kundrát
9a37f1ec8f refactor: namespace py = pybind11
...just to align with the upstream docs.
2023-05-16 19:03:23 +02:00
Jan Kundrát
b2eaeb4fe5 refactor: using namespace libyang 2023-05-16 19:03:23 +02:00
Jan Kundrát
dc8e5259d3 Adapt to upstream C++ overloading 2023-05-16 19:03:23 +02:00
Jan Kundrát
1734421544 Update libyang 2023-05-16 18:15:05 +02:00
Jan Kundrát
d18d1ab4ea Sync with upstream
I'm deliberately not checking whether the headers are self-contained
because it seems that MSVC has different rules about
std::optional/std::variant intrinsic traits compared to GCC and clang.

Here's how to reproduce via GitHub actions:

 cmake --build . --target=all_verify_interface_header_sets -j${{ steps.cpu-cores.outputs.count }} --config ${{ matrix.build_type }}
v0.0.6
2023-05-09 17:17:26 +02:00
Jan Kundrát
a3d8b75cfc Update copyright year 2023-02-05 01:09:28 +01:00
Jan Kundrát
be917803d9 CI: adapt to github changes for ::set-output
Bug: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
v0.0.5
2023-02-05 00:14:14 +01:00
Jan Kundrát
6507fa5138 Build for Python 3.11 as well
On Windows and OS X, this simply adds a bunch of extra builds. On Linux,
I'm also bumping the manylinux tag because Python 3.11 is newer than the
distro in question. This means that there will be no builds for "new
Python on old distros" because one has to draw a line somewhere.
Effectively, wheels for Linux Python 3.11 will therefore require glibc
2.35.
2023-02-04 22:58:46 +01:00
Jan Kundrát
54489cea62 Use pybind11 from PIP
I don't have the details about why exactly that version of pybind11 on
Ubuntu 20.04 broke down, but here's how it ended up on Ubuntu 22.04 when
trying to use Python 3.11:

 In file included from /usr/include/pybind11/cast.h:16,
                  from /usr/include/pybind11/attr.h:13,
                  from /usr/include/pybind11/pybind11.h:13,
                  from /usr/include/pybind11/functional.h:12,
                  from /home/runner/work/oopt-gnpy-libyang/oopt-gnpy-libyang/oopt-gnpy-libyang.cpp:1:
 /usr/include/pybind11/detail/type_caster_base.h: In function ‘std::string pybind11::detail::error_string()’:
 /usr/include/pybind11/detail/type_caster_base.h:482:26: error: invalid use of incomplete type ‘PyFrameObject’ {aka ‘struct _frame’}
   482 |             frame = frame->f_back;
       |                          ^~
 In file included from /opt/hostedtoolcache/Python/3.11.1/x64/include/python3.11/Python.h:42,
                  from /usr/include/pybind11/detail/common.h:215,
                  from /usr/include/pybind11/pytypes.h:12,
                  from /usr/include/pybind11/cast.h:13,
                  from /usr/include/pybind11/attr.h:13,
                  from /usr/include/pybind11/pybind11.h:13,
                  from /usr/include/pybind11/functional.h:12,
                  from /home/runner/work/oopt-gnpy-libyang/oopt-gnpy-libyang/oopt-gnpy-libyang.cpp:1:
 /opt/hostedtoolcache/Python/3.11.1/x64/include/python3.11/pytypedefs.h:22:16: note: forward declaration of ‘PyFrameObject’ {aka ‘struct _frame’}
    22 | typedef struct _frame PyFrameObject;
       |                ^~~~~~

On Windows, it failed because (apparently) vcpkg patches Python
detection as per https://github.com/microsoft/vcpkg/issues/23796. The
build would fail like this (vcpkg Pytohn is 3.10, the system-selected
one is 3.11):

 CMake Error at C:/t/build-env-1a5f954n/Lib/site-packages/cmake/data/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
   Could NOT find Python (missing: Development.Module) (found suitable version
   "3.11.1", minimum required is "3.8")
 Call Stack (most recent call first):
   C:/t/build-env-1a5f954n/Lib/site-packages/cmake/data/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
   C:/t/build-env-1a5f954n/Lib/site-packages/cmake/data/share/cmake-3.25/Modules/FindPython/Support.cmake:3245 (find_package_handle_standard_args)
   C:/t/build-env-1a5f954n/Lib/site-packages/cmake/data/share/cmake-3.25/Modules/FindPython.cmake:519 (include)

So let's just use the PIP magic and hope for the best.
2023-02-04 22:58:46 +01:00
Jan Kundrát
d940700a20 python prefers list over dict for setup.py classifiers
Bug: https://bugs.python.org/issue19610
2023-02-03 15:54:48 +01:00