Fork me on GitHub

sqlalchemy_imageattach.util — Utilities

This module provides some utility functions to manipulate docstrings at runtime. It’s useful for adjusting the docs built by Sphinx without making the code ugly.

sqlalchemy_imageattach.util.append_docstring(docstring, *lines)

Appends the docstring with given lines:

function.__doc__ = append_docstring(
    function.__doc__,
    '.. note::'
    '',
    '   Appended docstring!'
)
Parameters:
  • docstring – a docstring to be appended
  • *lines – lines of trailing docstring
Returns:

new docstring which is appended

Return type:

basestring

sqlalchemy_imageattach.util.append_docstring_attributes(docstring, locals)

Manually appends class’ docstring with its attribute docstrings. For example:

class Entity(object):
    # ...

    __doc__ = append_docstring_attributes(
        __doc__,
        dict((k, v) for k, v in locals()
                    if isinstance(v, MyDescriptor))
    )
Parameters:
  • docstring (basestring) – class docstring to be appended
  • locals (collections.Mapping) – attributes dict
Returns:

appended docstring

Return type:

basestring

sqlalchemy_imageattach.util.get_minimum_indent(docstring, ignore_before=1)

Gets the minimum indent string from the docstring:

>>> get_minimum_indent('Hello')
''
>>> get_minimum_indent('Hello\n    world::\n        yeah')
'    '
Parameters:
  • docstring (basestring) – the docstring to find its minimum indent
  • ignore_before (numbers.Integral) – ignore lines before this line. usually docstrings which follow PEP 8 have no indent for the first line, so its default value is 1
Returns:

the minimum indent string which consists of only whitespaces (tabs and/or spaces)

Return type:

basestring