Skip to content

Commit 461257d

Browse files
authored
Add Ruff to cluster_tools (#1023)
* added ruff to cluster_tools * auto-format * manually fixed linting errors * removed pylint coments * update changelog * fix typechecking * fixed linting
1 parent b246338 commit 461257d

24 files changed

+201
-412
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/webknossos.svg)](https://pypi.python.org/pypi/webknossos)
44
[![Build Status](https://img.shields.io/github/actions/workflow/status/scalableminds/webknossos-libs/.github/workflows/ci.yml?branch=master)](https://github.com/scalableminds/webknossos-libs/actions?query=workflow%3A%22CI%22)
55
[![Documentation](https://img.shields.io/badge/docs-passing-brightgreen.svg)](https://docs.webknossos.org/webknossos-py/index.html)
6-
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
6+
[![Code Style](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://docs.astral.sh/ruff/)
77

88
<img align="right" src="https://static.webknossos.org/logos/webknossos-icon-only.svg" alt="WEBKNOSSOS Logo" width="100" height="100"/>
99

cluster_tools/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ For upgrade instructions, please check the respective *Breaking Changes* section
1414
### Added
1515

1616
### Changed
17+
- Replaced black+isort formatters and pylint linter with ruff. [#1023](https://github.com/scalableminds/webknossos-libs/pull/1023)
1718

1819
### Fixed
1920

cluster_tools/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Cluster Tools
22

33
[![Build Status](https://img.shields.io/github/actions/workflow/status/scalableminds/webknossos-libs/.github/workflows/ci.yml?branch=master)](https://github.com/scalableminds/webknossos-libs/actions?query=workflow%3A%22CI%22)
4+
[![Code Style](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://docs.astral.sh/ruff/)
5+
46

57
This package provides python `Executor` classes for distributing tasks on a slurm cluster or via multi processing.
68

cluster_tools/cluster_tools/__init__.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
from cluster_tools.executors.pickle_ import PickleExecutor
88
from cluster_tools.executors.sequential import SequentialExecutor
99
from cluster_tools.schedulers.cluster_executor import (
10-
ClusterExecutor,
11-
RemoteOutOfMemoryException,
12-
RemoteResourceLimitException,
13-
RemoteTimeLimitException,
10+
ClusterExecutor, # noqa: F401 `cluster_tools.schedulers.cluster_executor.ClusterExecutor` imported but unused;
11+
RemoteOutOfMemoryException, # noqa: F401 `cluster_tools.schedulers.cluster_executor.ClusterExecutor` imported but unused;
12+
RemoteResourceLimitException, # noqa: F401 `cluster_tools.schedulers.cluster_executor.ClusterExecutor` imported but unused;
13+
RemoteTimeLimitException, # noqa: F401 `cluster_tools.schedulers.cluster_executor.ClusterExecutor` imported but unused;
1414
)
1515
from cluster_tools.schedulers.kube import KubernetesExecutor
1616
from cluster_tools.schedulers.pbs import PBSExecutor
@@ -54,53 +54,45 @@ def _test_valid_multiprocessing() -> None:
5454

5555

5656
@overload
57-
def get_executor(environment: Literal["slurm"], **kwargs: Any) -> SlurmExecutor:
58-
...
57+
def get_executor(environment: Literal["slurm"], **kwargs: Any) -> SlurmExecutor: ...
5958

6059

6160
@overload
62-
def get_executor(environment: Literal["pbs"], **kwargs: Any) -> PBSExecutor:
63-
...
61+
def get_executor(environment: Literal["pbs"], **kwargs: Any) -> PBSExecutor: ...
6462

6563

6664
@overload
6765
def get_executor(
6866
environment: Literal["kubernetes"], **kwargs: Any
69-
) -> KubernetesExecutor:
70-
...
67+
) -> KubernetesExecutor: ...
7168

7269

7370
@overload
74-
def get_executor(environment: Literal["dask"], **kwargs: Any) -> DaskExecutor:
75-
...
71+
def get_executor(environment: Literal["dask"], **kwargs: Any) -> DaskExecutor: ...
7672

7773

7874
@overload
7975
def get_executor(
8076
environment: Literal["multiprocessing"], **kwargs: Any
81-
) -> MultiprocessingExecutor:
82-
...
77+
) -> MultiprocessingExecutor: ...
8378

8479

8580
@overload
8681
def get_executor(
8782
environment: Literal["sequential"], **kwargs: Any
88-
) -> SequentialExecutor:
89-
...
83+
) -> SequentialExecutor: ...
9084

9185

9286
@overload
9387
def get_executor(
9488
environment: Literal["debug_sequential"], **kwargs: Any
95-
) -> DebugSequentialExecutor:
96-
...
89+
) -> DebugSequentialExecutor: ...
9790

9891

9992
@overload
10093
def get_executor(
10194
environment: Literal["test_pickling"], **kwargs: Any
102-
) -> PickleExecutor:
103-
...
95+
) -> PickleExecutor: ...
10496

10597

10698
def get_executor(environment: str, **kwargs: Any) -> "Executor":

cluster_tools/cluster_tools/_utils/call.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ def call(command: str, stdin: Optional[str] = None) -> Tuple[str, str, int]:
2525
class CommandError(Exception):
2626
"""Raised when a shell command exits abnormally."""
2727

28-
def __init__(
29-
self, command: str, code: int, stderr: str
30-
): # pylint: disable=super-init-not-called
28+
def __init__(self, command: str, code: int, stderr: str):
3129
self.command = command
3230
self.code = code
3331
self.stderr = stderr

cluster_tools/cluster_tools/_utils/multiprocessing_logging_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def _receive(self) -> None:
5252
record = self.queue.get(timeout=0.2)
5353
if record is not None:
5454
self.wrapped_handler.emit(record)
55-
except (KeyboardInterrupt, SystemExit): # pylint: disable=try-except-raise
55+
except (KeyboardInterrupt, SystemExit):
5656
raise
5757
# The following errors pop up quite often.
5858
# It seems that they can be safely ignored, though.

cluster_tools/cluster_tools/_utils/pickling.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,5 @@ def find_class(self, module: str, name: str) -> Any:
4646
@warn_after("pickle.load", WARNING_TIMEOUT)
4747
def load(f: BinaryIO, custom_main_path: Optional[str] = None) -> Any:
4848
unpickler = _RenameUnpickler(f)
49-
unpickler.custom_main_path = ( # pylint: disable=attribute-defined-outside-init
50-
custom_main_path
51-
)
49+
unpickler.custom_main_path = custom_main_path
5250
return unpickler.load()

cluster_tools/cluster_tools/executor_protocol.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,35 @@
2020

2121
class Executor(Protocol, ContextManager["Executor"]):
2222
@classmethod
23-
def as_completed(cls, futures: List["Future[_T]"]) -> Iterator["Future[_T]"]:
24-
...
23+
def as_completed(cls, futures: List["Future[_T]"]) -> Iterator["Future[_T]"]: ...
2524

2625
def submit(
2726
self,
2827
__fn: Callable[_P, _T],
2928
/,
3029
*args: _P.args,
3130
**kwargs: _P.kwargs,
32-
) -> "Future[_T]":
33-
...
31+
) -> "Future[_T]": ...
3432

35-
def map_unordered(self, fn: Callable[[_S], _T], args: Iterable[_S]) -> Iterator[_T]:
36-
...
33+
def map_unordered(
34+
self, fn: Callable[[_S], _T], args: Iterable[_S]
35+
) -> Iterator[_T]: ...
3736

3837
def map_to_futures(
3938
self,
4039
fn: Callable[[_S], _T],
4140
args: Iterable[_S],
4241
output_pickle_path_getter: Optional[Callable[[_S], PathLike]] = None,
43-
) -> List["Future[_T]"]:
44-
...
42+
) -> List["Future[_T]"]: ...
4543

4644
def map(
4745
self,
4846
fn: Callable[[_S], _T],
4947
iterables: Iterable[_S],
5048
timeout: Optional[float] = None,
5149
chunksize: Optional[int] = None,
52-
) -> Iterator[_T]:
53-
...
50+
) -> Iterator[_T]: ...
5451

55-
def forward_log(self, fut: "Future[_T]") -> _T:
56-
...
52+
def forward_log(self, fut: "Future[_T]") -> _T: ...
5753

58-
def shutdown(self, wait: bool = True, *, cancel_futures: bool = False) -> None:
59-
...
54+
def shutdown(self, wait: bool = True, *, cancel_futures: bool = False) -> None: ...

cluster_tools/cluster_tools/executors/dask.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ def result_generator() -> Iterator:
239239
def map_to_futures(
240240
self,
241241
fn: Callable[[_S], _T],
242-
args: Iterable[_S], # TODO change: allow more than one arg per call
242+
args: Iterable[
243+
_S
244+
], # TODO change: allow more than one arg per call # noqa FIX002 Line contains TODO
243245
output_pickle_path_getter: Optional[Callable[[_S], os.PathLike]] = None,
244246
) -> List["Future[_T]"]:
245247
if output_pickle_path_getter is not None:
@@ -286,13 +288,12 @@ def handle_kill(
286288
self.client.cancel(list(self.pending_futures))
287289

288290
if (
289-
existing_sigint_handler # pylint: disable=comparison-with-callable
290-
!= signal.default_int_handler
291+
existing_sigint_handler != signal.default_int_handler
291292
and callable(existing_sigint_handler) # Could also be signal.SIG_IGN
292293
):
293294
existing_sigint_handler(signum, frame)
294295

295-
def shutdown(self, wait: bool = True, *, cancel_futures: bool = False) -> None:
296+
def shutdown(self, wait: bool = True, *, cancel_futures: bool = False) -> None: # noqa: ARG002 Unused method argument: `cancel_futures`
296297
if wait:
297298
for fut in list(self.pending_futures):
298299
fut.result()

cluster_tools/cluster_tools/executors/multiprocessing_.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ def result_generator() -> Iterator:
246246
def map_to_futures(
247247
self,
248248
fn: Callable[[_S], _T],
249-
args: Iterable[_S], # TODO change: allow more than one arg per call
249+
args: Iterable[
250+
_S
251+
], # TODO change: allow more than one arg per call #noqa: FIX002 Line contains TODO
250252
output_pickle_path_getter: Optional[Callable[[_S], os.PathLike]] = None,
251253
) -> List["Future[_T]"]:
252254
if output_pickle_path_getter is not None:

0 commit comments

Comments
 (0)