mirror of https://github.com/celery/kombu.git
Improve pre-commit checks and fix all new lint errors (#2124)
* Added pyproject.toml * Imported .pre-commit-config.yaml config from Celery * Codespell Fixes * Fixed lint errors * Added back autoflake
This commit is contained in:
parent
e845d5bf3a
commit
b48d1cbab0
|
@ -3,7 +3,7 @@ repos:
|
|||
rev: v3.17.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: ["--py37-plus", "--keep-runtime-typing"]
|
||||
args: ["--py38-plus"]
|
||||
|
||||
- repo: https://github.com/PyCQA/autoflake
|
||||
rev: v2.3.1
|
||||
|
@ -20,7 +20,14 @@ repos:
|
|||
rev: v1.5.0
|
||||
hooks:
|
||||
- id: yesqa
|
||||
exclude: ^kombu/messaging\.py$|^kombu/serialization\.py$
|
||||
|
||||
- repo: https://github.com/codespell-project/codespell
|
||||
rev: v2.3.0
|
||||
hooks:
|
||||
- id: codespell # See pyproject.toml for args
|
||||
args: [--toml, pyproject.toml, --write-changes]
|
||||
additional_dependencies:
|
||||
- tomli
|
||||
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.6.0
|
||||
|
@ -34,3 +41,9 @@ repos:
|
|||
rev: 5.13.2
|
||||
hooks:
|
||||
- id: isort
|
||||
|
||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: v1.11.2
|
||||
hooks:
|
||||
- id: mypy
|
||||
pass_filenames: false
|
||||
|
|
2
Makefile
2
Makefile
|
@ -40,7 +40,7 @@ help:
|
|||
@echo "readme - Regenerate README.rst file."
|
||||
@echo "contrib - Regenerate CONTRIBUTING.rst file"
|
||||
@echo "clean-dist --------- - Clean all distribution build artifacts."
|
||||
@echo " clean-git-force - Remove all uncomitted files."
|
||||
@echo " clean-git-force - Remove all uncommitted files."
|
||||
@echo " clean ------------ - Non-destructive clean"
|
||||
@echo " clean-pyc - Remove .pyc/__pycache__ files"
|
||||
@echo " clean-docs - Remove documentation build artifacts."
|
||||
|
|
|
@ -23,7 +23,7 @@ with Connection('amqp://guest:guest@localhost:5672//') as conn:
|
|||
print(message.payload)
|
||||
|
||||
####
|
||||
#: If you don't use the with statement then you must aways
|
||||
#: If you don't use the with statement then you must always
|
||||
# remember to close objects after use:
|
||||
# queue.close()
|
||||
# connection.close()
|
||||
|
|
|
@ -78,7 +78,7 @@ class AsyncSQSConnection(AsyncAWSQueryConnection):
|
|||
|
||||
def make_request(self, operation_name, params, queue_url, verb, callback=None): # noqa
|
||||
"""
|
||||
Overide make_request to support different protocols.
|
||||
Override make_request to support different protocols.
|
||||
|
||||
botocore is soon going to change the default protocol of communicating
|
||||
with SQS backend from 'query' to 'json', so we need a special
|
||||
|
|
|
@ -89,7 +89,7 @@ registry = MatcherRegistry()
|
|||
|
||||
:param data: The data that should be matched. Must be string.
|
||||
:param pattern: The pattern that should be applied. Must be string.
|
||||
:keyword matcher: An optional string representing the mathcing
|
||||
:keyword matcher: An optional string representing the matching
|
||||
method (for example, `glob` or `pcre`).
|
||||
|
||||
If :const:`None` (default), then `glob` will be used.
|
||||
|
@ -108,7 +108,7 @@ match = registry.match
|
|||
.. function:: register(name, matcher):
|
||||
Register a new matching method.
|
||||
|
||||
:param name: A convenient name for the mathing method.
|
||||
:param name: A convenient name for the matching method.
|
||||
:param matcher: A method that will be passed data and pattern.
|
||||
"""
|
||||
register = registry.register
|
||||
|
|
|
@ -51,7 +51,7 @@ class Producer:
|
|||
#: Default compression method. Disabled by default.
|
||||
compression = None
|
||||
|
||||
#: By default, if a defualt exchange is set,
|
||||
#: By default, if a default exchange is set,
|
||||
#: that exchange will be declare when publishing a message.
|
||||
auto_declare = True
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ class Resource:
|
|||
# not evaluated yet, just put it back
|
||||
self._resource.put_nowait(R)
|
||||
else:
|
||||
# evaluted so must try to release/close first.
|
||||
# evaluated so must try to release/close first.
|
||||
self.release(R)
|
||||
raise
|
||||
self._dirty.add(R)
|
||||
|
|
|
@ -59,7 +59,7 @@ from __future__ import annotations
|
|||
|
||||
import string
|
||||
from queue import Empty
|
||||
from typing import Any, Dict, Set
|
||||
from typing import Any
|
||||
|
||||
import azure.core.exceptions
|
||||
import azure.servicebus.exceptions
|
||||
|
@ -122,8 +122,8 @@ class Channel(virtual.Channel):
|
|||
# Max time to backoff (is the default from service bus repo)
|
||||
default_retry_backoff_max: int = 120
|
||||
domain_format: str = 'kombu%(vhost)s'
|
||||
_queue_cache: Dict[str, SendReceive] = {}
|
||||
_noack_queues: Set[str] = set()
|
||||
_queue_cache: dict[str, SendReceive] = {}
|
||||
_noack_queues: set[str] = set()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
|
|
@ -54,7 +54,7 @@ from __future__ import annotations
|
|||
|
||||
import string
|
||||
from queue import Empty
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from azure.core.exceptions import ResourceExistsError
|
||||
|
||||
|
@ -87,7 +87,7 @@ class Channel(virtual.Channel):
|
|||
"""Azure Storage Queues channel."""
|
||||
|
||||
domain_format: str = 'kombu%(vhost)s'
|
||||
_queue_service: Optional[QueueServiceClient] = None
|
||||
_queue_service: QueueServiceClient | None = None
|
||||
_queue_name_cache: dict[Any, Any] = {}
|
||||
no_ack: bool = True
|
||||
_noack_queues: set[Any] = set()
|
||||
|
@ -201,7 +201,7 @@ class Transport(virtual.Transport):
|
|||
Channel = Channel
|
||||
|
||||
polling_interval: int = 1
|
||||
default_port: Optional[int] = None
|
||||
default_port: int | None = None
|
||||
can_parse_url: bool = True
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -58,7 +58,7 @@ All parameters are passed to ``ssl`` parameter of
|
|||
:class:`amqp.connection.Connection` class.
|
||||
|
||||
SSL option ``server_hostname`` can be set to ``None`` which is causing using
|
||||
hostname from broker URL. This is usefull when failover is used to fill
|
||||
hostname from broker URL. This is useful when failover is used to fill
|
||||
``server_hostname`` with currently used broker::
|
||||
|
||||
conn = Connect('amqp://broker1.example.com;broker2.example.com', ssl={
|
||||
|
|
|
@ -356,7 +356,7 @@ class QoS(virtual.QoS):
|
|||
def append(self, message, delivery_tag):
|
||||
delivery = message.delivery_info
|
||||
EX, RK = delivery['exchange'], delivery['routing_key']
|
||||
# TODO: Remove this once we soley on Redis-py 3.0.0+
|
||||
# TODO: Remove this once we solely on Redis-py 3.0.0+
|
||||
if redis.VERSION[0] >= 3:
|
||||
# Redis-py changed the format of zadd args in v3.0.0
|
||||
zadd_args = [{delivery_tag: time()}]
|
||||
|
@ -747,7 +747,7 @@ class Channel(virtual.Channel):
|
|||
raise
|
||||
|
||||
self.connection.cycle.add(self) # add to channel poller.
|
||||
# and set to true after sucessfuly added channel to the poll.
|
||||
# and set to true after successfully added channel to the poll.
|
||||
self._registered = True
|
||||
|
||||
# copy errors, in case channel closed but threads still
|
||||
|
|
|
@ -11,7 +11,7 @@ from kombu.log import get_logger
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from logging import Logger
|
||||
from typing import Any, Callable, Dict, List, Optional
|
||||
from typing import Any, Callable
|
||||
|
||||
from kombu.transport.base import Transport
|
||||
|
||||
|
@ -19,8 +19,8 @@ __all__ = ('setup_logging', 'Logwrapped')
|
|||
|
||||
|
||||
def setup_logging(
|
||||
loglevel: Optional[int] = logging.DEBUG,
|
||||
loggers: Optional[List[str]] = None
|
||||
loglevel: int | None = logging.DEBUG,
|
||||
loggers: list[str] | None = None
|
||||
) -> None:
|
||||
"""Setup logging to stdout."""
|
||||
loggers = ['kombu.connection', 'kombu.channel'] if not loggers else loggers
|
||||
|
@ -38,8 +38,8 @@ class Logwrapped:
|
|||
def __init__(
|
||||
self,
|
||||
instance: Transport,
|
||||
logger: Optional[Logger] = None,
|
||||
ident: Optional[str] = None
|
||||
logger: Logger | None = None,
|
||||
ident: str | None = None
|
||||
):
|
||||
self.instance = instance
|
||||
self.logger = get_logger(logger)
|
||||
|
@ -52,7 +52,7 @@ class Logwrapped:
|
|||
return meth
|
||||
|
||||
@wraps(meth)
|
||||
def __wrapped(*args: List[Any], **kwargs: Dict[str, Any]) -> Callable:
|
||||
def __wrapped(*args: list[Any], **kwargs: dict[str, Any]) -> Callable:
|
||||
info = ''
|
||||
if self.ident:
|
||||
info += self.ident.format(self.instance)
|
||||
|
@ -73,5 +73,5 @@ class Logwrapped:
|
|||
def __repr__(self) -> str:
|
||||
return repr(self.instance)
|
||||
|
||||
def __dir__(self) -> List[str]:
|
||||
def __dir__(self) -> list[str]:
|
||||
return dir(self.instance)
|
||||
|
|
|
@ -54,7 +54,7 @@ class FairCycle:
|
|||
try:
|
||||
return self.fun(resource, callback, **kwargs)
|
||||
except self.predicate:
|
||||
# reraise when retries exchausted.
|
||||
# reraise when retries exhausted.
|
||||
if tried >= len(self.resources) - 1:
|
||||
raise
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
[tool.codespell]
|
||||
ignore-words-list = "assertin"
|
||||
skip = "./.*,docs/AUTHORS.txt,docs/history/*,docs/spelling_wordlist.txt,Changelog.rst,CONTRIBUTORS.txt,*.key"
|
||||
|
||||
[tool.coverage.run]
|
||||
branch = true
|
||||
cover_pylib = false
|
||||
include = ["*kombu/*"]
|
||||
omit = ["kombu.tests.*"]
|
||||
|
||||
[tool.coverage.report]
|
||||
exclude_lines = [
|
||||
"pragma: no cover",
|
||||
"if TYPE_CHECKING:",
|
||||
"except ImportError:"
|
||||
]
|
||||
omit = [
|
||||
"*/python?.?/*",
|
||||
"*/site-packages/*",
|
||||
"*/pypy/*",
|
||||
"*kombu/utils/debug.py",
|
||||
]
|
|
@ -163,7 +163,7 @@ class test_Connection:
|
|||
conn._ensure_connection = Mock()
|
||||
|
||||
conn.connect()
|
||||
# ensure_connection must be called to return immidiately
|
||||
# ensure_connection must be called to return immediately
|
||||
# and fail with transport exception
|
||||
conn._ensure_connection.assert_called_with(
|
||||
max_retries=1, reraise_as_library_errors=False
|
||||
|
@ -182,7 +182,7 @@ class test_Connection:
|
|||
|
||||
conn.connect()
|
||||
# connect() is ignoring transport options
|
||||
# ensure_connection must be called to return immidiately
|
||||
# ensure_connection must be called to return immediately
|
||||
# and fail with transport exception
|
||||
conn._ensure_connection.assert_called_with(
|
||||
max_retries=1, reraise_as_library_errors=False
|
||||
|
|
|
@ -1005,5 +1005,5 @@ class test_Channel:
|
|||
)
|
||||
output_message = self.queue(self.channel).get()
|
||||
assert message == output_message.payload
|
||||
# It's not propogated to the properties
|
||||
# It's not propagated to the properties
|
||||
assert 'message_attributes' not in output_message.properties
|
||||
|
|
|
@ -118,7 +118,7 @@ def test_queue_service_nocredentials():
|
|||
|
||||
|
||||
def test_queue_service_sas():
|
||||
# Test gettings queue service without credentials
|
||||
# Test getting queue service without credentials
|
||||
conn = Connection(URL_CREDS_SAS, transport=azureservicebus.Transport)
|
||||
with patch('kombu.transport.azureservicebus.ServiceBusClient') as m:
|
||||
channel = conn.channel()
|
||||
|
|
|
@ -28,7 +28,7 @@ def test_queue_service_nocredentials():
|
|||
|
||||
|
||||
def test_queue_service():
|
||||
# Test gettings queue service without credentials
|
||||
# Test getting queue service without credentials
|
||||
conn = Connection(URL_CREDS, transport=azurestoragequeues.Transport)
|
||||
with patch('kombu.transport.azurestoragequeues.QueueServiceClient'):
|
||||
channel = conn.channel()
|
||||
|
|
|
@ -392,11 +392,11 @@ class test_Channel:
|
|||
# the connection was added to the cycle
|
||||
conn.transport.cycle.add.assert_called_once()
|
||||
assert len(conn.transport.channels) == 1
|
||||
# the channel was flaged as registered into poller
|
||||
# the channel was flagged as registered into poller
|
||||
assert chan._registered
|
||||
|
||||
def test_redis_on_disconnect_channel_only_if_was_registered(self):
|
||||
"""Test shoud check if the _on_disconnect method is called only
|
||||
"""Test should check if the _on_disconnect method is called only
|
||||
if the channel was registered into the poller."""
|
||||
# given: mock pool and client
|
||||
pool = Mock(name='pool')
|
||||
|
@ -437,7 +437,7 @@ class test_Channel:
|
|||
transport_options={},
|
||||
hostname="127.0.0.1",
|
||||
virtual_host=None)))
|
||||
# create the _connparams with overriden connection_class
|
||||
# create the _connparams with overridden connection_class
|
||||
connparams = chan._connparams(asynchronous=True)
|
||||
# create redis.Connection
|
||||
redis_connection = connparams['connection_class']()
|
||||
|
@ -498,7 +498,7 @@ class test_Channel:
|
|||
transport_options={},
|
||||
hostname="127.0.0.1",
|
||||
virtual_host=None)))
|
||||
# create the _connparams with overriden connection_class
|
||||
# create the _connparams with overridden connection_class
|
||||
connparams = chan._connparams(asynchronous=True)
|
||||
# create redis.Connection
|
||||
redis_connection = connparams['connection_class']()
|
||||
|
|
Loading…
Reference in New Issue