Skip to content

Commit

Permalink
Add some more linters
Browse files Browse the repository at this point in the history
  • Loading branch information
mthrok committed Sep 2, 2024
1 parent 956748d commit b7d1908
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/image_dataloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def entrypoint(args: list[str] | None = None):
ns, args = _parse_process_args(args)

args_set = [
args + [f"--worker-id={i}", f"--num-workers={ns.num_workers}"]
[*args, f"--worker-id={i}", f"--num-workers={ns.num_workers}"]
for i in range(ns.num_workers)
]

Expand Down
2 changes: 1 addition & 1 deletion examples/video_dataloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def entrypoint(args: list[str] | None = None):
ns, args = _parse_process_args(args)

args_set = [
args + [f"--worker-id={i}", f"--num-workers={ns.num_workers}"]
[*args, f"--worker-id={i}", f"--num-workers={ns.num_workers}"]
for i in range(ns.num_workers)
]

Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ extend-exclude = [
"third_party",
"setup.py",
]

[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"PGH", # pygrep-hooks
"RUF", # Ruff-specific
]
4 changes: 2 additions & 2 deletions src/spdl/dataloader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from typing import Any

from . import _builder, _flist, _hook, _pipeline, _utils # noqa: E402
from . import _builder, _flist, _hook, _pipeline, _utils

_mods = [
_builder,
Expand All @@ -27,7 +27,7 @@ def __dir__():


def __getattr__(name: str) -> Any:
for mod in _mods + [_flist]:
for mod in [*_mods, _flist]:
if name in mod.__all__:
return getattr(mod, name)

Expand Down
2 changes: 1 addition & 1 deletion src/spdl/dataloader/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def _get_desc(self) -> list[str]:
return parts

def __str__(self) -> str:
return "\n".join([repr(self)] + self._get_desc())
return "\n".join([repr(self), *self._get_desc()])

def build(self, *, num_threads: int | None = None) -> Pipeline:
"""Build the pipeline.
Expand Down
7 changes: 4 additions & 3 deletions src/spdl/dataloader/_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def __init__(
):
self._queues = queues

self._str = "\n".join([repr(self)] + desc)
self._str = "\n".join([repr(self), *desc])

self._output_queue = queues[-1]
self._event_loop = _EventLoop(coro, num_threads)
Expand All @@ -281,14 +281,15 @@ def __del__(self) -> None:
"""Stop the pipeline if running."""
if _EventLoopState.STARTED <= self._event_loop_state < _EventLoopState.STOPPED:
warnings.warn(
f"Pipeline ({repr(self)}) is running in the background, but "
f"Pipeline ({self!r}) is running in the background, but "
"there is no valid reference pointing the foreground object. "
"Stopping the background thread. "
"It is strongly advised to stop the pipeline explicity, "
"using the `auto_stop` context manager. "
"If you are using a framework and you cannot use the "
"context manager, try calling `stop` in done callback and "
"error callback."
"error callback.",
stacklevel=1,
)
self.stop()

Expand Down
6 changes: 2 additions & 4 deletions src/spdl/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
# (black, flake8 and pyre) and documentation tools, this seems like
# the simplest solution.
# This import is just for annotation, so please overlook this one.
from ._type_stub import * # noqa
from ._type_stub import * # noqa: F403

from . import ( # noqa: E402
from . import (
_composite,
_config,
_convert,
_core,
_preprocessing,
_type_stub,
)


Expand All @@ -37,7 +36,6 @@
_convert,
_core,
_preprocessing,
_type_stub,
]


Expand Down
2 changes: 1 addition & 1 deletion tests/spdl_unittest/cuda/nvdec_async_decoding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_batch_decode_image(get_samples):
cmd = "ffmpeg -hide_banner -y -f lavfi -i testsrc -frames:v 10 sample_%03d.jpg"
samples = get_samples(cmd)

flist = ["NON_EXISTING_FILE.JPG"] + samples
flist = ["NON_EXISTING_FILE.JPG", *samples]

async def _test():
buffer = await spdl.io.async_load_image_batch_nvdec(
Expand Down
8 changes: 4 additions & 4 deletions tests/spdl_unittest/dataloader/pipeline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_async_enqueue_simple():
coro = _enqueue(src, queue)
asyncio.run(coro)
vals = _flush_aqueue(queue)
assert vals == src + [_EOF]
assert vals == [*src, _EOF]


def test_async_enqueue_skip():
Expand All @@ -72,7 +72,7 @@ def src():
coro = _enqueue(src(), queue)
asyncio.run(coro)
vals = _flush_aqueue(queue)
assert vals == list(range(6)) + [_EOF]
assert vals == [*list(range(6)), _EOF]


def test_async_enqueue_iterator_failure():
Expand Down Expand Up @@ -650,15 +650,15 @@ def test_task_stats():

async def _test():
async with hook.stage_hook():
for i in range(3):
for _ in range(3):
async with hook.task_hook():
await asyncio.sleep(0.5)

assert hook.num_tasks == 3
assert hook.num_success == 3
assert 0.3 < hook.ave_time < 0.7

for i in range(2):
for _ in range(2):
with pytest.raises(RuntimeError):
async with hook.task_hook():
await asyncio.sleep(1.0)
Expand Down
2 changes: 1 addition & 1 deletion tests/spdl_unittest/io/async_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def test_batch_decode_image(get_samples):
cmd = "ffmpeg -hide_banner -y -f lavfi -i testsrc -frames:v 250 sample_%03d.jpg"
samples = get_samples(cmd)

flist = ["NON_EXISTING_FILE.JPG"] + samples
flist = ["NON_EXISTING_FILE.JPG", *samples]

async def _test():
buffer = await spdl.io.async_load_image_batch(
Expand Down

0 comments on commit b7d1908

Please sign in to comment.