Skip to content

Commit

Permalink
Generate description of options as docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
BUYT-1 authored and polyntsov committed Dec 10, 2023
1 parent 898a798 commit 5eaab0f
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/python_bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,28 @@

INITIALIZE_EASYLOGGINGPP

#define DEFINE_ALGORITHM(type, base) \
py::class_<Py##type, Py##base##Base>(module, #type).def(py::init<>())
#define DEFINE_ALGORITHM(type, base) \
auto var##type = py::class_<Py##type, Py##base##Base>(module, #type).def(py::init<>()); \
var##type.doc() = MakeDocString<Py##type>(); \
var##type
#define DEFINE_ALGORITHM_BASE(base) py::class_<Py##base##Base, PyAlgorithmBase>(module, #base)
#define DEFINE_FD_ALGORITHM(type) DEFINE_ALGORITHM(type, FdAlgorithm)
#define DEFINE_AR_ALGORITHM(type) DEFINE_ALGORITHM(type, ArAlgorithm)
#define DEFINE_UCC_ALGORITHM(type) DEFINE_ALGORITHM(type, UCCAlgorithm)

namespace {
template <typename AlgoType>
std::string MakeDocString() {
AlgoType algo = AlgoType();
std::stringstream docstring;
docstring << "Options:\n";
for (std::string_view option_name : algo.GetPossibleOptions()) {
docstring << option_name << ": " << algo.GetDescription(option_name) << "\n";
}
return docstring.str();
}
} // namespace

namespace python_bindings {

namespace py = pybind11;
Expand Down

0 comments on commit 5eaab0f

Please sign in to comment.