[rhinstaller/blivet/pulls/160 master] Deprecate some little-used device lookup methods

bcl installerbot-noreply at redhat.com
Sat Jun 27 00:34:47 UTC 2015


> @@ -637,3 +643,105 @@ def eintr_retry_call(func, *args):
>              if e.errno == errno.EINTR:
>                  continue
>              raise
> +
> +#
> +# Deprecation decorator.
> +#
> +_DEPRECATION_MESSAGE = "will be removed in a future version."
> +def _default_deprecation_msg(func):
> +    return "%s %s" % (func.__name__, _DEPRECATION_MESSAGE)
> +
> +def indent(text, spaces=4):
> +    """ Indent text by a specified number of spaces.
> +
> +        :param str text: the text to indent
> +        :keyword int spaces: the number of spaces to indent text
> +    """
> +    if not text or not text.strip():
> +        return text
> +
> +    indentation = " " * spaces
> +    indented = []
> +    for line in text.splitlines():
> +        indented.append("%s%s" % (indentation, line))
> +
> +    return "\n".join(indented)
> +
> +_SPHINX_DEPRECATE = """.. deprecated:: %(version)s
> +    %(message)s
> +"""
> +def _add_deprecation_doc_text(func, version=None, message=None):
> +    """ Add sphinx 'deprecated' markup to a function's docstring.
> +
> +        :param :class:`function` func: the function
> +        :param str version: version in which the deprecation is effective
> +        :param str message: message suggesting a preferred alternative
> +
> +        If your doctext is indented with something other than spaces the added
> +        doctext's indentation will probably not match. That'd be your fault.
> +    """
> +    base_text = func.__doc__
> +    if base_text is None:
> +        base_text = " " # They contain leading and trailing spaces. *shrug*
> +    else:
> +        base_text = base_text[:-1] # Trim the trailing space.
> +
> +    if ".. deprecated::" in base_text:
> +        # Don't add multiple deprecation directives.
> +        return
> +
> +    # Figure out the number of spaces to indent docstring text.
> +    indent_spaces = None
> +    for l in base_text.splitlines()[1:]:
> +        if not l.strip():
> +            continue
> +
> +        spaces = 0
> +        _l = l[:]
> +        while _l and _l.startswith(" "):
> +            spaces += 1
> +            _l = _l[1:]
> +
> +        if indent_spaces is None or indent_spaces > spaces:

Ah! ok, maybe a note here that it's finding the minumum amount of indent.

-- 
To view this pull request on github, visit https://github.com/rhinstaller/blivet/pull/160#discussion_r33406853


More information about the anaconda-patches mailing list