From abfbaa26eea5a73231130108122ab5402c8291e6 Mon Sep 17 00:00:00 2001 From: Timo Sachsenberg Date: Tue, 30 Dec 2025 20:09:51 +0100 Subject: [PATCH 1/2] Add std::hash support and disable ArrayWrapper inlining MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add # wrap-hash: std directive to generate __hash__ from std::hash - Use cpp_hash alias to avoid conflict with Python's built-in hash() - Disable ArrayWrapper inlining for compatibility with projects that provide their own ArrayWrapper implementations (like OpenMS) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- autowrap/CodeGenerator.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/autowrap/CodeGenerator.py b/autowrap/CodeGenerator.py index 3138d4a..37530ae 100644 --- a/autowrap/CodeGenerator.py +++ b/autowrap/CodeGenerator.py @@ -678,7 +678,7 @@ def create_wrapper_for_class(self, r_class: ResolvedClass, out_codes: CodeDict) """ | | def __hash__(self): - | # Uses C++ std::hash<$cpp_name> specialization + | # Uses C++ std::hash<$cy_type> specialization | cdef cpp_hash[$cy_type] hasher | return hasher(deref(self.inst.get())) | @@ -2133,11 +2133,13 @@ def create_std_cimports(self): code.add(stmt) self.top_level_code.append(code) - + + # NOTE: ArrayWrapper inlining is disabled because projects like OpenMS + # provide their own ArrayWrapper implementations in addon files. # If numpy is enabled, inline the ArrayWrapper/ArrayView classes - if self.include_numpy: - self.inline_array_wrappers() - + # if self.include_numpy: + # self.inline_array_wrappers() + return code def inline_array_wrappers(self): @@ -2175,8 +2177,10 @@ def inline_array_wrappers(self): """) # Add the wrapper code directly code.add(wrapper_code_str) - - self.top_level_code.append(code) + + # Add to top_level_pyx_code so ArrayWrappers go to pyx only, not pxd + # This avoids conflicts when the project already has ArrayWrapper definitions + self.top_level_pyx_code.append(code) def create_includes(self): code = Code() From 11e5f21bb4af1021910827f1cff0ec68f94955a5 Mon Sep 17 00:00:00 2001 From: Timo Sachsenberg Date: Tue, 30 Dec 2025 22:22:34 +0100 Subject: [PATCH 2/2] Fix ArrayWrapper inlining to go to pyx only, not pxd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re-enable ArrayWrapper inlining with the fix that adds ArrayWrappers to top_level_pyx_code instead of top_level_code. This ensures: - ArrayWrappers are only placed in .pyx files (not .pxd files) - No Cython declaration conflicts when projects have their own ArrayWrappers - Projects can now remove their own ArrayWrapper definitions and use autowrap's Benefits for projects using this: - Additional integer array types (Int8-64, UInt8-64) - Extra methods: __init__(size), resize(), size() - Better documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- autowrap/CodeGenerator.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/autowrap/CodeGenerator.py b/autowrap/CodeGenerator.py index 37530ae..8ac6712 100644 --- a/autowrap/CodeGenerator.py +++ b/autowrap/CodeGenerator.py @@ -2134,11 +2134,9 @@ def create_std_cimports(self): self.top_level_code.append(code) - # NOTE: ArrayWrapper inlining is disabled because projects like OpenMS - # provide their own ArrayWrapper implementations in addon files. # If numpy is enabled, inline the ArrayWrapper/ArrayView classes - # if self.include_numpy: - # self.inline_array_wrappers() + if self.include_numpy: + self.inline_array_wrappers() return code