From bf076b6f58645167b5f207e1d8ca60c1bcec260c Mon Sep 17 00:00:00 2001 From: Dmitry Orlov Date: Mon, 16 Nov 2020 16:11:25 +0300 Subject: [PATCH 1/3] drop 3.5 support --- .drone.yml | 182 -------------------------------- .github/workflows/tox.yml | 2 - setup.py | 7 +- tests/conftest.py | 13 +-- tests/test_amqp_robust_proxy.py | 4 +- tox.ini | 2 +- 6 files changed, 9 insertions(+), 201 deletions(-) delete mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 57e0b636..00000000 --- a/.drone.yml +++ /dev/null @@ -1,182 +0,0 @@ ---- -kind: pipeline -name: default - - -steps: - - name: prepare toxenv - image: snakepacker/python:all - group: tests - pull: always - commands: - - tox --notest - volumes: - - name: cache - path: /drone/src/.tox - - - name: linter - image: snakepacker/python:all - commands: - - tox - environment: - TOXENV: lint - volumes: - - name: cache - path: /drone/src/.tox - - - name: mypy - image: snakepacker/python:all - group: tests - pull: always - commands: - - tox - environment: - TOXENV: mypy - volumes: - - name: cache - path: /drone/src/.tox - - - name: checkdoc - image: snakepacker/python:all - group: tests - pull: always - commands: - - tox - environment: - TOXENV: checkdoc - volumes: - - name: cache - path: /drone/src/.tox - - - name: python 3.8 - image: snakepacker/python:all - commands: - - tox - environment: - AMQP_URL: amqp://guest:guest@rabbitmq - TOXENV: py38 - COVERALLS_REPO_TOKEN: - from_secret: COVERALLS_TOKEN - volumes: - - name: cache - path: /drone/src/.tox - - - name: python 3.8 uvloop - image: snakepacker/python:all - commands: - - tox - environment: - AMQP_URL: amqp://guest:guest@rabbitmq - TOXENV: py38-uvloop - COVERALLS_REPO_TOKEN: - from_secret: COVERALLS_TOKEN - volumes: - - name: cache - path: /drone/src/.tox - - - name: python 3.7 - image: snakepacker/python:all - commands: - - tox - environment: - AMQP_URL: amqp://guest:guest@rabbitmq - TOXENV: py37 - COVERALLS_REPO_TOKEN: - from_secret: COVERALLS_TOKEN - volumes: - - name: cache - path: /drone/src/.tox - - - name: python 3.7 uvloop - image: snakepacker/python:all - commands: - - tox - environment: - AMQP_URL: amqp://guest:guest@rabbitmq - TOXENV: py37-uvloop - COVERALLS_REPO_TOKEN: - from_secret: COVERALLS_TOKEN - volumes: - - name: cache - path: /drone/src/.tox - - - name: python 3.6 - image: snakepacker/python:all - commands: - - tox - environment: - AMQP_URL: amqp://guest:guest@rabbitmq - TOXENV: py36 - COVERALLS_REPO_TOKEN: - from_secret: COVERALLS_TOKEN - volumes: - - name: cache - path: /drone/src/.tox - - - name: python 3.6 uvloop - image: snakepacker/python:all - commands: - - tox - environment: - AMQP_URL: amqp://guest:guest@rabbitmq - TOXENV: py36-uvloop - COVERALLS_REPO_TOKEN: - from_secret: COVERALLS_TOKEN - volumes: - - name: cache - path: /drone/src/.tox - - - name: python 3.5 - image: snakepacker/python:all - commands: - - tox - environment: - AMQP_URL: amqp://guest:guest@rabbitmq - TOXENV: py35 - COVERALLS_REPO_TOKEN: - from_secret: COVERALLS_TOKEN - volumes: - - name: cache - path: /drone/src/.tox - - - name: python 3.5 uvloop - image: snakepacker/python:all - commands: - - tox - environment: - AMQP_URL: amqp://guest:guest@rabbitmq - TOXENV: py35-uvloop - COVERALLS_REPO_TOKEN: - from_secret: COVERALLS_TOKEN - volumes: - - name: cache - path: /drone/src/.tox - - - name: notify - image: drillster/drone-email - settings: - host: - from_secret: SMTP_HOST - username: - from_secret: SMTP_USERNAME - password: - from_secret: SMTP_PASSWORD - from: - from_secret: SMTP_USERNAME - when: - status: - - changed - - failure - -volumes: - - name: cache - temp: {} - -services: - - name: rabbitmq - image: rabbitmq:3-alpine ---- -kind: signature -hmac: 32a7f019710b16f795a6531ef6fab89d2ab24f50aaee729c3a7379a0dda472b0 - -... diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 7fe22292..1cfcb1ba 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -46,12 +46,10 @@ jobs: matrix: toxenv: - - py35 - py36 - py37 - py38 - py39 - - py35-uvloop - py36-uvloop - py37-uvloop - py38-uvloop diff --git a/setup.py b/setup.py index 5453a495..1c5cabcc 100644 --- a/setup.py +++ b/setup.py @@ -29,21 +29,20 @@ "Operating System :: Microsoft", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", "Programming Language :: Python :: Implementation :: PyPy", "Programming Language :: Python :: Implementation :: CPython", ], packages=find_packages(exclude=["tests"]), package_data={"aio_pika": ["py.typed"]}, - install_requires=["aiormq>=3.2.3,<4", "yarl"], - python_requires=">3.5.*, <4", + install_requires=["aiormq~=4.0", "yarl"], + python_requires=">3.6.*, <4", extras_require={ "develop": [ "aiomisc~=10.1.6", - "async_generator", "coverage!=4.3", "coveralls", "pylava", diff --git a/tests/conftest.py b/tests/conftest.py index 2112756c..43fc7e63 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,6 @@ import pamqp import pytest from aiomisc import awaitable -from async_generator import async_generator, yield_ from yarl import URL import aio_pika @@ -17,7 +16,6 @@ @pytest.fixture -@async_generator async def add_cleanup(loop): entities = [] @@ -27,7 +25,7 @@ def payload(func, *args, **kwargs): entities.append(func) try: - await yield_(payload) + yield payload finally: for func in entities[::-1]: await func() @@ -36,7 +34,6 @@ def payload(func, *args, **kwargs): @pytest.fixture -@async_generator async def create_task(loop): tasks = [] @@ -47,7 +44,7 @@ def payload(coroutine): return task try: - await yield_(payload) + yield payload finally: cancelled = [] for task in tasks: @@ -117,18 +114,16 @@ async def fabric(cleanup=True, connection=None, *args, **kwargs): # noinspection PyTypeChecker @pytest.fixture -@async_generator async def connection(create_connection) -> aio_pika.Connection: async with await create_connection() as conn: - await yield_(conn) + yield conn # noinspection PyTypeChecker @pytest.fixture -@async_generator async def channel(connection: aio_pika.Connection) -> aio_pika.Channel: async with connection.channel() as ch: - await yield_(ch) + yield ch @pytest.fixture diff --git a/tests/test_amqp_robust_proxy.py b/tests/test_amqp_robust_proxy.py index 7c6ee6e4..33dbfdd2 100644 --- a/tests/test_amqp_robust_proxy.py +++ b/tests/test_amqp_robust_proxy.py @@ -9,7 +9,6 @@ import pytest import shortuuid from aiomisc_pytest.pytest_plugin import TCPProxy -from async_generator import async_generator, yield_ from yarl import URL import aio_pika @@ -21,13 +20,12 @@ @pytest.fixture -@async_generator async def proxy(tcp_proxy: Type[TCPProxy], amqp_direct_url: URL): p = tcp_proxy(amqp_direct_url.host, amqp_direct_url.port) await p.start() try: - await yield_(p) + yield p finally: await p.close() diff --git a/tox.ini b/tox.ini index 7e3409c8..6db14302 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = lint,py3{5,6,7},py3{5,6,7}-{uvloop} +envlist = lint,py3{6,7,8,9},py3{6,7,8}-{uvloop} [testenv] passenv = COVERALLS_* AMQP_* From 2353215c35dda72557757c8d4a8d48ad38737ada Mon Sep 17 00:00:00 2001 From: Dmitry Orlov Date: Mon, 16 Nov 2020 16:27:59 +0300 Subject: [PATCH 2/3] fixes --- aio_pika/channel.py | 9 +++++---- aio_pika/exceptions.py | 4 +--- aio_pika/exchange.py | 9 +++++---- aio_pika/message.py | 12 ++++++------ aio_pika/queue.py | 17 +++++++++-------- aio_pika/robust_channel.py | 4 ++-- aio_pika/transaction.py | 3 ++- 7 files changed, 30 insertions(+), 28 deletions(-) diff --git a/aio_pika/channel.py b/aio_pika/channel.py index 4e983b7e..917ea151 100644 --- a/aio_pika/channel.py +++ b/aio_pika/channel.py @@ -6,6 +6,7 @@ import aiormq import aiormq.types +from pamqp import commands from .exchange import Exchange, ExchangeType from .message import IncomingMessage @@ -335,7 +336,7 @@ async def set_qos( global_: bool = False, timeout: TimeoutType = None, all_channels: bool = None, - ) -> aiormq.spec.Basic.QosOk: + ) -> commands.Basic.QosOk: if all_channels is not None: warn('Use "global_" instead of "all_channels"', DeprecationWarning) global_ = all_channels @@ -356,7 +357,7 @@ async def queue_delete( if_unused: bool = False, if_empty: bool = False, nowait: bool = False, - ) -> aiormq.spec.Queue.DeleteOk: + ) -> commands.Queue.DeleteOk: return await asyncio.wait_for( self.channel.queue_delete( queue=queue_name, @@ -373,7 +374,7 @@ async def exchange_delete( timeout: TimeoutType = None, if_unused: bool = False, nowait: bool = False, - ) -> aiormq.spec.Exchange.DeleteOk: + ) -> commands.Exchange.DeleteOk: return await asyncio.wait_for( self.channel.exchange_delete( exchange=exchange_name, if_unused=if_unused, nowait=nowait, @@ -390,7 +391,7 @@ def transaction(self) -> Transaction: return Transaction(self._channel) - async def flow(self, active: bool = True) -> aiormq.spec.Channel.FlowOk: + async def flow(self, active: bool = True) -> commands.Channel.FlowOk: return await self.channel.flow(active=active) def __del__(self): diff --git a/aio_pika/exceptions.py b/aio_pika/exceptions.py index 1f62c8f7..59992b18 100644 --- a/aio_pika/exceptions.py +++ b/aio_pika/exceptions.py @@ -11,9 +11,7 @@ ) -PAMQP_EXCEPTIONS = (pamqp.exceptions.PAMQPException,) + tuple( - pamqp.specification.ERRORS.values(), -) +PAMQP_EXCEPTIONS = (pamqp.exceptions.PAMQPException,) CONNECTION_EXCEPTIONS = ( RuntimeError, diff --git a/aio_pika/exchange.py b/aio_pika/exchange.py index b22df2af..42284694 100644 --- a/aio_pika/exchange.py +++ b/aio_pika/exchange.py @@ -4,6 +4,7 @@ from typing import Optional, Union import aiormq +import pamqp.commands from .message import Message from .types import TimeoutType @@ -77,7 +78,7 @@ def __repr__(self): async def declare( self, timeout: TimeoutType = None - ) -> aiormq.spec.Exchange.DeclareOk: + ) -> pamqp.commands.Exchange.DeclareOk: return await asyncio.wait_for( self.channel.exchange_declare( self.name, @@ -109,7 +110,7 @@ async def bind( *, arguments: dict = None, timeout: TimeoutType = None - ) -> aiormq.spec.Exchange.BindOk: + ) -> pamqp.commands.Exchange.BindOk: """ A binding can also be a relationship between two exchanges. This can be simply read as: this exchange is interested in messages @@ -169,7 +170,7 @@ async def unbind( routing_key: str = "", arguments: dict = None, timeout: TimeoutType = None, - ) -> aiormq.spec.Exchange.UnbindOk: + ) -> pamqp.commands.Exchange.UnbindOk: """ Remove exchange-to-exchange binding for this :class:`Exchange` instance @@ -244,7 +245,7 @@ async def publish( async def delete( self, if_unused: bool = False, timeout: TimeoutType = None - ) -> aiormq.spec.Exchange.DeleteOk: + ) -> pamqp.commands.Exchange.DeleteOk: """ Delete the queue diff --git a/aio_pika/message.py b/aio_pika/message.py index ff1c8eff..33c87dd3 100644 --- a/aio_pika/message.py +++ b/aio_pika/message.py @@ -12,7 +12,7 @@ ) from warnings import warn -import aiormq +import pamqp.commands from aiormq.types import DeliveredMessage from .exceptions import MessageProcessError @@ -369,9 +369,9 @@ def locked(self) -> bool: return bool(self.__lock) @property - def properties(self) -> aiormq.spec.Basic.Properties: - """ Build :class:`aiormq.spec.Basic.Properties` object """ - return aiormq.spec.Basic.Properties( + def properties(self) -> pamqp.commands.Basic.Properties: + """ Build :class:`pamqp.commands.Basic.Properties` object """ + return pamqp.commands.Basic.Properties( content_type=self.content_type, content_encoding=self.content_encoding, headers=self.headers_raw, @@ -499,11 +499,11 @@ def __init__(self, message: DeliveredMessage, no_ack: bool = False): self.redelivered = None self.message_count = None - if isinstance(message.delivery, aiormq.spec.Basic.GetOk): + if isinstance(message.delivery, pamqp.commands.Basic.GetOk): self.message_count = message.delivery.message_count self.delivery_tag = message.delivery.delivery_tag self.redelivered = message.delivery.redelivered - elif isinstance(message.delivery, aiormq.spec.Basic.Deliver): + elif isinstance(message.delivery, pamqp.commands.Basic.Deliver): self.consumer_tag = message.delivery.consumer_tag self.delivery_tag = message.delivery.delivery_tag self.redelivered = message.delivery.redelivered diff --git a/aio_pika/queue.py b/aio_pika/queue.py index b18ac336..34ab6d0b 100644 --- a/aio_pika/queue.py +++ b/aio_pika/queue.py @@ -5,6 +5,7 @@ from typing import Any, Callable, Optional import aiormq +import pamqp.commands from aiormq.types import DeliveredMessage from .exceptions import QueueEmpty @@ -51,7 +52,7 @@ def __init__( self.auto_delete = auto_delete self.arguments = arguments self.passive = passive - self.declaration_result = None # type: aiormq.spec.Queue.DeclareOk + self.declaration_result = None # type: pamqp.commands.Queue.DeclareOk self._get_lock = asyncio.Lock() @property @@ -80,7 +81,7 @@ def __repr__(self): async def declare( self, timeout: int = None - ) -> aiormq.spec.Queue.DeclareOk: + ) -> pamqp.commands.Queue.DeclareOk: """ Declare queue. :param timeout: execution timeout @@ -99,7 +100,7 @@ async def declare( passive=self.passive, ), timeout=timeout, - ) # type: aiormq.spec.Queue.DeclareOk + ) # type: pamqp.commands.Queue.DeclareOk self.name = self.declaration_result.queue return self.declaration_result @@ -111,7 +112,7 @@ async def bind( *, arguments=None, timeout: int = None - ) -> aiormq.spec.Queue.BindOk: + ) -> pamqp.commands.Queue.BindOk: """ A binding is a relationship between an exchange and a queue. This can be simply read as: the queue is interested in messages @@ -157,7 +158,7 @@ async def unbind( routing_key: str = None, arguments: dict = None, timeout: int = None, - ) -> aiormq.spec.Queue.UnbindOk: + ) -> pamqp.commands.Queue.UnbindOk: """ Remove binding from exchange for this :class:`Queue` instance @@ -243,7 +244,7 @@ async def consume( async def cancel( self, consumer_tag: ConsumerTag, timeout=None, nowait: bool = False - ) -> aiormq.spec.Basic.CancelOk: + ) -> pamqp.commands.Basic.CancelOk: """ This method cancels a consumer. This does not affect already delivered messages, but it does mean the server will not send any more messages for that consumer. The client may receive an arbitrary number @@ -295,7 +296,7 @@ async def get( async def purge( self, no_wait=False, timeout=None - ) -> aiormq.spec.Queue.PurgeOk: + ) -> pamqp.commands.Queue.PurgeOk: """ Purge all messages from the queue. :param no_wait: no wait response @@ -312,7 +313,7 @@ async def purge( async def delete( self, *, if_unused=True, if_empty=True, timeout=None - ) -> aiormq.spec.Queue.DeclareOk: + ) -> pamqp.commands.Queue.DeclareOk: """ Delete the queue. diff --git a/aio_pika/robust_channel.py b/aio_pika/robust_channel.py index 37511baf..a9ac6b0c 100644 --- a/aio_pika/robust_channel.py +++ b/aio_pika/robust_channel.py @@ -3,7 +3,7 @@ from typing import Union from warnings import warn -import aiormq +import pamqp.commands from .channel import Channel from .exchange import Exchange, ExchangeType @@ -144,7 +144,7 @@ async def exchange_delete( timeout: TimeoutType = None, if_unused=False, nowait=False, - ) -> aiormq.spec.Exchange.DeleteOk: + ) -> pamqp.commands.Exchange.DeleteOk: result = await super().exchange_delete( exchange_name=exchange_name, diff --git a/aio_pika/transaction.py b/aio_pika/transaction.py index e27c218c..abfe1938 100644 --- a/aio_pika/transaction.py +++ b/aio_pika/transaction.py @@ -2,6 +2,7 @@ from enum import Enum import aiormq +import pamqp.commands class TransactionStates(Enum): @@ -30,7 +31,7 @@ def channel(self) -> aiormq.Channel: return self._channel - async def select(self, timeout=None) -> aiormq.spec.Tx.SelectOk: + async def select(self, timeout=None) -> pamqp.commands.Tx.SelectOk: result = await asyncio.wait_for( self.channel.tx_select(), timeout=timeout, ) From e72ba3dc947ca8edf42790737ae349c6b4c77874 Mon Sep 17 00:00:00 2001 From: Dmitry Orlov Date: Mon, 16 Nov 2020 16:36:24 +0300 Subject: [PATCH 3/3] remove useless tuple --- aio_pika/exceptions.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/aio_pika/exceptions.py b/aio_pika/exceptions.py index 59992b18..ca85f6fe 100644 --- a/aio_pika/exceptions.py +++ b/aio_pika/exceptions.py @@ -10,15 +10,13 @@ ProtocolSyntaxError, PublishError, ) - -PAMQP_EXCEPTIONS = (pamqp.exceptions.PAMQPException,) - CONNECTION_EXCEPTIONS = ( RuntimeError, ConnectionError, OSError, AMQPError, -) + PAMQP_EXCEPTIONS + pamqp.exceptions.PAMQPException +) class MessageProcessError(AMQPError):