Skip to content

Commit

Permalink
Adds docstrings to Python bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
ilumsden committed Sep 10, 2024
1 parent e6b3ce2 commit a2f78e9
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 112 deletions.
42 changes: 30 additions & 12 deletions bindings/python/annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,55 +68,73 @@ PythonAnnotation &PythonAnnotation::set(PythonVariant &data) {
void create_caliper_annotation_mod(py::module_ &caliper_annotation_mod) {
py::class_<PythonAnnotation> annotation_type(caliper_annotation_mod,
"Annotation");
annotation_type.def(py::init<const char *>(), "",
annotation_type.def(py::init<const char *>(),
"Creates an annotation object to manipulate the context "
"attribute with the given name.",
py::arg());
annotation_type.def(py::init<const char *, cali_attr_properties>(), "",
annotation_type.def(py::init<const char *, cali_attr_properties>(),
"Creates an annotation object to manipulate the context "
"attribute with the given name",
py::arg(), py::arg("opt"));
annotation_type.def("end", &PythonAnnotation::end, "");
annotation_type.def(
"end", &PythonAnnotation::end,
"Close the top-most open region for the associated context attribute.");
annotation_type.def("begin",
static_cast<PythonAnnotation &(PythonAnnotation::*)()>(
&PythonAnnotation::begin),
"");
"Begin the region for the associated context attribute");
annotation_type.def("begin",
static_cast<PythonAnnotation &(PythonAnnotation::*)(int)>(
&PythonAnnotation::begin),
"");
"Begin the region for the associated context attribute "
"with an integer value");
annotation_type.def(
"begin",
static_cast<PythonAnnotation &(PythonAnnotation::*)(const char *)>(
&PythonAnnotation::begin),
"");
"Begin the region for the associated context attribute "
"with a str/bytes value");
annotation_type.def(
"begin",
static_cast<PythonAnnotation &(PythonAnnotation::*)(cali_attr_type,
const std::string &)>(
&PythonAnnotation::begin),
"");
"Begin the region for the associated context attribute "
"with a str/bytes value");
annotation_type.def(
"begin",
static_cast<PythonAnnotation &(PythonAnnotation::*)(PythonVariant &)>(
&PythonAnnotation::begin),
"");
"Begin the region for the associated context attribute "
"with a variant");
annotation_type.def("set",
static_cast<PythonAnnotation &(PythonAnnotation::*)(int)>(
&PythonAnnotation::set),
"");
"Exports an entry for the associated context attribute "
"with an integer value. The top-most prior open value "
"for the attribute, if any, will be overwritten.");
annotation_type.def(
"set",
static_cast<PythonAnnotation &(PythonAnnotation::*)(const char *)>(
&PythonAnnotation::set),
"");
"Exports an entry for the associated context attribute "
"with a str/bytes value. The top-most prior open value "
"for the attribute, if any, will be overwritten.");
annotation_type.def(
"set",
static_cast<PythonAnnotation &(PythonAnnotation::*)(cali_attr_type,
const std::string &)>(
&PythonAnnotation::set),
"");
"Exports an entry for the associated context attribute "
"with a str/bytes value. The top-most prior open value "
"for the attribute, if any, will be overwritten.");
annotation_type.def(
"set",
static_cast<PythonAnnotation &(PythonAnnotation::*)(PythonVariant &)>(
&PythonAnnotation::set),
"");
"Exports an entry for the associated context attribute "
"with a variant. The top-most prior open value "
"for the attribute, if any, will be overwritten.");
}

} // namespace cali
123 changes: 87 additions & 36 deletions bindings/python/config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,60 +31,111 @@ void create_caliper_config_manager_mod(
py::module_ &caliper_config_manager_mod) {
py::class_<PythonConfigManager> config_mgr_type(caliper_config_manager_mod,
"ConfigManager");
config_mgr_type.def(py::init<>());
config_mgr_type.def(py::init<const char *>());
config_mgr_type.def("add_config_spec",
static_cast<void (PythonConfigManager::*)(const char *)>(
&cali::ConfigManager::add_config_spec));
config_mgr_type.def("add_config_spec",
static_cast<void (PythonConfigManager::*)(py::dict)>(
&PythonConfigManager::add_config_spec));
config_mgr_type.def("add_option_spec",
static_cast<void (PythonConfigManager::*)(const char *)>(
&cali::ConfigManager::add_option_spec));
config_mgr_type.def("add_option_spec",
static_cast<void (PythonConfigManager::*)(py::dict)>(
&PythonConfigManager::add_option_spec));
config_mgr_type.def("add", &PythonConfigManager::py_add);
config_mgr_type.def("load",
static_cast<void (PythonConfigManager::*)(const char *)>(
&cali::ConfigManager::load));
config_mgr_type.def(py::init<>(), "Create a ConfigManager.");
config_mgr_type.def(
py::init<const char *>(),
"Create a ConfigManager with the provide configuration string.");
config_mgr_type.def(
"add_config_spec",
static_cast<void (PythonConfigManager::*)(const char *)>(
&cali::ConfigManager::add_config_spec),
"Add a custom config spec to this ConfigManager."
""
"Adds a new Caliper configuration spec for this ConfigManager"
"using a custom ChannelController or option checking function.");
config_mgr_type.def(
"add_config_spec",
static_cast<void (PythonConfigManager::*)(py::dict)>(
&PythonConfigManager::add_config_spec),
"Add a JSON config spec to this ConfigManager"
""
"Adds a new Caliper configuration specification for this ConfigManager"
"using a basic ChannelController."
""
"See the C++ docs for more details");
config_mgr_type.def(
"add_option_spec",
static_cast<void (PythonConfigManager::*)(const char *)>(
&cali::ConfigManager::add_option_spec),
"Add a JSON option spec to this ConfigManager"
""
"Allows one to define options for any config in a matching category."
"Option specifications must be added before querying or creating any"
"configurations to be effective."
""
"See the C++ docs for more details");
config_mgr_type.def(
"add_option_spec",
static_cast<void (PythonConfigManager::*)(py::dict)>(
&PythonConfigManager::add_option_spec),
"Add a JSON option spec to this ConfigManager"
""
"Allows one to define options for any config in a matching category."
"Option specifications must be added before querying or creating any"
"configurations to be effective."
""
"See the C++ docs for more details");
config_mgr_type.def("add", &PythonConfigManager::py_add,
"Parse the provided configuration string and create the "
"specified configuration channels.");
config_mgr_type.def(
"load",
static_cast<void (PythonConfigManager::*)(const char *)>(
&cali::ConfigManager::load),
"Load config and option specs from the provided filename.");
config_mgr_type.def(
"set_default_parameter",
static_cast<void (PythonConfigManager::*)(const char *, const char *)>(
&cali::ConfigManager::set_default_parameter));
&cali::ConfigManager::set_default_parameter),
"Pre-set a key-value pair for all configurations.");
config_mgr_type.def(
"set_default_parameter_for_config",
static_cast<void (PythonConfigManager::*)(const char *, const char *,
const char *)>(
&cali::ConfigManager::set_default_parameter_for_config));
config_mgr_type.def("error",
static_cast<bool (PythonConfigManager::*)() const>(
&cali::ConfigManager::error));
&cali::ConfigManager::set_default_parameter_for_config),
"Pre-set a key-value pair for the specified configuration.");
config_mgr_type.def(
"error",
static_cast<bool (PythonConfigManager::*)() const>(
&cali::ConfigManager::error),
"Returns true if there was an error while parsing configuration.");
config_mgr_type.def("error_msg",
static_cast<std::string (PythonConfigManager::*)() const>(
&cali::ConfigManager::error_msg));
&cali::ConfigManager::error_msg),
"Returns an error message if there was an error while "
"parsing configuration.");
config_mgr_type.def("__repr__",
static_cast<std::string (PythonConfigManager::*)() const>(
&cali::ConfigManager::error_msg));
config_mgr_type.def("start", static_cast<void (PythonConfigManager::*)()>(
&cali::ConfigManager::start));
config_mgr_type.def("stop", static_cast<void (PythonConfigManager::*)()>(
&cali::ConfigManager::stop));
config_mgr_type.def("flush", static_cast<void (PythonConfigManager::*)()>(
&cali::ConfigManager::flush));
config_mgr_type.def("check", &PythonConfigManager::check);
config_mgr_type.def(
"start",
static_cast<void (PythonConfigManager::*)()>(&cali::ConfigManager::start),
"Start all configured measurement channels, or re-start paused ones.");
config_mgr_type.def(
"stop",
static_cast<void (PythonConfigManager::*)()>(&cali::ConfigManager::stop),
"Pause all configured measurement channels.");
config_mgr_type.def(
"flush",
static_cast<void (PythonConfigManager::*)()>(&cali::ConfigManager::flush),
"Flush all configured measurement channels.");
config_mgr_type.def("check", &PythonConfigManager::check,
"Check if the given config string is valid.");
config_mgr_type.def(
"available_config_specs",
static_cast<std::vector<std::string> (PythonConfigManager::*)() const>(
&cali::ConfigManager::available_config_specs));
&cali::ConfigManager::available_config_specs),
"Return names of available config specs.");
config_mgr_type.def(
"get_documentation_for_spec",
static_cast<std::string (PythonConfigManager::*)(const char *) const>(
&cali::ConfigManager::get_documentation_for_spec));
config_mgr_type.def_static("get_config_docstrings",
static_cast<std::vector<std::string> (*)()>(
&cali::ConfigManager::get_config_docstrings));
&cali::ConfigManager::get_documentation_for_spec),
"Return short description for the given config spec.");
config_mgr_type.def_static(
"get_config_docstrings",
static_cast<std::vector<std::string> (*)()>(
&cali::ConfigManager::get_config_docstrings),
"Return descriptions for available global configs.");
}

} // namespace cali
Loading

0 comments on commit a2f78e9

Please sign in to comment.