Skip to content

Commit

Permalink
Merge pull request #122 from OpenMS/feature/enum-docs
Browse files Browse the repository at this point in the history
add wrap-doc for Enums including test
  • Loading branch information
jpfeuffer authored Jan 24, 2022
2 parents a966a19 + ca8219d commit 8645068
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
11 changes: 9 additions & 2 deletions autowrap/CodeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ def create_wrapper_for_enum(self, decl, out_codes):
name = "_Py" + decl.name # __ prefix in python are private members
else:
name = decl.name

doc = decl.cpp_decl.annotations.get("wrap-doc", [])
if doc:
doc = '"""\n ' + '\n '.join(doc) + '\n """'

L.info("create wrapper for enum %s" % name)
code = Code.Code()
enum_pxd_code = Code.Code()
Expand All @@ -359,12 +364,14 @@ def create_wrapper_for_enum(self, decl, out_codes):
code.add("""
|
|cdef class $name:
""", name=name)
| $doc
""", name=name, doc=doc)
else: # for scoped enums we use the python enum class
code.add("""
|
|class $name(_PyEnum):
""", name=name)
| $doc
""", name=name, doc=doc)
for (optname, value) in decl.items:
code.add(" $name = $value", name=optname, value=value)

Expand Down
2 changes: 2 additions & 0 deletions tests/test_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def test_enums():
mod = autowrap.Utils.compile_and_import("enummodule", [target, ], include_dirs)

foo = mod.Foo()
my_enum = mod.Foo.MyEnum
assert "Testing Enum documentation." in my_enum.__doc__
myenum_a = mod.Foo.MyEnum.A
myenum2_a = mod.Foo.MyEnum2.A
assert (foo.enumToInt(myenum_a) == 1)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_files/enums.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ cdef extern from "enums.hpp" namespace "Foo":
cpdef enum class MyEnum "Foo::MyEnum":
# wrap-attach:
# Foo
#
# wrap-doc:
# Testing Enum documentation.
A
B
C
Expand Down

0 comments on commit 8645068

Please sign in to comment.