| 1 |
--- |
| 2 |
layout: post |
| 3 |
title: "Doxygen documentation to Python Docstrings" |
| 4 |
date: Thu 31 Oct 09:38:05 GMT 2024 |
| 5 |
--- |
| 6 |
|
| 7 |
[Libcootapi](https://www2.mrc-lmb.cam.ac.uk/personal/pemsley/coot/docs/api/html/) is written |
| 8 |
in C++ and documented with [Doxygen](https://www.doxygen.nl/). |
| 9 |
|
| 10 |
I wanted this functionality to be available via Python and I chose |
| 11 |
[nanobind](https://nanobind.readthedocs.io/en/latest/) as the means to do that. |
| 12 |
|
| 13 |
Nanobind provides access to practically all of the many hundreds of |
| 14 |
functions in the C++ class and it would be useful if the Python API |
| 15 |
was as well documented as was the C++ api. Transfering the |
| 16 |
documentation from C++ to Python "by hand" would be tedious. So |
| 17 |
Lucrezia (@lulu_catapano) and I wrote a [Python |
| 18 |
script](https://github.com/pemsley/coot/blob/main/api/doxy-sphinx/xml-to-python.py) |
| 19 |
to transfer the Doxygen documentation into Python docstrings in reStructured Text format, |
| 20 |
which then get processed by Sphinx so that the Python API looks like read-the-docs |
| 21 |
documentation from native Python code. |
| 22 |
|
| 23 |
As well as attractive HTML output, the intermediate documented python |
| 24 |
function stubs work with LSP and intellisense to provide api documentation |
| 25 |
and completions. |
| 26 |
|
| 27 |
The script works pretty well for our [chapi documentation](https://www.mrc-lmb.cam.ac.uk/lucrezia/libcootapi-documentation/api.html). |
| 28 |
It might work for other nanobinders in a similar situation. |
| 29 |
|