From 5700b31e7b96558a80dcd925d6b1af39f8cce6f6 Mon Sep 17 00:00:00 2001 From: Marcin Wojdyr Date: Thu, 3 Oct 2024 17:30:39 +0200 Subject: [PATCH] updating nanobind to 2.2 allows simplifying type_caster and nanobind is compatible with Clang 8 again --- .github/workflows/ci.yml | 10 +++++----- pyproject.toml | 2 +- python/meta.h | 25 +++---------------------- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ba35bb7..20c692d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -181,18 +181,18 @@ jobs: - name: run tests under valgrind run: PYTHONMALLOC=malloc valgrind python3 -m unittest discover -v -s tests/ - ubuntu2004_clang9: - name: "Ubuntu 20.04 with Clang 9" + ubuntu2004_clang8: + name: "Ubuntu 20.04 with Clang 8" runs-on: ubuntu-20.04 if: "!contains(github.event.head_commit.message, '[skip ci]')" env: - CC: clang-9 - CXX: clang++-9 + CC: clang-8 + CXX: clang++-8 SKBUILD_CMAKE_ARGS: "-DCMAKE_CXX_STANDARD=11;-DEXTRA_WARNINGS=ON;-DSTANDALONE_PYTHON_MODULE=OFF" SKBUILD_CMAKE_TARGETS: "all;check" steps: - uses: actions/checkout@v4 - - run: sudo apt-get install clang-9 libz-dev python3-pip python3-numpy + - run: sudo apt-get install clang-8 libz-dev python3-pip python3-numpy - name: install nanobind run: | sudo /usr/bin/python3 -m pip install nanobind build diff --git a/pyproject.toml b/pyproject.toml index 0b3fea44..ba9fb8a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [build-system] requires = [ "scikit-build-core ~=0.10.7", - "nanobind >=2.1", + "nanobind >=2.2", "typing-extensions >=4.0; python_version < '3.11'" ] build-backend = "scikit_build_core.build" diff --git a/python/meta.h b/python/meta.h index b4bbf156..0c98d8b2 100644 --- a/python/meta.h +++ b/python/meta.h @@ -1,31 +1,12 @@ +#include namespace gemmi { std::ostream& operator<< (std::ostream& os, const Entity& ent); } namespace nanobind { namespace detail { - template<> struct type_caster { - NB_TYPE_CASTER(gemmi::SeqId::OptionalNum, optional_name(const_name("int"))) - using Caster = make_caster; - - bool from_python(handle src, uint8_t flags, cleanup_list* cleanup) noexcept { - if (src.is_none()) { - value = Value(); - return true; - } - Caster caster; - if (!caster.from_python(src, flags_for_local_caster(flags), cleanup)) - return false; - value = caster.operator cast_t(); - return true; - } - - static handle from_cpp(Value value, rv_policy policy, cleanup_list *cleanup) noexcept { - if (!value) - return none().release(); - return Caster::from_cpp(*value, policy, cleanup); - } - }; + template<> struct type_caster + : optional_caster {}; }} // namespace nanobind::detail NB_MAKE_OPAQUE(std::vector)