def doc(pipeline=None): """Get doc for one or all pipelines If pipeline is specified, return the doc-string for that pipeline, otherwise return a string with short documentation for all available pipelines. Args: pipeline (String): The pipeline to document (optional). Returns: String: Documentation of one or all pipelines. """ # Add a custom formatter to customize the action class DocString(str): def __format__(self, format_spec): if not format_spec: format_spec = "Run" return self.format(action=format_spec) # Single pipeline if pipeline is not None: doc_str = plugins.doc(package_name=__name__, plugin_name=pipeline, long_doc=False, use_module=True) return DocString(f"{{action}} {doc_str}") # All pipelines doc_list = list() all_options = options() for pipeline in names(): pipeline_opts = ", ".join(o for o, p in all_options.items() if p == pipeline) doc_list.append(f"{pipeline_opts:<20s} {doc(pipeline):__action__}") return DocString("\n".join(doc_list).replace("__action__", "{action}"))
def test_long_doc(plugin_package): """Test that we can retrieve the long docstring from a plugin""" plugin_name = "plugin_plain" doc = plugins.doc(plugin_package, plugin_name) assert doc == "This is the plain docstring."
def test_short_doc(plugin_package): """Test that we can retrieve the short docstring from a plugin""" plugin_name = "plugin_plain" doc = plugins.doc(plugin_package, plugin_name, long_doc=False) assert doc == "A plain plugin"