diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cfa43e6..c0f8f51 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,17 +7,14 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace -- repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.9.0 - hooks: - - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.287 + rev: v0.2.2 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 + rev: v1.8.0 hooks: - id: mypy additional_dependencies: [ diff --git a/changes/26.misc.md b/changes/26.misc.md new file mode 100644 index 0000000..ad1c228 --- /dev/null +++ b/changes/26.misc.md @@ -0,0 +1 @@ +Update dependencies including pyzmq ('>=23' → '>=25.1.1' to support Python 3.12) and development tools including ruff to replace the black formatter diff --git a/examples/simple-consumer-redis.py b/examples/simple-consumer-redis.py index 66b35cf..cfe6a7a 100644 --- a/examples/simple-consumer-redis.py +++ b/examples/simple-consumer-redis.py @@ -5,6 +5,7 @@ whether each consumer gets only the messages which have not been obtained by others so far. """ + import asyncio import json import logging diff --git a/examples/simple-publisher-redis.py b/examples/simple-publisher-redis.py index a933ea8..951db19 100644 --- a/examples/simple-publisher-redis.py +++ b/examples/simple-publisher-redis.py @@ -3,6 +3,7 @@ simultaneously, so as to check whether messages from multiple publishers are distributed among the consumers. """ + import asyncio import json import logging diff --git a/examples/simple-server.py b/examples/simple-server.py index c31cf2c..c4da2c2 100644 --- a/examples/simple-server.py +++ b/examples/simple-server.py @@ -50,18 +50,14 @@ async def handle_output(request): async def handle_show_memory_stat(request): global last_snapshot, scheduler - last_snapshot = last_snapshot.filter_traces( - ( - tracemalloc.Filter(False, ""), - tracemalloc.Filter(False, tracemalloc.__file__), - ) - ) - new_snapshot = tracemalloc.take_snapshot().filter_traces( - ( - tracemalloc.Filter(False, ""), - tracemalloc.Filter(False, tracemalloc.__file__), - ) - ) + last_snapshot = last_snapshot.filter_traces(( + tracemalloc.Filter(False, ""), + tracemalloc.Filter(False, tracemalloc.__file__), + )) + new_snapshot = tracemalloc.take_snapshot().filter_traces(( + tracemalloc.Filter(False, ""), + tracemalloc.Filter(False, tracemalloc.__file__), + )) top_stats = new_snapshot.compare_to(last_snapshot, "lineno") last_snapshot = new_snapshot print("[ Top 10 differences ]") diff --git a/pyproject.toml b/pyproject.toml index 557c931..a04852b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,10 @@ underlines = ["", "", ""] [tool.ruff] line-length = 85 src = ["src"] +preview = true +target-version = "py311" + +[tool.ruff.lint] select = [ "E", # pycodestyle errors "W", # pycodestyle warnings @@ -58,14 +62,11 @@ select = [ ] ignore = ["E203","E731","E501"] -[tool.ruff.isort] +[tool.ruff.lint.isort] known-first-party = ["callosum"] known-local-folder = ["src"] split-on-trailing-comma = true -[tool.black] -line-length = 85 - [tool.mypy] ignore_missing_imports = true diff --git a/setup.cfg b/setup.cfg index 7a973ba..2e8af01 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,9 +40,9 @@ python_requires = >=3.11 install_requires = attrs>=21.3.0 python-dateutil>=2.8.2 - msgpack>=1.0.4 + msgpack>=1.0.7 temporenc>=0.1 - yarl>=1.8.2 + yarl>=1.9.4 zip_safe = false include_package_data = true @@ -65,19 +65,18 @@ test = dev = pre-commit lint = - black~=23.9.1 - ruff>=0.0.287 - ruff-lsp>=0.0.38 + ruff>=0.2.2 + ruff-lsp>=0.0.52 typecheck = - mypy~=1.5.1 + mypy~=1.8.0 types-python-dateutil docs = sphinx~=4.3 sphinx-autodoc-typehints thrift = - thriftpy2>=0.4.16 + thriftpy2>=0.4.20 zeromq = - pyzmq>=23.0.0 + pyzmq>=25.1.1 redis = redis>=4.6.0 snappy = diff --git a/src/callosum/lower/dispatch_redis.py b/src/callosum/lower/dispatch_redis.py index 71212ae..e19ad12 100644 --- a/src/callosum/lower/dispatch_redis.py +++ b/src/callosum/lower/dispatch_redis.py @@ -186,7 +186,6 @@ async def __aexit__(self, exc_type, exc_obj, exc_tb): class DispatchRedisTransport(BaseTransport): - """ Implementation for unidirectional transport backend by Redis Streams. """ diff --git a/src/callosum/lower/rpc_redis.py b/src/callosum/lower/rpc_redis.py index 8824c81..4c3a3f5 100644 --- a/src/callosum/lower/rpc_redis.py +++ b/src/callosum/lower/rpc_redis.py @@ -206,7 +206,6 @@ async def __aexit__(self, exc_type, exc_obj, exc_tb): class RPCRedisTransport(BaseTransport): - """ Implementation for bidirectional transport backend by Redis Streams. """ diff --git a/src/callosum/lower/zeromq.py b/src/callosum/lower/zeromq.py index a47f749..5d2a093 100644 --- a/src/callosum/lower/zeromq.py +++ b/src/callosum/lower/zeromq.py @@ -227,14 +227,12 @@ async def recv_message(self) -> AsyncGenerator[Optional[RawHeaderBody], None]: multipart_msg = await self.transport._sock.recv_multipart() *pre, zmsg_type, raw_header, raw_body = multipart_msg if zmsg_type == b"PING": - await self.transport._sock.send_multipart( - [ - *pre, - b"PONG", - raw_header, - raw_body, - ] - ) + await self.transport._sock.send_multipart([ + *pre, + b"PONG", + raw_header, + raw_body, + ]) elif zmsg_type == b"UPPER": if len(pre) > 0: # server @@ -250,23 +248,19 @@ async def send_message(self, raw_msg: RawHeaderBody) -> None: peer_id = raw_msg.peer_id if peer_id is not None: # server - await self.transport._sock.send_multipart( - [ - peer_id, - b"UPPER", - raw_msg.header, - raw_msg.body, - ] - ) + await self.transport._sock.send_multipart([ + peer_id, + b"UPPER", + raw_msg.header, + raw_msg.body, + ]) else: # client - await self.transport._sock.send_multipart( - [ - b"UPPER", - raw_msg.header, - raw_msg.body, - ] - ) + await self.transport._sock.send_multipart([ + b"UPPER", + raw_msg.header, + raw_msg.body, + ]) class ZeroMQMonitorMixin: @@ -469,7 +463,6 @@ class ZeroMQSubConnector(ZeroMQBaseConnector): class ZeroMQBaseTransport(BaseTransport): - """ Implementation for the ZeorMQ-backed transport. diff --git a/src/callosum/ordering.py b/src/callosum/ordering.py index 9415595..93d02d3 100644 --- a/src/callosum/ordering.py +++ b/src/callosum/ordering.py @@ -170,7 +170,6 @@ def cleanup(self, request_id) -> None: self._tasks.pop(request_id, None) async def cancel(self, request_id) -> None: - method, okey, seq = request_id if request_id in self._futures: task = self._tasks.get(request_id, None) if task is None: diff --git a/src/callosum/rpc/channel.py b/src/callosum/rpc/channel.py index 6d33dc6..e5b250b 100644 --- a/src/callosum/rpc/channel.py +++ b/src/callosum/rpc/channel.py @@ -167,9 +167,9 @@ async def _recv_loop(self) -> None: client_request_id[1], server_seq_id, ) - self._req_idmap[ - (request.peer_id, client_request_id) - ] = server_request_id + self._req_idmap[(request.peer_id, client_request_id)] = ( + server_request_id + ) func_handler = self._lookup_func(request.method) task = asyncio.create_task( self._func_task( diff --git a/tests/test_rpc.py b/tests/test_rpc.py index 3c5fa33..7e60012 100644 --- a/tests/test_rpc.py +++ b/tests/test_rpc.py @@ -93,7 +93,7 @@ async def dummy_client( async def test_messaging(scheduler_cls) -> None: done = asyncio.Event() total = 50 - call_results: List[int] = [] + call_results: List[int | BaseException] = [] return_results: List[int] = [] # a list of events to make fucntions to return in the reversed order order_events = [asyncio.Event() for _ in range(total)] @@ -159,7 +159,7 @@ async def test_messaging_server_cancellation(scheduler_cls) -> None: total = 200 cancel_idxs = [False] * 130 + [True] * 70 random.shuffle(cancel_idxs) - call_results: List[int] = [] + call_results: List[int | BaseException] = [] return_results: List[int] = [] # a list of events to make fucntions to return in the reversed order order_events = [asyncio.Event() for _ in range(total)] @@ -232,7 +232,7 @@ async def test_messaging_server_error(scheduler_cls) -> None: total = 200 error_idxs = [False] * 130 + [True] * 70 random.shuffle(error_idxs) - call_results: List[int] = [] + call_results: List[int | BaseException] = [] return_results: List[int] = [] # a list of events to make fucntions to return in the reversed order order_events = [asyncio.Event() for _ in range(total)]