Integrate ruff, ruff-format

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Change-Id: I6ac01b671e3d7cc6a7d571b59013783436be618e
This commit is contained in:
Stephen Finucane
2025-03-04 15:53:52 +00:00
parent 14881ea395
commit 42d5591d5e
14 changed files with 396 additions and 208 deletions

View File

@@ -12,17 +12,18 @@ repos:
- id: debug-statements
- id: check-yaml
files: .*\.(yaml|yml)$
- repo: https://opendev.org/openstack/hacking
rev: 7.0.0
hooks:
- id: hacking
additional_dependencies: []
- repo: https://github.com/PyCQA/doc8
rev: v2.0.0
hooks:
- id: doc8
- repo: https://github.com/asottile/pyupgrade
rev: v3.20.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.10
hooks:
- id: pyupgrade
args: [--py310-plus]
- id: ruff-check
args: ['--fix', '--unsafe-fixes']
- id: ruff-format
- repo: https://opendev.org/openstack/hacking
rev: 8.0.0
hooks:
- id: hacking
additional_dependencies: []

View File

@@ -17,9 +17,15 @@ from debtcollector import _utils
__version__ = importlib.metadata.version('debtcollector')
def deprecate(prefix, postfix=None, message=None,
version=None, removal_version=None,
stacklevel=3, category=DeprecationWarning):
def deprecate(
prefix,
postfix=None,
message=None,
version=None,
removal_version=None,
stacklevel=3,
category=DeprecationWarning,
):
"""Helper to deprecate some thing using generated message format.
:param prefix: prefix string used as the prefix of the output message
@@ -38,8 +44,11 @@ def deprecate(prefix, postfix=None, message=None,
: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)
out_message = _utils.generate_message(
prefix,
postfix=postfix,
version=version,
message=message,
removal_version=removal_version,
)
_utils.deprecation(out_message, stacklevel=stacklevel, category=category)

View File

@@ -56,23 +56,26 @@ def get_qualified_name(obj):
return (False, obj.__name__)
def generate_message(prefix, postfix=None, message=None,
version=None, removal_version=None):
def generate_message(
prefix, postfix=None, message=None, version=None, removal_version=None
):
"""Helper to generate a common message 'style' for deprecation helpers."""
message_components = [prefix]
if version:
message_components.append(" in version '%s'" % version)
message_components.append(f" in version '{version}'")
if removal_version:
if removal_version == "?":
message_components.append(" and will be removed in a future"
" version")
message_components.append(
" and will be removed in a future version"
)
else:
message_components.append(" and will be removed in version '%s'"
% removal_version)
message_components.append(
f" and will be removed in version '{removal_version}'"
)
if postfix:
message_components.append(postfix)
if message:
message_components.append(": %s" % message)
message_components.append(f": {message}")
return ''.join(message_components)
@@ -139,8 +142,11 @@ def get_callable_name(function):
if hasattr(function, 'im_class'):
# This is a unbound method, which exists only in python 2.x
im_class = function.im_class
parts = (im_class.__module__,
im_class.__name__, function.__name__)
parts = (
im_class.__module__,
im_class.__name__,
function.__name__,
)
else:
parts = (function.__module__, function.__name__)
else:

View File

@@ -25,9 +25,16 @@ _MOVED_CALLABLE_POSTFIX = "()"
_FUNC_MOVED_PREFIX_TPL = "Function '%s' has moved to '%s'"
def _moved_decorator(kind, new_attribute_name, message=None,
version=None, removal_version=None, stacklevel=3,
attr_postfix=None, category=None):
def _moved_decorator(
kind,
new_attribute_name,
message=None,
version=None,
removal_version=None,
stacklevel=3,
attr_postfix=None,
category=None,
):
"""Decorates a method/property that was moved to another location."""
def decorator(f):
@@ -45,10 +52,14 @@ def _moved_decorator(kind, new_attribute_name, message=None,
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)
prefix,
message=message,
version=version,
removal_version=removal_version,
)
_utils.deprecation(
out_message, stacklevel=stacklevel, category=category
)
return wrapped(*args, **kwargs)
return wrapper(f)
@@ -56,9 +67,16 @@ def _moved_decorator(kind, new_attribute_name, message=None,
return decorator
def moved_function(new_func, old_func_name, old_module_name,
message=None, version=None, removal_version=None,
stacklevel=3, category=None):
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
@@ -70,14 +88,18 @@ def moved_function(new_func, old_func_name, old_module_name,
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)
out_message = _utils.generate_message(
prefix,
message=message,
version=version,
removal_version=removal_version,
)
@functools.wraps(new_func, assigned=_utils.get_assigned(new_func))
def old_new_func(*args, **kwargs):
_utils.deprecation(out_message, stacklevel=stacklevel,
category=category)
_utils.deprecation(
out_message, stacklevel=stacklevel, category=category
)
return new_func(*args, **kwargs)
old_new_func.__name__ = old_func_name
@@ -109,22 +131,30 @@ class moved_read_only_property:
:py:class:`DeprecationWarning` if not provided
"""
def __init__(self, old_name, new_name,
version=None, removal_version=None,
stacklevel=3, category=None):
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)
f"Read-only property '{self._old_name}' has moved"
f" to '{self._new_name}'",
version=version,
removal_version=removal_version,
)
self._stacklevel = stacklevel
self._category = category
def __get__(self, instance, owner):
_utils.deprecation(self._message,
stacklevel=self._stacklevel,
category=self._category)
_utils.deprecation(
self._message, stacklevel=self._stacklevel, category=self._category
)
# This handles the descriptor being applied on a
# instance or a class and makes both work correctly...
if instance is not None:
@@ -134,31 +164,59 @@ class moved_read_only_property:
return getattr(real_owner, self._new_name)
def moved_method(new_method_name, message=None,
version=None, removal_version=None, stacklevel=3,
category=None):
def moved_method(
new_method_name,
message=None,
version=None,
removal_version=None,
stacklevel=3,
category=None,
):
"""Decorates an *instance* method that was moved to another location."""
if not new_method_name.endswith(_MOVED_CALLABLE_POSTFIX):
new_method_name += _MOVED_CALLABLE_POSTFIX
return _moved_decorator('Method', new_method_name, message=message,
version=version, removal_version=removal_version,
stacklevel=stacklevel,
attr_postfix=_MOVED_CALLABLE_POSTFIX,
category=category)
return _moved_decorator(
'Method',
new_method_name,
message=message,
version=version,
removal_version=removal_version,
stacklevel=stacklevel,
attr_postfix=_MOVED_CALLABLE_POSTFIX,
category=category,
)
def moved_property(new_attribute_name, message=None,
version=None, removal_version=None, stacklevel=3,
category=None):
def moved_property(
new_attribute_name,
message=None,
version=None,
removal_version=None,
stacklevel=3,
category=None,
):
"""Decorates an *instance* property that was moved to another location."""
return _moved_decorator('Property', new_attribute_name, message=message,
version=version, removal_version=removal_version,
stacklevel=stacklevel, category=category)
return _moved_decorator(
'Property',
new_attribute_name,
message=message,
version=version,
removal_version=removal_version,
stacklevel=stacklevel,
category=category,
)
def moved_class(new_class, old_class_name, old_module_name,
message=None, version=None, removal_version=None,
stacklevel=3, category=None):
def moved_class(
new_class,
old_class_name,
old_module_name,
message=None,
version=None,
removal_version=None,
stacklevel=3,
category=None,
):
"""Deprecates a class that was moved to another location.
This creates a 'new-old' type that can be used for a
@@ -169,22 +227,26 @@ def moved_class(new_class, old_class_name, old_module_name,
if not inspect.isclass(new_class):
_qual, type_name = _utils.get_qualified_name(type(new_class))
raise TypeError("Unexpected class type '%s' (expected"
" class type only)" % type_name)
raise TypeError(
f"Unexpected class type '{type_name}' (expected class type only)"
)
old_name = ".".join((old_module_name, old_class_name))
new_name = _utils.get_class_name(new_class)
prefix = _CLASS_MOVED_PREFIX_TPL % (old_name, new_name)
out_message = _utils.generate_message(
prefix, message=message, version=version,
removal_version=removal_version)
prefix,
message=message,
version=version,
removal_version=removal_version,
)
def decorator(f):
@functools.wraps(f, assigned=_utils.get_assigned(f))
def wrapper(self, *args, **kwargs):
_utils.deprecation(out_message, stacklevel=stacklevel,
category=category)
_utils.deprecation(
out_message, stacklevel=stacklevel, category=category
)
return f(self, *args, **kwargs)
return wrapper

View File

@@ -61,9 +61,18 @@ class removed_property:
'delete': "Deleting the '%s' property is deprecated",
}
def __init__(self, fget=None, fset=None, fdel=None, doc=None,
stacklevel=3, category=DeprecationWarning,
version=None, removal_version=None, message=None):
def __init__(
self,
fget=None,
fset=None,
fdel=None,
doc=None,
stacklevel=3,
category=DeprecationWarning,
version=None,
removal_version=None,
message=None,
):
self.fset = fset
self.fget = fget
self.fdel = fdel
@@ -83,11 +92,18 @@ class removed_property:
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="???")
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)
prefix,
message=self.message,
version=self.version,
removal_version=self.removal_version,
)
self._message_cache[kind] = out_message
return out_message
@@ -95,12 +111,14 @@ class removed_property:
self.fget = fget
self.message = kwargs.get('message', self.message)
self.version = kwargs.get('version', self.version)
self.removal_version = kwargs.get('removal_version',
self.removal_version)
self.removal_version = kwargs.get(
'removal_version', self.removal_version
)
self.stacklevel = kwargs.get('stacklevel', self.stacklevel)
self.category = kwargs.get('category', self.category)
self.__doc__ = kwargs.get('doc',
getattr(fget, '__doc__', self.__doc__))
self.__doc__ = kwargs.get(
'doc', getattr(fget, '__doc__', self.__doc__)
)
# Regenerate all the messages...
self._message_cache.clear()
return self
@@ -109,16 +127,18 @@ class removed_property:
if self.fdel is None:
raise AttributeError("can't delete attribute")
out_message = self._fetch_message_from_cache('delete')
_utils.deprecation(out_message, stacklevel=self.stacklevel,
category=self.category)
_utils.deprecation(
out_message, stacklevel=self.stacklevel, category=self.category
)
self.fdel(obj)
def __set__(self, obj, value):
if self.fset is None:
raise AttributeError("can't set attribute")
out_message = self._fetch_message_from_cache('set')
_utils.deprecation(out_message, stacklevel=self.stacklevel,
category=self.category)
_utils.deprecation(
out_message, stacklevel=self.stacklevel, category=self.category
)
self.fset(obj, value)
def __get__(self, obj, value):
@@ -127,8 +147,9 @@ class removed_property:
if self.fget is None:
raise AttributeError("unreadable attribute")
out_message = self._fetch_message_from_cache('get')
_utils.deprecation(out_message, stacklevel=self.stacklevel,
category=self.category)
_utils.deprecation(
out_message, stacklevel=self.stacklevel, category=self.category
)
return self.fget(obj)
def getter(self, fget):
@@ -159,8 +180,14 @@ class removed_property:
return o
def remove(f=None, message=None, version=None, removal_version=None,
stacklevel=3, category=None):
def remove(
f=None,
message=None,
version=None,
removal_version=None,
stacklevel=3,
category=None,
):
"""Decorates a function, method, or class to emit a deprecation warning
Due to limitations of the wrapt library (and python) itself, if this
@@ -180,11 +207,14 @@ def remove(f=None, message=None, version=None, removal_version=None,
``DeprecationWarning`` when none is provided)
"""
if f is None:
return functools.partial(remove, message=message,
version=version,
removal_version=removal_version,
stacklevel=stacklevel,
category=category)
return functools.partial(
remove,
message=message,
version=version,
removal_version=removal_version,
stacklevel=stacklevel,
category=category,
)
@wrapt.decorator
def wrapper(f, instance, args, kwargs):
@@ -207,10 +237,10 @@ def remove(f=None, message=None, version=None, removal_version=None,
module_name = _get_qualified_name(inspect.getmodule(f))
if module_name == '__main__':
f_name = _utils.get_class_name(
f, fully_qualified=False)
f, fully_qualified=False
)
else:
f_name = _utils.get_class_name(
f, fully_qualified=True)
f_name = _utils.get_class_name(f, fully_qualified=True)
# Decorator was a used on a function
else:
thing_post = '()'
@@ -220,8 +250,9 @@ def remove(f=None, message=None, version=None, removal_version=None,
# Decorator was used on a classmethod or instancemethod
else:
thing_post = '()'
base_name = _utils.get_class_name(instance,
fully_qualified=False)
base_name = _utils.get_class_name(
instance, fully_qualified=False
)
if base_name:
thing_name = ".".join([base_name, f_name])
else:
@@ -230,49 +261,68 @@ def remove(f=None, message=None, version=None, removal_version=None,
thing_name = f_name
if thing_post:
thing_name += thing_post
prefix = prefix_pre + " '%s' is deprecated" % (thing_name)
prefix = prefix_pre + f" '{thing_name}' is deprecated"
out_message = _utils.generate_message(
prefix,
version=version,
removal_version=removal_version,
message=message)
_utils.deprecation(out_message,
stacklevel=stacklevel, category=category)
message=message,
)
_utils.deprecation(
out_message, stacklevel=stacklevel, category=category
)
return f(*args, **kwargs)
return wrapper(f)
def removed_kwarg(old_name, message=None,
version=None, removal_version=None, stacklevel=3,
category=None):
def removed_kwarg(
old_name,
message=None,
version=None,
removal_version=None,
stacklevel=3,
category=None,
):
"""Decorates a kwarg accepting function to deprecate a removed kwarg."""
prefix = "Using the '%s' argument is deprecated" % old_name
prefix = f"Using the '{old_name}' argument is deprecated"
out_message = _utils.generate_message(
prefix, postfix=None, message=message, version=version,
removal_version=removal_version)
prefix,
postfix=None,
message=message,
version=version,
removal_version=removal_version,
)
@wrapt.decorator
def wrapper(f, instance, args, kwargs):
if old_name in kwargs:
_utils.deprecation(out_message,
stacklevel=stacklevel, category=category)
_utils.deprecation(
out_message, stacklevel=stacklevel, category=category
)
return f(*args, **kwargs)
return wrapper
def removed_class(cls_name, replacement=None, message=None,
version=None, removal_version=None, stacklevel=3,
category=None):
def removed_class(
cls_name,
replacement=None,
message=None,
version=None,
removal_version=None,
stacklevel=3,
category=None,
):
"""Decorates a class to denote that it will be removed at some point."""
def _wrap_it(old_init, out_message):
@functools.wraps(old_init, assigned=_utils.get_assigned(old_init))
def new_init(self, *args, **kwargs):
_utils.deprecation(out_message, stacklevel=stacklevel,
category=category)
_utils.deprecation(
out_message, stacklevel=stacklevel, category=category
)
return old_init(self, *args, **kwargs)
return new_init
@@ -280,24 +330,36 @@ def removed_class(cls_name, replacement=None, message=None,
def _check_it(cls):
if not inspect.isclass(cls):
_qual, type_name = _utils.get_qualified_name(type(cls))
raise TypeError("Unexpected class type '%s' (expected"
" class type only)" % type_name)
raise TypeError(
f"Unexpected class type '{type_name}' (expected"
" class type only)"
)
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)
f"Using class '{cls_name}' (either directly or via inheritance)"
" is deprecated",
postfix=None,
message=message,
version=version,
removal_version=removal_version,
)
cls.__init__ = _wrap_it(cls.__init__, out_message)
return cls
return _cls_decorator
def removed_module(module, replacement=None, message=None,
version=None, removal_version=None, stacklevel=3,
category=None):
def removed_module(
module,
replacement=None,
message=None,
version=None,
removal_version=None,
stacklevel=3,
category=None,
):
"""Helper to be called inside a module to emit a deprecation warning
:param str replacment: A location (or information about) of any potential
@@ -318,16 +380,20 @@ def removed_module(module, replacement=None, message=None,
module_name = module
else:
_qual, type_name = _utils.get_qualified_name(type(module))
raise TypeError("Unexpected module type '%s' (expected string or"
" module type only)" % type_name)
prefix = "The '%s' module usage is deprecated" % module_name
raise TypeError(
f"Unexpected module type '{type_name}' (expected string or"
" module type only)"
)
prefix = f"The '{module_name}' module usage is deprecated"
if replacement:
postfix = ", please use %s instead" % replacement
postfix = f", please use {replacement} instead"
else:
postfix = None
out_message = _utils.generate_message(prefix,
postfix=postfix, message=message,
version=version,
removal_version=removal_version)
_utils.deprecation(out_message,
stacklevel=stacklevel, category=category)
out_message = _utils.generate_message(
prefix,
postfix=postfix,
message=message,
version=version,
removal_version=removal_version,
)
_utils.deprecation(out_message, stacklevel=stacklevel, category=category)

View File

@@ -20,22 +20,34 @@ _KWARG_RENAMED_POSTFIX_TPL = ", please use the '%s' argument instead"
_KWARG_RENAMED_PREFIX_TPL = "Using the '%s' argument is deprecated"
def renamed_kwarg(old_name, new_name, message=None,
version=None, removal_version=None, stacklevel=3,
category=None, replace=False):
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)
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)
_utils.deprecation(
out_message, stacklevel=stacklevel, category=category
)
if replace:
kwargs.setdefault(new_name, kwargs.pop(old_name))
return wrapped(*args, **kwargs)

