tools¶
docstr_to_html¶
- msdss_models_api.tools.docstr_to_html(docstr)[source]¶
Converts a docstring into HTML format.
- Parameters
docstr (str) – Docstring to convert into HTML.
- Returns
HTML formatted docstring.
- Return type
Author
Richard Wen <rrwen.dev@gmail.com>
Example
from msdss_models_api.models import Model from msdss_models_api.tools import * from pprint import pprint docstr = ''.join(get_npdoc(Model)['Extended Summary']) html = docstr_to_html(docstr) pprint(html)
('<div class="document">\n' '<ul class="simple">\n' '<li>Methods <tt class="docutils literal">delete</tt>, <tt class="docutils ' 'literal">load</tt>, and <tt class="docutils literal">save</tt> are handled ' 'by default using <a href="#id1"><span class="problematic" ' 'id="id2">:class:`pickle`</span></a> and do not need to be defined if there ' 'is no need for custom model saving and loading.* Methods <tt class="docutils ' 'literal">input</tt>, <tt class="docutils literal">output</tt> and <tt ' 'class="docutils literal">update</tt> need to be defined as they are ' 'placeholders for standardized functions of the model</li>\n' '</ul>\n' '</div>\n')
get_md_doc¶
- msdss_models_api.tools.get_md_doc(obj)[source]¶
Converts a Python objects numpy style docstring into markdown for the summary, extended summary, and parameters headings.
- Parameters
obj (any or str) – A python object with numpy style docstring. If
str
, then it will assume that the str will be the docstring.- Returns
Markdown formatted docstring for the summary, extended summary, and parameters headings.
- Return type
Author
Richard Wen <rrwen.dev@gmail.com>
Example
from msdss_models_api.models import Model from msdss_models_api.tools import * from pprint import pprint model_doc = get_md_doc(Model) pprint(model_doc)
('\n' 'Template class to standardize modelling.\n' '\n' '\n' '* Methods delete, load, and save are handled by default using ' '[:class:`pickle`](#id1) and do not need to be defined if there is no need ' 'for custom model saving and loading.* Methods input, output and update need ' 'to be defined as they are placeholders for standardized functions of the ' 'model\n' '\n' '\n' '\n' ' \n' 'Parameters\n' '----------\n' '\n' '\n' '* file\\_path: Path to save, load, and delete the model for persistence ' 'without the extension. Can be used in methods as self.file.\n' '* file\\_ext: File extension to save the model in.\n' '* can\\_input: Whether the method .input is defined and available. This is ' 'useful for controlling route requests in an API.\n' '* can\\_output: Whether the method .output is defined and available. This is ' 'useful for controlling route requests in an API.\n' '* can\\_update: Whether the method .update is defined and available. This is ' 'useful for controlling route requests in an API.\n' '* settings: Dict of initial custom settings to be used by model methods. ' 'These are expected not to change from the time of initialization.\n' '\n' '\n' '\n')
get_npdoc¶
- msdss_models_api.tools.get_npdoc(obj)[source]¶
Parses a numpy style docstring from a Python object.
- Parameters
obj (any or str) – A python object with numpy style docstring. If
str
, then it will assume that the str will be the docstring.- Returns
A parsed numpy docstring object.
- Return type
numpydoc:numpydoc.docscrape.NumpyDocString
Author
Richard Wen <rrwen.dev@gmail.com>
Example
from msdss_models_api.models import Model from msdss_models_api.tools import * from pprint import pprint docstr = ''.join(get_npdoc(Model)['Extended Summary']) pprint(docstr)
('* Methods ``delete``, ``load``, and ``save`` are handled by default using ' ':class:`pickle` and do not need to be defined if there is no need for custom ' 'model saving and loading.* Methods ``input``, ``output`` and ``update`` need ' 'to be defined as they are placeholders for standardized functions of the ' 'model')
html_to_md¶
- msdss_models_api.tools.html_to_md(html)[source]¶
Converts HTML into markdown format.
- Parameters
html (str) – HTML to convert to markdown.
- Returns
markdown formatted from HTML.
- Return type
Author
Richard Wen <rrwen.dev@gmail.com>
Example
from msdss_models_api.models import Model from msdss_models_api.tools import * from pprint import pprint docstr = ''.join(get_npdoc(Model)['Extended Summary']) html = docstr_to_html(docstr) md = html_to_md(html) pprint(md)
('\n' '* Methods delete, load, and save are handled by default using ' '[:class:`pickle`](#id1) and do not need to be defined if there is no need ' 'for custom model saving and loading.* Methods input, output and update need ' 'to be defined as they are placeholders for standardized functions of the ' 'model\n' '\n' '\n' '\n')