Skip to content

Commit

Permalink
repo: Update dev tools and reformat with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Feb 1, 2024
1 parent d099910 commit 85cc8fe
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 69 deletions.
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ select = [
# "B", # flake8-bugbear
]
ignore = ["E203","E731","E501"]
preview = true

[tool.ruff.isort]
known-first-party = ["aiotools"]
Expand Down
7 changes: 3 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions src/aiotools/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 8 additions & 10 deletions src/aiotools/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 8 additions & 10 deletions src/aiotools/taskgroup/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 14 additions & 16 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
26 changes: 11 additions & 15 deletions tests/test_utils_as_completed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 85cc8fe

Please sign in to comment.