View File

@@ -17,5 +17,4 @@ import unittest
class TestCase(unittest.TestCase):
"""Test case base class for all unit tests."""

View File

@@ -45,11 +45,11 @@ def blip_blop_3(blop=1):
@updating.updated_kwarg_default_value('type', 'cat', 'feline')
def blip_blop_blip(type='cat'):
return "The %s meowed quietly" % type
return f"The {type} meowed quietly"
def blip_blop_blip_unwrapped(type='cat'):
return "The %s meowed quietly" % type
return f"The {type} meowed quietly"
class WoofWoof:
@@ -74,7 +74,6 @@ class WoofWoof:
class KittyKat:
@moves.moved_method('supermeow')
def meow(self, volume=11):
return self.supermeow(volume)
@@ -205,8 +204,9 @@ class ThingB:
OldHotness = moves.moved_class(NewHotness, 'OldHotness', __name__)
OldHotness2 = moves.moved_class(NewHotness, 'OldHotness', __name__,
category=PendingDeprecationWarning)
OldHotness2 = moves.moved_class(
NewHotness, 'OldHotness', __name__, category=PendingDeprecationWarning
)
class DeprecateAnythingTest(test_base.TestCase):
@@ -244,7 +244,6 @@ class MovedInheritableClassTest(test_base.TestCase):
self.assertEqual(PendingDeprecationWarning, w.category)
def test_existing_refer_subclass(self):
class MyOldThing(OldHotness):
pass
@@ -357,8 +356,10 @@ class MovedMethodTest(test_base.TestCase):
self.assertEqual(0, len(capture))
def test_keeps_argspec(self):
self.assertEqual(inspect.getfullargspec(KittyKat.supermeow),
inspect.getfullargspec(KittyKat.meow))
self.assertEqual(
inspect.getfullargspec(KittyKat.supermeow),
inspect.getfullargspec(KittyKat.meow),
)
class RenamedKwargTest(test_base.TestCase):
@@ -416,8 +417,10 @@ class RenamedKwargTest(test_base.TestCase):
def test_argspec(self):
# The decorated function keeps its argspec.
self.assertEqual(inspect.getfullargspec(blip_blop_unwrapped),
inspect.getfullargspec(blip_blop))
self.assertEqual(
inspect.getfullargspec(blip_blop_unwrapped),
inspect.getfullargspec(blip_blop),
)
class UpdatedArgsTest(test_base.TestCase):
@@ -433,13 +436,15 @@ class UpdatedArgsTest(test_base.TestCase):
with warnings.catch_warnings(record=True) as capture:
warnings.simplefilter("always")
self.assertEqual(
'The kitten meowed quietly',
blip_blop_blip(type='kitten'))
'The kitten meowed quietly', blip_blop_blip(type='kitten')
)
self.assertEqual(0, len(capture))
def test_argspec_preserved(self):
self.assertEqual(inspect.getfullargspec(blip_blop_blip_unwrapped),
inspect.getfullargspec(blip_blop_blip))
self.assertEqual(
inspect.getfullargspec(blip_blop_blip_unwrapped),
inspect.getfullargspec(blip_blop_blip),
)
class RemovalTests(test_base.TestCase):
@@ -453,10 +458,10 @@ class RemovalTests(test_base.TestCase):
# The decorated function keeps its argspec.
self.assertEqual(
inspect.getfullargspec(crimson_lightning_unwrapped),
inspect.getfullargspec(crimson_lightning))
inspect.getfullargspec(crimson_lightning),
)
def test_deprecated_kwarg(self):
@removals.removed_kwarg('b')
def f(b=2):
return b
@@ -481,11 +486,11 @@ class RemovalTests(test_base.TestCase):
def f_unwrapped(b=2):
return b
self.assertEqual(inspect.getfullargspec(f_unwrapped),
inspect.getfullargspec(f))
self.assertEqual(
inspect.getfullargspec(f_unwrapped), inspect.getfullargspec(f)
)
def test_pending_deprecated_kwarg(self):
@removals.removed_kwarg('b', category=PendingDeprecationWarning)
def f(b=2):
return b
@@ -654,8 +659,9 @@ class RemovalTests(test_base.TestCase):
def test_pending_removed_module(self):
with warnings.catch_warnings(record=True) as capture:
warnings.simplefilter("always")
removals.removed_module(__name__,
category=PendingDeprecationWarning)
removals.removed_module(
__name__, category=PendingDeprecationWarning
)
self.assertEqual(1, len(capture))
w = capture[0]
self.assertEqual(PendingDeprecationWarning, w.category)

View File

@@ -18,22 +18,30 @@ from inspect import signature
from debtcollector import _utils
_KWARG_UPDATED_POSTFIX_TPL = (', please update the code to explicitly set %s '
'as the value')
_KWARG_UPDATED_PREFIX_TPL = ('The %s argument is changing its default value '
'to %s')
_KWARG_UPDATED_POSTFIX_TPL = (
', please update the code to explicitly set %s as the value'
)
_KWARG_UPDATED_PREFIX_TPL = (
'The %s argument is changing its default value to %s'
)
def updated_kwarg_default_value(name, old_value, new_value, message=None,
version=None, stacklevel=3,
category=FutureWarning):
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)
prefix, postfix=postfix, message=message, version=version
)
def decorator(f):
sig = signature(f)
@@ -41,14 +49,13 @@ def updated_kwarg_default_value(name, old_value, new_value, message=None,
@wrapt.decorator
def wrapper(wrapped, instance, args, kwargs):
explicit_params = set(
varnames[:len(args)] + list(kwargs.keys())
)
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)
_utils.deprecation(
out_message, stacklevel=stacklevel, category=category
)
return wrapped(*args, **kwargs)
return wrapper(f)

View File

@@ -69,16 +69,19 @@ html_theme = 'openstackdocs'
# Output file base name for HTML help builder.
htmlhelp_basename = '%sdoc' % project
htmlhelp_basename = f'{project}doc'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass
# [howto/manual]).
latex_documents = [
('index',
'%s.tex' % project,
'%s Documentation' % project,
'OpenStack Foundation', 'manual'),
(
'index',
f'{project}.tex',
f'{project} Documentation',
'OpenStack Foundation',
'manual',
),
]
# -- Options for autoddoc ----------------------------------------------------

View File

@@ -34,3 +34,13 @@ Repository = "https://opendev.org/openstack/debtcollector/"
packages = [
"debtcollector"
]
[tool.ruff]
line-length = 79
[tool.ruff.format]
quote-style = "preserve"
docstring-code-format = true
[tool.ruff.lint]
select = ["E4", "E5", "E7", "E9", "F", "U"]

View File

@@ -192,10 +192,8 @@ htmlhelp_basename = 'debtcollectorReleaseNotesDoc'
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}
@@ -204,9 +202,13 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'debtcollectorReleaseNotes.tex',
'debtcollector Release Notes Documentation',
'debtcollector Developers', 'manual'),
(
'index',
'debtcollectorReleaseNotes.tex',
'debtcollector Release Notes Documentation',
'debtcollector Developers',
'manual',
),
]
# The name of an image file (relative to this directory) to place at the top of
@@ -235,9 +237,13 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'debtcollectorReleaseNotes',
'debtcollector Release Notes Documentation',
['debtcollector Developers'], 1)
(
'index',
'debtcollectorReleaseNotes',
'debtcollector Release Notes Documentation',
['debtcollector Developers'],
1,
)
]
# If true, show URL addresses after external links.
@@ -250,11 +256,15 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'debtcollectorReleaseNotes',
'debtcollector Release Notes Documentation',
'debtcollector Developers', 'debtcollectorReleaseNotes',
'One line description of project.',
'Miscellaneous'),
(
'index',
'debtcollectorReleaseNotes',
'debtcollector Release Notes Documentation',
'debtcollector Developers',
'debtcollectorReleaseNotes',
'One line description of project.',
'Miscellaneous',
),
]
# Documents to append as an appendix to all manuals.

View File

@@ -16,6 +16,4 @@
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
import setuptools
setuptools.setup(
setup_requires=['pbr>=2.0.0'],
pbr=True)
setuptools.setup(setup_requires=['pbr>=2.0.0'], pbr=True)

View File

@@ -40,10 +40,9 @@ deps =
commands = sphinx-build -W --keep-going -b html -d doc/build/doctrees doc/source doc/build/html
[flake8]
# E123, E125 skipped as they are invalid PEP-8.
show-source = True
ignore = E123,E125
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
# We only enable the hacking (H) checks
select = H
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build
[testenv:releasenotes]
deps = {[testenv:docs]deps}