Using SWIG to generate a Python interface to a C++ application, is there any way to have it comment the functions in the generated .py file? I’m actually pulling in an entire .h file into the .i file, but for a small example:
%module example
bool do_something_interesting(int number, string text);
swig -python example.i Generates:
...
def do_something_interesting(*args):
return _example.do_something_interesting(*args)
do_something_interesting = _example.do_something_interesting
Ideally, I would like it to automatically add a comment with the original method signature
#bool do_something_interesting(int number, string text)
def do_something_interesting(*args):
return _example.do_something_interesting(*args)
do_something_interesting = _example.do_something_interesting
But I would be perfectly amenable to writing my own comment somewhere (particularly if the comment could somehow be in the .h file). I thought %pythonprepend might be a possible solution, but it inserts code inside the function definition rather than before it.
EDIT: Here’s what I came up with in the .h file. Not the prettiest thing ever but it’ll do:
#ifdef SWIG
%pythonprepend do_something_interesting(int, string) %{
"""Do some interesting thing
number:Int -- a number
text:String -- some text
"""
%}
#endif
bool do_something_interesting(int number, string text);
Look at the docstring feature in SWIG for Python.
Probably putting the following line in your .i file
would do what you want (see http://www.swig.org/Doc2.0/Python.html#Python_nn65 for more options)