Skip to content

Commit 8db5830

Browse files
authored
Fix handling of wrap-ignore for base classes to avoid invalid cimport in derived classes
Previously, autowrap would generate a `from ... cimport` statement for derived classes even if their base class was marked with `wrap-ignore`. This caused build failures due to missing .pxd files for ignored base classes, especially when those were the only contents of their file. This change checks whether the base class has the `wrap-ignore` annotation and, if so, suppresses the cimport generation for the derived class. This prevents erroneous imports like: From ._pyopenms_20 cimport SpectrumAccessTransforming When SpectrumAccessTransforming is intentionally not wrapped. Also adds an optional debug message to clarify when this skip occurs. This fix preserves expected behaviour for abstract base classes and improves compatibility when selectively wrapping a class hierarchy. Fixes: #194
1 parent 92598a8 commit 8db5830

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

autowrap/CodeGenerator.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,15 @@ def create_foreign_cimports(self):
19511951
if resolved.__class__ in (ResolvedClass,):
19521952
# Skip classes that explicitely should not have a pxd
19531953
# import statement (abstract base classes and the like)
1954-
if not resolved.no_pxd_import:
1954+
ignore_base = False
1955+
# Check if this class has a base class and that base class is wrap-ignored
1956+
if resolved.cpp_decl.parent:
1957+
base_class = resolved.cpp_decl.parent
1958+
if base_class.annotations.get("wrap-ignore"):
1959+
ignore_base = True
1960+
print(f"[autowrap] Skipping pxd import for derived class '{resolved.name}' "
1961+
f"because base '{base_class.name}' is wrap-ignored.")
1962+
if not resolved.no_pxd_import and not ignore_base:
19551963
if resolved.cpp_decl.annotations.get("wrap-attach"):
19561964
code.add("from $mname cimport __$name", locals())
19571965
else:

0 commit comments

Comments
 (0)