-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Problem
When a C++ scoped enum (enum class) is defined in a .pxd file without the wrap-attach directive, autowrap fails with an error like:
FileNotFoundError: IDScoreType.pxd not found
This happens because create_foreign_cimports() in DeclResolver.py treats the enum as if it were a separate class requiring its own .pxd file.
Minimal Example
Scores.pxd:
cdef extern from "<OpenMS/ANALYSIS/ID/Scores.h>" namespace "OpenMS::Scores":
cdef enum class IDType "OpenMS::Scores::IDType":
# No wrap-attach directive
RAW,
PEP,
QVALSomeClass.pxd (uses the enum):
from Scores cimport IDType
cdef extern from "<SomeClass.h>" namespace "OpenMS":
cdef cppclass SomeClass:
void doSomething(IDType t) except + nogilWhen autowrap processes SomeClass.pxd, it sees IDType as a dependency and tries to find IDType.pxd, which doesn't exist.
Current Workaround
Use wrap-attach to attach the enum to a class:
cdef enum class IDType "OpenMS::Scores::IDType":
# wrap-attach:
# Scores
RAW,
PEP,
QVALThis works, but requires creating a wrapper class if one doesn't naturally exist.
Expected Behavior
Standalone scoped enums should be wrapped without requiring wrap-attach. The enum should be accessible directly (e.g., pyopenms.IDType.PEP) rather than requiring attachment to an arbitrary class.
Technical Details
The issue appears to be in DeclResolver.py's create_foreign_cimports() function, which generates cimport statements for dependencies. When it encounters a scoped enum type, it assumes there's a corresponding .pxd file for it.
Possible fix: When resolving dependencies, check if the type is a scoped enum defined in the current compilation unit or in an already-imported .pxd file, rather than assuming it has its own file.
Environment
- autowrap version: 0.27.0
- Cython version: 3.0.x
- Python version: 3.10+