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,
QVAL
SomeClass.pxd (uses the enum):
from Scores cimport IDType
cdef extern from "<SomeClass.h>" namespace "OpenMS":
cdef cppclass SomeClass:
void doSomething(IDType t) except + nogil
When 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,
QVAL
This 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+
Problem
When a C++ scoped enum (
enum class) is defined in a.pxdfile without thewrap-attachdirective, autowrap fails with an error like:This happens because
create_foreign_cimports()inDeclResolver.pytreats the enum as if it were a separate class requiring its own.pxdfile.Minimal Example
Scores.pxd:
SomeClass.pxd (uses the enum):
When autowrap processes
SomeClass.pxd, it seesIDTypeas a dependency and tries to findIDType.pxd, which doesn't exist.Current Workaround
Use
wrap-attachto attach the enum to a class:This 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'screate_foreign_cimports()function, which generatescimportstatements for dependencies. When it encounters a scoped enum type, it assumes there's a corresponding.pxdfile 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
.pxdfile, rather than assuming it has its own file.Environment