How to use the debtcollector._utils.generate_message function in debtcollector

To help you get started, we’ve selected a few debtcollector examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / debtcollector / debtcollector / removals.py View on Github external
def _cls_decorator(cls):
        _check_it(cls)
        out_message = _utils.generate_message(
            "Using class '%s' (either directly or via inheritance)"
            " is deprecated" % cls_name, postfix=None, message=message,
            version=version, removal_version=removal_version)
        cls.__init__ = _wrap_it(cls.__init__, out_message)
        return cls
github openstack / debtcollector / debtcollector / renames.py View on Github external
def renamed_kwarg(old_name, new_name, message=None,
                  version=None, removal_version=None, stacklevel=3,
                  category=None, replace=False):
    """Decorates a kwarg accepting function to deprecate a renamed kwarg."""

    prefix = _KWARG_RENAMED_PREFIX_TPL % old_name
    postfix = _KWARG_RENAMED_POSTFIX_TPL % new_name
    out_message = _utils.generate_message(
        prefix, postfix=postfix, message=message, version=version,
        removal_version=removal_version)

    @wrapt.decorator
    def decorator(wrapped, instance, args, kwargs):
        if old_name in kwargs:
            _utils.deprecation(out_message,
                               stacklevel=stacklevel, category=category)
            if replace:
                kwargs.setdefault(new_name, kwargs.pop(old_name))
        return wrapped(*args, **kwargs)

    return decorator
github openstack / debtcollector / debtcollector / removals.py View on Github external
def _fetch_message_from_cache(self, kind):
        try:
            out_message = self._message_cache[kind]
        except KeyError:
            prefix_tpl = self._PROPERTY_GONE_TPLS[kind]
            prefix = prefix_tpl % _fetch_first_result(
                self.fget, self.fset, self.fdel, _get_qualified_name,
                value_not_found="???")
            out_message = _utils.generate_message(
                prefix, message=self.message, version=self.version,
                removal_version=self.removal_version)
            self._message_cache[kind] = out_message
        return out_message
github openstack / debtcollector / debtcollector / __init__.py View on Github external
:param postfix: postfix string used as the postfix of the output message
    :param message: message string used as ending contents of the deprecate
                    message
    :param version: version string (represents the version this
                    deprecation was created in)
    :param removal_version: version string (represents the version this
                            deprecation will be removed in); a string of '?'
                            will denote this will be removed in some future
                            unknown version
    :param stacklevel: stacklevel used in the :func:`warnings.warn` function
                       to locate where the users code is in the
                       :func:`warnings.warn` call
    :param category: the :mod:`warnings` category to use, defaults to
                     :py:class:`DeprecationWarning` if not provided
    """
    out_message = _utils.generate_message(prefix, postfix=postfix,
                                          version=version, message=message,
                                          removal_version=removal_version)
    _utils.deprecation(out_message, stacklevel=stacklevel,
                       category=category)
github openstack / debtcollector / debtcollector / updating.py View on Github external
def updated_kwarg_default_value(name, old_value, new_value, message=None,
                                version=None, stacklevel=3,
                                category=FutureWarning):

    """Decorates a kwarg accepting function to change the default value"""

    prefix = _KWARG_UPDATED_PREFIX_TPL % (name, new_value)
    postfix = _KWARG_UPDATED_POSTFIX_TPL % old_value
    out_message = _utils.generate_message(
        prefix, postfix=postfix, message=message, version=version)

    def decorator(f):
        sig = signature(f)
        varnames = list(sig.parameters.keys())

        @wrapt.decorator
        def wrapper(wrapped, instance, args, kwargs):
            explicit_params = set(
                varnames[:len(args)] + list(kwargs.keys())
            )
            allparams = set(varnames)
            default_params = set(allparams - explicit_params)
            if name in default_params:
                _utils.deprecation(out_message,
                                   stacklevel=stacklevel, category=category)
github openstack / debtcollector / debtcollector / moves.py View on Github external
def wrapper(wrapped, instance, args, kwargs):
            base_name = _utils.get_class_name(wrapped, fully_qualified=False)
            if fully_qualified:
                old_name = old_attribute_name
            else:
                old_name = ".".join((base_name, old_attribute_name))
            new_name = ".".join((base_name, new_attribute_name))
            prefix = _KIND_MOVED_PREFIX_TPL % (kind, old_name, new_name)
            out_message = _utils.generate_message(
                prefix, message=message,
                version=version, removal_version=removal_version)
            _utils.deprecation(out_message, stacklevel=stacklevel,
                               category=category)
            return wrapped(*args, **kwargs)
github openstack / debtcollector / debtcollector / removals.py View on Github external
f_name = _utils.get_callable_name(f)
            # Decorator was used on a classmethod or instancemethod
            else:
                thing_post = '()'
                base_name = _utils.get_class_name(instance,
                                                  fully_qualified=False)
            if base_name:
                thing_name = ".".join([base_name, f_name])
            else:
                thing_name = f_name
        else:
            thing_name = f_name
        if thing_post:
            thing_name += thing_post
        prefix = prefix_pre + " '%s' is deprecated" % (thing_name)
        out_message = _utils.generate_message(
            prefix,
            version=version,
            removal_version=removal_version,
            message=message)
        _utils.deprecation(out_message,
                           stacklevel=stacklevel, category=category)
        return f(*args, **kwargs)
    return wrapper(f)
github openstack / debtcollector / debtcollector / moves.py View on Github external
def __init__(self, old_name, new_name,
                 version=None, removal_version=None,
                 stacklevel=3, category=None):
        self._old_name = old_name
        self._new_name = new_name
        self._message = _utils.generate_message(
            "Read-only property '%s' has moved"
            " to '%s'" % (self._old_name, self._new_name),
            version=version, removal_version=removal_version)
        self._stacklevel = stacklevel
        self._category = category
github openstack / debtcollector / debtcollector / moves.py View on Github external
def moved_function(new_func, old_func_name, old_module_name,
                   message=None, version=None, removal_version=None,
                   stacklevel=3, category=None):
    """Deprecates a function that was moved to another location.

    This generates a wrapper around ``new_func`` that will emit a deprecation
    warning when called. The warning message will include the new location
    to obtain the function from.
    """
    new_func_full_name = _utils.get_callable_name(new_func)
    new_func_full_name += _MOVED_CALLABLE_POSTFIX
    old_func_full_name = ".".join([old_module_name, old_func_name])
    old_func_full_name += _MOVED_CALLABLE_POSTFIX
    prefix = _FUNC_MOVED_PREFIX_TPL % (old_func_full_name, new_func_full_name)
    out_message = _utils.generate_message(prefix,
                                          message=message, version=version,
                                          removal_version=removal_version)

    @six.wraps(new_func, assigned=_utils.get_assigned(new_func))
    def old_new_func(*args, **kwargs):
        _utils.deprecation(out_message, stacklevel=stacklevel,
                           category=category)
        return new_func(*args, **kwargs)

    old_new_func.__name__ = old_func_name
    old_new_func.__module__ = old_module_name
    return old_new_func