Open3D (C++ API)
|
#include <docstring.h>
Public Member Functions | |
FunctionDoc (const std::string &pybind_doc) | |
std::string | ToGoogleDocString () const |
Generate Google style python docstring. More... | |
Static Public Member Functions | |
static std::string | NamespaceFix (const std::string &s) |
Apply fixes to namespace, e.g. "::" to "." for python. More... | |
Data Fields | |
std::string | name_ = "" |
std::vector< ArgumentDoc > | argument_docs_ |
ArgumentDoc | return_doc_ |
std::string | summary_ = "" |
std::string | body_ = "" |
Protected Member Functions | |
void | ParseFunctionName () |
Parse the function name from docstring. More... | |
void | ParseSummary () |
Parse the function "summary" docstring received from pybind. More... | |
void | ParseArguments () |
Parse ArgumentDoc for each argument. More... | |
void | ParseReturn () |
Parse function return. More... | |
Static Protected Member Functions | |
static std::vector< std::string > | GetArgumentTokens (const std::string &pybind_doc) |
static ArgumentDoc | ParseArgumentToken (const std::string &argument_token) |
Parse individual argument token and returns a ArgumentDoc. More... | |
static std::string | StringCleanAll (std::string &s, const std::string &white_space=" \") |
Runs all string cleanup functions. More... | |
Protected Attributes | |
std::string | pybind_doc_ = "" |
This class is designed to parse docstrings generated by pybind11 and convert to Python friendly Google-style docstring with the flexibility of adding additional docstrings manually.
The automated part includes:
This approach was chosen in favor of writting docstring in Python files for two reasons 1) We don't need to create additional (pure) Python wrapper functions, 2) The type information generated by pybind is preserved.
However, this also comes with a drawback: FunctionDoc rely on docstrings generated by pybind11, which is subject to change. So if a new version of pybind11 changes the format of docstring, this class needs to be updated accordingly. Another alternative approach is to modify pybind11 directly, although it makes some of the parsing part simpler, it could be much harder to maintain to keep track of the upstream pybind11.
Example usage:
open3d::docstring::FunctionDoc::FunctionDoc | ( | const std::string & | pybind_doc | ) |
|
staticprotected |
Split docstring to argument tokens E.g. "cylinder_radius: float = 1.0", "cylinder_radius: float"
|
static |
Apply fixes to namespace, e.g. "::" to "." for python.
|
protected |
Parse ArgumentDoc for each argument.
|
staticprotected |
Parse individual argument token and returns a ArgumentDoc.
|
protected |
Parse the function name from docstring.
|
protected |
Parse function return.
|
protected |
Parse the function "summary" docstring received from pybind.
|
staticprotected |
Runs all string cleanup functions.
std::string open3d::docstring::FunctionDoc::ToGoogleDocString | ( | ) | const |
Generate Google style python docstring.
std::vector<ArgumentDoc> open3d::docstring::FunctionDoc::argument_docs_ |
std::string open3d::docstring::FunctionDoc::body_ = "" |
std::string open3d::docstring::FunctionDoc::name_ = "" |
|
protected |
ArgumentDoc open3d::docstring::FunctionDoc::return_doc_ |
std::string open3d::docstring::FunctionDoc::summary_ = "" |