Skip to content

Commit 5700b31

Browse files
committed
updating nanobind to 2.2 allows simplifying type_caster<SeqId::OptionalNum>
and nanobind is compatible with Clang 8 again
1 parent 3d3eecb commit 5700b31

File tree

3 files changed

+9
-28
lines changed

3 files changed

+9
-28
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,18 @@ jobs:
181181
- name: run tests under valgrind
182182
run: PYTHONMALLOC=malloc valgrind python3 -m unittest discover -v -s tests/
183183

184-
ubuntu2004_clang9:
185-
name: "Ubuntu 20.04 with Clang 9"
184+
ubuntu2004_clang8:
185+
name: "Ubuntu 20.04 with Clang 8"
186186
runs-on: ubuntu-20.04
187187
if: "!contains(github.event.head_commit.message, '[skip ci]')"
188188
env:
189-
CC: clang-9
190-
CXX: clang++-9
189+
CC: clang-8
190+
CXX: clang++-8
191191
SKBUILD_CMAKE_ARGS: "-DCMAKE_CXX_STANDARD=11;-DEXTRA_WARNINGS=ON;-DSTANDALONE_PYTHON_MODULE=OFF"
192192
SKBUILD_CMAKE_TARGETS: "all;check"
193193
steps:
194194
- uses: actions/checkout@v4
195-
- run: sudo apt-get install clang-9 libz-dev python3-pip python3-numpy
195+
- run: sudo apt-get install clang-8 libz-dev python3-pip python3-numpy
196196
- name: install nanobind
197197
run: |
198198
sudo /usr/bin/python3 -m pip install nanobind build

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[build-system]
22
requires = [
33
"scikit-build-core ~=0.10.7",
4-
"nanobind >=2.1",
4+
"nanobind >=2.2",
55
"typing-extensions >=4.0; python_version < '3.11'"
66
]
77
build-backend = "scikit_build_core.build"

python/meta.h

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
1+
#include <nanobind/stl/detail/nb_optional.h>
12

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

67
namespace nanobind { namespace detail {
7-
template<> struct type_caster<gemmi::SeqId::OptionalNum> {
8-
NB_TYPE_CASTER(gemmi::SeqId::OptionalNum, optional_name(const_name("int")))
9-
using Caster = make_caster<int>;
10-
11-
bool from_python(handle src, uint8_t flags, cleanup_list* cleanup) noexcept {
12-
if (src.is_none()) {
13-
value = Value();
14-
return true;
15-
}
16-
Caster caster;
17-
if (!caster.from_python(src, flags_for_local_caster<int>(flags), cleanup))
18-
return false;
19-
value = caster.operator cast_t<int>();
20-
return true;
21-
}
22-
23-
static handle from_cpp(Value value, rv_policy policy, cleanup_list *cleanup) noexcept {
24-
if (!value)
25-
return none().release();
26-
return Caster::from_cpp(*value, policy, cleanup);
27-
}
28-
};
8+
template<> struct type_caster<gemmi::SeqId::OptionalNum>
9+
: optional_caster<gemmi::SeqId::OptionalNum> {};
2910
}} // namespace nanobind::detail
3011

3112
NB_MAKE_OPAQUE(std::vector<gemmi::Helix>)

0 commit comments

Comments
 (0)