Skip to content

Commit

Permalink
Merge pull request #170 from OpenMS/upd/docstrings
Browse files Browse the repository at this point in the history
Update docstrings for overloads in pyx using autodoc syntax.
  • Loading branch information
jpfeuffer authored Oct 29, 2022
2 parents ba79635 + 37e893a commit dc46331
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
autowrap 0.22.10

- Revamped docstrings for overloaded methods in generated pyx files. They use RST and sphinx.autodoc syntax now.
14 changes: 9 additions & 5 deletions autowrap/CodeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,24 +931,28 @@ def _create_overloaded_method_decl(
# Add autodoc docstring signatures first: https://github.com/sphinx-doc/sphinx/pull/7748
sig = f"{py_name}(self, {args_typestub_str}) {return_type}"
signatures.append(sig)
docstrings.add(sig)
#docstrings.add(sig)

docstrings.add("")
#docstrings.add("")

for method, sig in zip(methods, signatures):
docstrings.add(".. rubric:: Overload:")
docstrings.add(".. py:function:: %s" % sig)
docstrings.add(" :noindex:")
docstrings.add("")
# Now add Cython signatures with additional description for each overload (if available)
extra_doc = method.cpp_decl.annotations.get("wrap-doc", None)
if extra_doc is not None:
docstrings.add("- Overload: %s" % sig)
docstrings.add(extra_doc)
docstrings.add("")
docstrings.extend(extra_doc)
docstrings.add("")

docstring_as_str = docstrings.render(indent=8)
method_code.add(
"""
|
|def $py_name(self, *args $kwargs):
| \"\"\"\n$docstring_as_str
|
| \"\"\"
""",
locals(),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_code_generator_libcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_libcpp():
)
assert libcpp.__name__ == "libcpp"
print(dir(libcpp))
assert len(libcpp.LibCppTest.__doc__) == 213
assert len(libcpp.LibCppTest.__doc__) == 214
assert len(libcpp.LibCppTest.twist.__doc__) == 111
assert len(libcpp.LibCppTest.gett.__doc__) == 72
assert len(libcpp.ABS_Impl1.__doc__) == 90
Expand Down
2 changes: 1 addition & 1 deletion tests/test_code_generator_minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def output_conversion(self, cpp_type, input_cpp_var, output_py_var):

minimal = wrapped.Minimal()

assert len(minimal.compute.__doc__) == 536
assert len(minimal.compute.__doc__) == 681

assert len(minimal.run.__doc__) == 143

Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/inherited.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Generated with autowrap 0.22.9 and Cython (Parser) 0.29.32
#Generated with autowrap 0.22.10 and Cython (Parser) 0.29.32
#cython: c_string_encoding=ascii
#cython: embedsignature=False
from enum import Enum as _PyEnum
Expand Down
2 changes: 1 addition & 1 deletion tests/test_full_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def test_full_lib(tmpdir):
# Check doc string
assert "Inherits from" in moduleB.Bklass.__doc__
assert "some doc!" in moduleB.Bklass.__doc__
assert len(moduleB.Bklass.__doc__) == 92, len(moduleB.Bklass.__doc__)
assert len(moduleB.Bklass.__doc__) == 93, len(moduleB.Bklass.__doc__)

Bsecond = moduleB.B_second(8)
Dsecond = moduleCD.D_second(11)
Expand Down

0 comments on commit dc46331

Please sign in to comment.