Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docstrings to Python interface via SWIG #361

Closed
moschmdt opened this issue Jun 20, 2023 · 6 comments · Fixed by #362
Closed

Add docstrings to Python interface via SWIG #361

moschmdt opened this issue Jun 20, 2023 · 6 comments · Fixed by #362

Comments

@moschmdt
Copy link

At the moment the generated Python SML interface file does not contain the doxygen comments.

Is it possible to add the docstrings via the %feature("autodoc", ...) line, e.g. in the SWIG Python file?

@scijones
Copy link
Contributor

scijones commented Jun 20, 2023

I'll be honest -- I'm not familiar with this part of the code, but our software engineer is coming online soon (~weeks) and I'll run this by him.

@garfieldnate
Copy link
Collaborator

I think this is a great idea! I think the directives go in the CPP file. We would probably need to iterate on the actual documentation a bit, and experiment with the auto doc settings to get what we want.

This feature is supported for Python and Ruby only. Not sure about how the generated docs look for Java and the others.

@moschmdt
Copy link
Author

I think this might also greatly benefit the Pysoarlib project, if this is still maintained?

@moschmdt
Copy link
Author

moschmdt commented Jul 6, 2023

@garfieldnate I got a working solution, but I think I do not have the permission to push a new branch and submit a PR.
It is sufficient to add the following line in the Python interface definition file:

%feature("autodoc","1"); 

I did already test it and it works, for example:

class ElementXML(object):
    r"""Proxy of C++ soarxml::ElementXML class."""

    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr

    @staticmethod
    def IsValidID(str):
        r"""IsValidID(char const * str) -> bool"""
        return _Python_sml_ClientInterface.ElementXML_IsValidID(str)

    def __init__(self, *args):
        r"""
        __init__(ElementXML self) -> ElementXML
        __init__(ElementXML self, ElementXML_Handle hXML) -> ElementXML
        """
        _Python_sml_ClientInterface.ElementXML_swiginit(self, _Python_sml_ClientInterface.new_ElementXML(*args))
    __swig_destroy__ = _Python_sml_ClientInterface.delete_ElementXML

@garfieldnate
Copy link
Collaborator

@moschmdt Cool, thanks! I think I'd go more verbose and use "3" instead of "1". The numpy-style parameter documentation is used by some tools.

You definitely have permissions to send a PR. Just click the little pencil at the top of the file display, edit it how you like, and GitHub should guide you through creating a fork and then sending a PR from the fork (you do not have permissions to edit the file directly; you always have to go through a fork).

@scijones scijones linked a pull request Jul 7, 2023 that will close this issue
scijones added a commit that referenced this issue Jul 7, 2023
Add autodoc feature for Python SWIG bindings. Closes #361
@garfieldnate
Copy link
Collaborator

Revisiting this, I wanted to try adding in the actual doxygen comments contained in the C++ code using SWIG's -doxygen flag, but it only translates the comments contained in the one .i file, ignoring the comments elsewhere. This is a shame, as it would be very useful to have the full documentation available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants