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

Automatic documentation for boost python. #237

Open
jmirabel opened this issue Sep 19, 2019 · 10 comments
Open

Automatic documentation for boost python. #237

jmirabel opened this issue Sep 19, 2019 · 10 comments

Comments

@jmirabel
Copy link
Collaborator

Although not related to CMake, I post this issue here because the problem was encountered in many packages and the best place to provide a solution is this package.
This is mostly for reporting as I have no time to allocate to this at the moment.

Problem

A C++ library can be easily exposed in Python, using for instance boost python. If the C++ library is already documented using Doxygen, documenting the Python bindings in somewhat tedious as it duplicates the already written documentation.

Solution

  1. make Doxygen generate XML documentation for your project. There is no need to install it if all the bindings are in the same package.
  2. using a Python script similar to https://github.com/jmirabel/hpp-python/tree/master/doc, generate a C++ file containing the documentation for all the functions of your C++ code. There are two possible formats, one using templates, the other using a std::map. At the moment, I am not able to say which one is preferable.

Format using templates

template <typename FunctionPrototype> struct doxygen_doc
{
inline static const char* docstring() { static const char* ds = "undocumented function"; return ds; }
}
// A template specialization for each C++ function that Doxygen knows.
  1. in the Python bindings code, use the file generated above to fill the documentation of your classes, methods, (attributes?)...
@jcarpent
Copy link
Contributor

typename FunctionPrototype you meant a pointer on the function?

@jmirabel
Copy link
Collaborator Author

jmirabel commented Sep 19, 2019

typename FunctionPrototype you meant a pointer on the function?

I meant the type of this function, i.e. return_type (ClassName::*) (args) but I realize now that it is not sufficient because the type does not include the function name... It may be necessary to use a pointer to the function.

Assuming there are no ambiguities, the idea is to use it as
.def ("func", &Class::func, doxygen_doc<&Class::func>::docstring())

If this works well, this could even become
.def (documented_method<&Class::func> ("func"))

@jcarpent
Copy link
Contributor

Another issue concerns Majax equations. Do you know how to handle them?

@jmirabel
Copy link
Collaborator Author

Maybe http://asciitex.sourceforge.net/

@jcarpent
Copy link
Contributor

This would be indeed a nice and expected feature.

@jmirabel
Copy link
Collaborator Author

Eventually this: https://www.ctan.org/pkg/tex2mail

@jmirabel
Copy link
Collaborator Author

@jmirabel
Copy link
Collaborator Author

I played a bit on this topic. A first working version can be found by pulling branch python_doc of https://github.com/jmirabel/hpp-fcl.
To make it work, you must add my fork as remote of the submodule:

cd cmake
git remote add -f jmirabel https://github.com/jmirabel/jrl-cmakemodules

@jmirabel
Copy link
Collaborator Author

@jmirabel
Copy link
Collaborator Author

For the conversion from TeX formulas to ASCII, I found this very helpful package: https://pylatexenc.readthedocs.io/en/latest/

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

No branches or pull requests

2 participants