Skip to content

Commit

Permalink
updating nanobind to 2.2 allows simplifying type_caster<SeqId::Option…
Browse files Browse the repository at this point in the history
…alNum>

and nanobind is compatible with Clang 8 again
  • Loading branch information
wojdyr committed Oct 3, 2024
1 parent 3d3eecb commit 5700b31
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
25 changes: 3 additions & 22 deletions python/meta.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
#include <nanobind/stl/detail/nb_optional.h>

namespace gemmi {
std::ostream& operator<< (std::ostream& os, const Entity& ent);
}

namespace nanobind { namespace detail {
template<> struct type_caster<gemmi::SeqId::OptionalNum> {
NB_TYPE_CASTER(gemmi::SeqId::OptionalNum, optional_name(const_name("int")))
using Caster = make_caster<int>;

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<int>(flags), cleanup))
return false;
value = caster.operator cast_t<int>();
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<gemmi::SeqId::OptionalNum>
: optional_caster<gemmi::SeqId::OptionalNum> {};
}} // namespace nanobind::detail

NB_MAKE_OPAQUE(std::vector<gemmi::Helix>)
Expand Down

0 comments on commit 5700b31

Please sign in to comment.