Skip to content

Standalone scoped enums (enum class) without wrap-attach cause 'pxd not found' error #248

@timosachsenberg

Description

@timosachsenberg

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+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions