From 85cc8fea0bb83a69f2a93a88cbd6256558c83731 Mon Sep 17 00:00:00 2001 From: Joongi Kim Date: Thu, 1 Feb 2024 16:21:18 +0900 Subject: [PATCH] repo: Update dev tools and reformat with ruff --- .pre-commit-config.yaml | 11 ++++------ pyproject.toml | 1 + setup.cfg | 7 +++---- src/aiotools/server.py | 12 +++++------ src/aiotools/supervisor.py | 18 ++++++++--------- src/aiotools/taskgroup/persistent.py | 18 ++++++++--------- tests/test_server.py | 30 +++++++++++++--------------- tests/test_utils_as_completed.py | 26 ++++++++++-------------- 8 files changed, 54 insertions(+), 69 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b0f097..cde1efb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,21 +2,18 @@ ci: autoupdate_schedule: quarterly repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace -- repo: https://github.com/psf/black - rev: 23.9.1 - hooks: - - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.291 + rev: v0.1.15 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 diff --git a/pyproject.toml b/pyproject.toml index 82c556a..61d0e6d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,6 +59,7 @@ select = [ # "B", # flake8-bugbear ] ignore = ["E203","E731","E501"] +preview = true [tool.ruff.isort] known-first-party = ["aiotools"] diff --git a/setup.cfg b/setup.cfg index 7fcb211..dc44ac2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,11 +50,10 @@ test = dev = pre-commit lint = - black~=23.3.0 - ruff>=0.0.285 - ruff-lsp>=0.0.37 + ruff>=0.1.15 + ruff-lsp>=0.0.50 typecheck = - mypy~=1.5.1 + mypy~=1.8.0 docs = sphinx~=4.3 sphinx-rtd-theme~=1.0 diff --git a/src/aiotools/server.py b/src/aiotools/server.py index a570809..15a297d 100644 --- a/src/aiotools/server.py +++ b/src/aiotools/server.py @@ -256,13 +256,11 @@ async def cancel_all_tasks() -> None: if task.cancelled(): continue if task.exception() is not None: - loop.call_exception_handler( - { - "message": "unhandled exception during loop shutdown", - "exception": task.exception(), - "task": task, - } - ) + loop.call_exception_handler({ + "message": "unhandled exception during loop shutdown", + "exception": task.exception(), + "task": task, + }) def _worker_main( diff --git a/src/aiotools/supervisor.py b/src/aiotools/supervisor.py index 7eb253d..789073a 100644 --- a/src/aiotools/supervisor.py +++ b/src/aiotools/supervisor.py @@ -190,16 +190,14 @@ def _on_task_done(self, task): if self._parent_task.done(): # Not sure if this case is possible, but we want to handle # it anyways. - self._loop.call_exception_handler( - { - "message": ( - f"Task {task!r} has errored out but its parent " - f"task {self._parent_task} is already completed" - ), - "exception": exc, - "task": task, - } - ) + self._loop.call_exception_handler({ + "message": ( + f"Task {task!r} has errored out but its parent " + f"task {self._parent_task} is already completed" + ), + "exception": exc, + "task": task, + }) return if _is_base_error and not self._aborting and not self._parent_cancel_requested: diff --git a/src/aiotools/taskgroup/persistent.py b/src/aiotools/taskgroup/persistent.py index f3db661..2cbc903 100644 --- a/src/aiotools/taskgroup/persistent.py +++ b/src/aiotools/taskgroup/persistent.py @@ -165,16 +165,14 @@ async def _task_wrapper( # we report it as soon as possible using the event loop's # exception handler, instead of postponing # to the timing when PersistentTaskGroup terminates. - loop.call_exception_handler( - { - "message": ( - "Got an unhandled exception " - f"in the exception handler of Task {task!r}" - ), - "exception": exc, - "task": task, - } - ) + loop.call_exception_handler({ + "message": ( + "Got an unhandled exception " + f"in the exception handler of Task {task!r}" + ), + "exception": exc, + "task": task, + }) finally: del fut diff --git a/tests/test_server.py b/tests/test_server.py index 20801ea..01a364e 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -172,24 +172,22 @@ def write(self, msg): self.writer(f"log:{proc_idx}:{msg}") log_stream = _LogAdaptor(write) - logging.config.dictConfig( - { - "version": 1, - "handlers": { - "console": { - "class": "logging.StreamHandler", - "stream": log_stream, - "level": "DEBUG", - }, + logging.config.dictConfig({ + "version": 1, + "handlers": { + "console": { + "class": "logging.StreamHandler", + "stream": log_stream, + "level": "DEBUG", }, - "loggers": { - "aiotools": { - "handlers": ["console"], - "level": "DEBUG", - }, + }, + "loggers": { + "aiotools": { + "handlers": ["console"], + "level": "DEBUG", }, - } - ) + }, + }) log = logging.getLogger("aiotools") write(f"started:{proc_idx}") log.debug("hello") diff --git a/tests/test_utils_as_completed.py b/tests/test_utils_as_completed.py index 66412ac..802d278 100644 --- a/tests/test_utils_as_completed.py +++ b/tests/test_utils_as_completed.py @@ -37,13 +37,11 @@ async def test_as_completed_safe() -> None: results = [] with VirtualClock().patch_loop(): async with aclosing( - as_completed_safe( - [ - do_job(0.3, 1), - do_job(0.2, 2), - do_job(0.1, 3), - ] - ) + as_completed_safe([ + do_job(0.3, 1), + do_job(0.2, 2), + do_job(0.1, 3), + ]) ) as ag: async for result in ag: results.append(await result) @@ -56,14 +54,12 @@ async def test_as_completed_safe_partial_failure() -> None: errors = [] with VirtualClock().patch_loop(): async with aclosing( - as_completed_safe( - [ - do_job(0.1, 1), - fail_job(0.2), - do_job(0.3, 3), - fail_job(0.4), - ] - ) + as_completed_safe([ + do_job(0.1, 1), + fail_job(0.2), + do_job(0.3, 3), + fail_job(0.4), + ]) ) as ag: async for result in ag: try: