From 1e77d8fbc421cc6a5c13dfdd4eb92480f516fe45 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Fri, 11 Aug 2023 09:49:11 +0200 Subject: [PATCH 1/6] unblock aio-pika --- .../service-library/requirements/_aiohttp.txt | 16 +++++++- .../service-library/requirements/_base.txt | 24 +++++++++--- .../service-library/requirements/_fastapi.txt | 20 ++++++++-- .../service-library/requirements/_test.txt | 39 ++++++++++++++++++- .../service-library/requirements/_tools.txt | 4 +- requirements/constraints.txt | 4 -- 6 files changed, 91 insertions(+), 16 deletions(-) diff --git a/packages/service-library/requirements/_aiohttp.txt b/packages/service-library/requirements/_aiohttp.txt index b5d4e662e87..d2cde157750 100644 --- a/packages/service-library/requirements/_aiohttp.txt +++ b/packages/service-library/requirements/_aiohttp.txt @@ -2,10 +2,13 @@ # This file is autogenerated by pip-compile with Python 3.10 # by the following command: # -# pip-compile --output-file=requirements/_aiohttp.txt --resolver=backtracking --strip-extras requirements/_aiohttp.in +# pip-compile --output-file=requirements/_aiohttp.txt --strip-extras requirements/_aiohttp.in # aiohttp==3.8.5 # via + # -c requirements/./../../../packages/models-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../requirements/constraints.txt # -r requirements/_aiohttp.in # aiozipkin aiopg==1.4.0 @@ -115,14 +118,21 @@ psycopg2-binary==2.9.6 # sqlalchemy pydantic==1.10.11 # via + # -c requirements/./../../../packages/models-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../requirements/constraints.txt # -c requirements/./_base.in # -r requirements/./../../../packages/models-library/requirements/_base.in + # -r requirements/./../../../packages/settings-library/requirements/_base.in pygments==2.15.1 # via rich python-dateutil==2.8.2 # via arrow pyyaml==6.0.1 # via + # -c requirements/./../../../packages/models-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../requirements/constraints.txt # -c requirements/./_base.in # jsonschema-spec referencing==0.29.3 @@ -153,7 +163,9 @@ sniffio==1.3.0 # httpcore sqlalchemy==1.4.49 # via + # -c requirements/./../../../packages/models-library/requirements/../../../requirements/constraints.txt # -c requirements/./../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../requirements/constraints.txt # aiopg typer==0.9.0 # via -r requirements/./../../../packages/settings-library/requirements/_base.in @@ -164,7 +176,9 @@ typing-extensions==4.7.1 # typer urllib3==2.0.4 # via + # -c requirements/./../../../packages/models-library/requirements/../../../requirements/constraints.txt # -c requirements/./../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../requirements/constraints.txt # requests werkzeug==2.3.6 # via diff --git a/packages/service-library/requirements/_base.txt b/packages/service-library/requirements/_base.txt index 2277a24d53a..ad50cd0c741 100644 --- a/packages/service-library/requirements/_base.txt +++ b/packages/service-library/requirements/_base.txt @@ -2,9 +2,9 @@ # This file is autogenerated by pip-compile with Python 3.10 # by the following command: # -# pip-compile --output-file=requirements/_base.txt --resolver=backtracking --strip-extras requirements/_base.in +# pip-compile --output-file=requirements/_base.txt --strip-extras requirements/_base.in # -aio-pika==9.1.2 +aio-pika==9.2.1 # via -r requirements/_base.in aiodebug==2.3.0 # via -r requirements/_base.in @@ -14,9 +14,11 @@ aiofiles==23.1.0 # via -r requirements/_base.in aiohttp==3.8.5 # via + # -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt # -c requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/../../../requirements/constraints.txt # aiodocker -aiormq==6.7.6 +aiormq==6.7.7 # via aio-pika aiosignal==1.3.1 # via aiohttp @@ -76,7 +78,11 @@ pamqp==3.2.1 # via aiormq pydantic==1.10.11 # via + # -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt + # -c requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/../../../requirements/constraints.txt # -r requirements/../../../packages/models-library/requirements/_base.in + # -r requirements/../../../packages/settings-library/requirements/_base.in # -r requirements/_base.in pygments==2.15.1 # via rich @@ -85,9 +91,17 @@ pyinstrument==4.5.0 python-dateutil==2.8.2 # via arrow pyyaml==6.0.1 - # via -r requirements/_base.in + # via + # -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt + # -c requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/../../../requirements/constraints.txt + # -r requirements/_base.in redis==4.6.0 - # via -r requirements/_base.in + # via + # -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt + # -c requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/../../../requirements/constraints.txt + # -r requirements/_base.in referencing==0.29.3 # via # -c requirements/./constraints.txt diff --git a/packages/service-library/requirements/_fastapi.txt b/packages/service-library/requirements/_fastapi.txt index 78ec56ced5a..a9c660ee2c8 100644 --- a/packages/service-library/requirements/_fastapi.txt +++ b/packages/service-library/requirements/_fastapi.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile with Python 3.10 # by the following command: # -# pip-compile --output-file=requirements/_fastapi.txt --resolver=backtracking --strip-extras requirements/_fastapi.in +# pip-compile --output-file=requirements/_fastapi.txt --strip-extras requirements/_fastapi.in # anyio==3.7.1 # via @@ -31,7 +31,11 @@ email-validator==2.0.0.post2 exceptiongroup==1.1.2 # via anyio fastapi==0.99.1 - # via -r requirements/_fastapi.in + # via + # -c requirements/./../../../packages/models-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../requirements/constraints.txt + # -r requirements/_fastapi.in h11==0.14.0 # via # httpcore @@ -41,7 +45,11 @@ httpcore==0.17.3 # dnspython # httpx httpx==0.24.1 - # via -r requirements/_fastapi.in + # via + # -c requirements/./../../../packages/models-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../requirements/constraints.txt + # -r requirements/_fastapi.in idna==3.4 # via # anyio @@ -57,8 +65,12 @@ mdurl==0.1.2 # via markdown-it-py pydantic==1.10.11 # via + # -c requirements/./../../../packages/models-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../requirements/constraints.txt # -c requirements/./_base.in # -r requirements/./../../../packages/models-library/requirements/_base.in + # -r requirements/./../../../packages/settings-library/requirements/_base.in # fastapi pygments==2.15.1 # via rich @@ -85,7 +97,9 @@ sniffio==1.3.0 # httpx starlette==0.27.0 # via + # -c requirements/./../../../packages/models-library/requirements/../../../requirements/constraints.txt # -c requirements/./../../../packages/settings-library/requirements/../../../requirements/constraints.txt + # -c requirements/./../../../requirements/constraints.txt # fastapi typer==0.9.0 # via -r requirements/./../../../packages/settings-library/requirements/_base.in diff --git a/packages/service-library/requirements/_test.txt b/packages/service-library/requirements/_test.txt index 4bd3ebcb0ef..4b764880bc5 100644 --- a/packages/service-library/requirements/_test.txt +++ b/packages/service-library/requirements/_test.txt @@ -2,24 +2,30 @@ # This file is autogenerated by pip-compile with Python 3.10 # by the following command: # -# pip-compile --output-file=requirements/_test.txt --resolver=backtracking --strip-extras requirements/_test.in +# pip-compile --output-file=requirements/_test.txt --strip-extras requirements/_test.in # aiohttp==3.8.5 # via + # -c requirements/../../../requirements/constraints.txt # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # pytest-aiohttp aiosignal==1.3.1 # via # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # aiohttp asgi-lifespan==2.1.0 # via -r requirements/_test.in async-timeout==4.0.2 # via # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # aiohttp attrs==23.1.0 # via + # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # -c requirements/_fastapi.txt # aiohttp # jsonschema @@ -27,11 +33,14 @@ attrs==23.1.0 # referencing certifi==2023.5.7 # via + # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # -c requirements/_fastapi.txt # requests charset-normalizer==3.2.0 # via # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # aiohttp # requests coverage==7.2.7 @@ -42,6 +51,8 @@ docker==6.1.3 # via -r requirements/_test.in exceptiongroup==1.1.2 # via + # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # -c requirements/_fastapi.txt # pytest execnet==2.0.2 @@ -53,10 +64,13 @@ flaky==3.7.0 frozenlist==1.4.0 # via # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # aiohttp # aiosignal idna==3.4 # via + # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # -c requirements/_fastapi.txt # requests # yarl @@ -64,6 +78,8 @@ iniconfig==2.0.0 # via pytest jsonschema==4.18.4 # via + # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # -c requirements/_fastapi.txt # openapi-schema-validator # openapi-spec-validator @@ -73,6 +89,8 @@ jsonschema-spec==0.2.3 # openapi-spec-validator jsonschema-specifications==2023.7.1 # via + # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # -c requirements/_fastapi.txt # jsonschema # openapi-schema-validator @@ -83,6 +101,7 @@ lazy-object-proxy==1.9.0 multidict==6.0.4 # via # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # aiohttp # yarl openapi-schema-validator==0.6.0 @@ -90,7 +109,9 @@ openapi-schema-validator==0.6.0 # -c requirements/_aiohttp.txt # openapi-spec-validator openapi-spec-validator==0.6.0 - # via -r requirements/_test.in + # via + # -c requirements/_aiohttp.txt + # -r requirements/_test.in packaging==23.1 # via # docker @@ -138,16 +159,22 @@ pytest-xdist==3.3.1 # via -r requirements/_test.in python-dateutil==2.8.2 # via + # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # -c requirements/_fastapi.txt # faker python-dotenv==1.0.0 # via -r requirements/_test.in pyyaml==6.0.1 # via + # -c requirements/../../../requirements/constraints.txt # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # jsonschema-spec referencing==0.29.3 # via + # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # -c requirements/_fastapi.txt # jsonschema # jsonschema-spec @@ -163,16 +190,22 @@ rfc3339-validator==0.1.4 # openapi-schema-validator rpds-py==0.9.2 # via + # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # -c requirements/_fastapi.txt # jsonschema # referencing six==1.16.0 # via + # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # -c requirements/_fastapi.txt # python-dateutil # rfc3339-validator sniffio==1.3.0 # via + # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # -c requirements/_fastapi.txt # asgi-lifespan termcolor==2.3.0 @@ -183,6 +216,7 @@ tomli==2.0.1 # pytest urllib3==2.0.4 # via + # -c requirements/../../../requirements/constraints.txt # -c requirements/_aiohttp.txt # docker # requests @@ -191,4 +225,5 @@ websocket-client==1.6.1 yarl==1.9.2 # via # -c requirements/_aiohttp.txt + # -c requirements/_base.txt # aiohttp diff --git a/packages/service-library/requirements/_tools.txt b/packages/service-library/requirements/_tools.txt index 1f1c63fc0e1..b1ff5bcdaa3 100644 --- a/packages/service-library/requirements/_tools.txt +++ b/packages/service-library/requirements/_tools.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile with Python 3.10 # by the following command: # -# pip-compile --output-file=requirements/_tools.txt --resolver=backtracking --strip-extras requirements/_tools.in +# pip-compile --output-file=requirements/_tools.txt --strip-extras requirements/_tools.in # astroid==2.15.6 # via pylint @@ -63,6 +63,8 @@ pyproject-hooks==1.0.0 # via build pyyaml==6.0.1 # via + # -c requirements/../../../requirements/constraints.txt + # -c requirements/_base.txt # -c requirements/_test.txt # pre-commit ruff==0.0.278 diff --git a/requirements/constraints.txt b/requirements/constraints.txt index d0634fe40cf..09a5198948c 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -30,10 +30,6 @@ urllib3>=1.26.5 # https://github.com/advisories/GH # Breaking changes ----------------------------------------------------------------------------------------- # -# SEE https://github.com/ITISFoundation/osparc-simcore/issues/4513 -# FAILED tests/rabbitmq/test_rabbitmq_rpc.py::test_replier_responds_with_not_locally_defined_object_instance - AttributeError: Can't pickle local object 'test_replier_responds_with_not_locally_defined_object_instance.._replier_scope..Custom' -aio-pika<9.1.3 - # SEE https://github.com/ITISFoundation/osparc-simcore/issues/4481 fastapi<0.100.0 From 9e618ad045f553f28311bfd87d662a6522a9f7a5 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:01:57 +0200 Subject: [PATCH 2/6] fix test --- .../service-library/tests/rabbitmq/test_rabbitmq_rpc.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/service-library/tests/rabbitmq/test_rabbitmq_rpc.py b/packages/service-library/tests/rabbitmq/test_rabbitmq_rpc.py index f97e4304634..9c00e7ac40e 100644 --- a/packages/service-library/tests/rabbitmq/test_rabbitmq_rpc.py +++ b/packages/service-library/tests/rabbitmq/test_rabbitmq_rpc.py @@ -316,7 +316,6 @@ async def test_replier_responds_with_not_locally_defined_object_instance( rabbit_requester: RabbitMQClient, rabbit_replier: RabbitMQClient, namespace: RPCNamespace, - caplog: pytest.LogCaptureFixture, ): async def _replier_scope() -> None: class Custom: @@ -335,14 +334,13 @@ async def _requester_scope() -> None: # the replier will say that it cannot pickle a local object and send it over # the server's request will just time out. I would prefer a cleaner interface. # There is no change of intercepting this message. - with pytest.raises(asyncio.TimeoutError): + with pytest.raises( + AttributeError, match=r"Can't pickle local object .+..Custom" + ): await rabbit_requester.rpc_request( namespace, RPCMethodName("a_name"), x=10, timeout_s=1 ) - assert "Can't pickle local object" in caplog.text - assert "..Custom" in caplog.text - await _replier_scope() await _requester_scope() From b9946969b74f3799187f452c35cf64ad8bd204d4 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:02:23 +0200 Subject: [PATCH 3/6] auto ruff --- packages/service-library/tests/rabbitmq/test_rabbitmq.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/service-library/tests/rabbitmq/test_rabbitmq.py b/packages/service-library/tests/rabbitmq/test_rabbitmq.py index 748e4003e17..87a657fd77f 100644 --- a/packages/service-library/tests/rabbitmq/test_rabbitmq.py +++ b/packages/service-library/tests/rabbitmq/test_rabbitmq.py @@ -6,8 +6,9 @@ import asyncio +from collections.abc import Callable from dataclasses import dataclass -from typing import Any, Callable +from typing import Any from unittest import mock import aio_pika @@ -202,7 +203,8 @@ def _raise_once_then_true(*args, **kwargs): _raise_once_then_true.calls += 1 if _raise_once_then_true.calls == 1: - raise KeyError("this is a test!") + msg = "this is a test!" + raise KeyError(msg) if _raise_once_then_true.calls == 2: return False return True From 687cd13275f948622d5b130122b4b6a7f3d20449 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:06:23 +0200 Subject: [PATCH 4/6] ruff --- .../tests/rabbitmq/test_rabbitmq.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/service-library/tests/rabbitmq/test_rabbitmq.py b/packages/service-library/tests/rabbitmq/test_rabbitmq.py index 87a657fd77f..38cd7d2d124 100644 --- a/packages/service-library/tests/rabbitmq/test_rabbitmq.py +++ b/packages/service-library/tests/rabbitmq/test_rabbitmq.py @@ -40,15 +40,15 @@ async def test_rabbit_client( client = RabbitMQClient(rabbit_client_name, rabbit_service) assert client # check it is correctly initialized - assert client._connection_pool - assert not client._connection_pool.is_closed - assert client._channel_pool - assert not client._channel_pool.is_closed + assert client._connection_pool # noqa: SLF001 + assert not client._connection_pool.is_closed # noqa: SLF001 + assert client._channel_pool # noqa: SLF001 + assert not client._channel_pool.is_closed # noqa: SLF001 assert client.client_name == rabbit_client_name assert client.settings == rabbit_service await client.close() - assert client._connection_pool - assert client._connection_pool.is_closed + assert client._connection_pool # noqa: SLF001 + assert client._connection_pool.is_closed # noqa: SLF001 @pytest.fixture @@ -174,7 +174,7 @@ async def test_rabbit_client_pub_many_subs( await asyncio.gather( *( consumer.subscribe(exchange_name, parser) - for consumer, parser in zip(consumers, mocked_message_parsers) + for consumer, parser in zip(consumers, mocked_message_parsers, strict=True) ) ) @@ -237,7 +237,7 @@ async def test_pub_sub_with_non_exclusive_queue( await asyncio.gather( *( consumer.subscribe(exchange_name, parser, exclusive_queue=False) - for consumer, parser in zip(consumers, mocked_message_parsers) + for consumer, parser in zip(consumers, mocked_message_parsers, strict=True) ) ) From 12583e66ce064bb591464cc974dad8f79b6c82bb Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:15:04 +0200 Subject: [PATCH 5/6] remove comment --- packages/service-library/tests/rabbitmq/test_rabbitmq_rpc.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/service-library/tests/rabbitmq/test_rabbitmq_rpc.py b/packages/service-library/tests/rabbitmq/test_rabbitmq_rpc.py index 9c00e7ac40e..0f5494eb210 100644 --- a/packages/service-library/tests/rabbitmq/test_rabbitmq_rpc.py +++ b/packages/service-library/tests/rabbitmq/test_rabbitmq_rpc.py @@ -309,9 +309,6 @@ async def _raising_error() -> None: assert f"{exec_info.value}" == "failed as requested" -# WARNING: This test fails with aio-pika==9.1.4 -# FAILED tests/rabbitmq/test_rabbitmq_rpc.py::test_replier_responds_with_not_locally_defined_object_instance - AttributeError: Can't pickle local object 'test_replier_responds_with_not_locally_defined_object_instance.._replier_scope..Custom' -# async def test_replier_responds_with_not_locally_defined_object_instance( rabbit_requester: RabbitMQClient, rabbit_replier: RabbitMQClient, From 231199c9fb2b31d1057394bd13af6c6bda77966d Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:15:19 +0200 Subject: [PATCH 6/6] ruff --- packages/service-library/src/servicelib/rabbitmq.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/service-library/src/servicelib/rabbitmq.py b/packages/service-library/src/servicelib/rabbitmq.py index 01393039aea..2650cb76ebb 100644 --- a/packages/service-library/src/servicelib/rabbitmq.py +++ b/packages/service-library/src/servicelib/rabbitmq.py @@ -1,7 +1,8 @@ import asyncio import logging +from collections.abc import Awaitable, Callable from dataclasses import dataclass, field -from typing import Any, Awaitable, Callable, Final, Protocol +from typing import Any, Final, Protocol import aio_pika import aiormq @@ -313,7 +314,7 @@ async def rpc_request( method_name: RPCMethodName, *, timeout_s: PositiveInt | None = 5, - **kwargs: dict[str, Any], + **kwargs, ) -> Any: """ Call a remote registered `handler` by providing it's `namespace`, `method_name` @@ -327,7 +328,7 @@ async def rpc_request( """ if not self._rpc: - raise RPCNotInitializedError() + raise RPCNotInitializedError namespaced_method_name = RPCNamespacedMethodName.from_namespace_and_method( namespace, method_name @@ -362,7 +363,7 @@ async def rpc_register_handler( """ if self._rpc is None: - raise RPCNotInitializedError() + raise RPCNotInitializedError await self._rpc.register( RPCNamespacedMethodName.from_namespace_and_method(namespace, method_name), @@ -374,6 +375,6 @@ async def rpc_unregister_handler(self, handler: Callable[..., Any]) -> None: """Unbind a locally added `handler`""" if self._rpc is None: - raise RPCNotInitializedError() + raise RPCNotInitializedError await self._rpc.unregister(handler)