[rhinstaller/blivet/pulls/160 master] Deprecate some little-used device lookup methods
dwlehman
installerbot-noreply at redhat.com
Fri Jun 26 21:36:17 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
I was right to begin with. If indent_spaces starts at 0 that if statement will never be True and indent_spaces will always end up being 0. (The idea there is to get the minimum indentation in the docstring and use that for the sphinx directive.)
--
To view this pull request on github, visit https://github.com/rhinstaller/blivet/pull/160#discussion_r33398240
More information about the anaconda-patches
mailing list