Skip to content

Commit 2d4ba04

Browse files
Add ruff and refurb. (#51)
1 parent c91d008 commit 2d4ba04

10 files changed

+80
-134
lines changed

.pre-commit-config.yaml

+9-26
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ repos:
1717
- id: python-no-log-warn
1818
- id: python-use-type-annotations
1919
- id: text-unicode-replacement-char
20-
- repo: https://github.com./asottile/pyupgrade
21-
rev: v3.3.1
22-
hooks:
23-
- id: pyupgrade
24-
args: [--py37-plus]
2520
- repo: https://github.com./asottile/reorder_python_imports
2621
rev: v3.9.0
2722
hooks:
@@ -32,35 +27,23 @@ repos:
3227
hooks:
3328
- id: setup-cfg-fmt
3429
- repo: https://github.com./PYCQA/docformatter
35-
rev: v1.5.0
30+
rev: v1.5.1
3631
hooks:
3732
- id: docformatter
3833
args: [--in-place, --wrap-summaries, "88", --wrap-descriptions, "88", --blank]
3934
- repo: https://github.com./psf/black
4035
rev: 22.12.0
4136
hooks:
4237
- id: black
43-
- repo: https://github.com./PyCQA/flake8
44-
rev: 5.0.4
38+
- repo: https://github.com./charliermarsh/ruff-pre-commit
39+
rev: v0.0.215
4540
hooks:
46-
- id: flake8
47-
types: [python]
48-
additional_dependencies: [
49-
flake8-alfred,
50-
flake8-bugbear,
51-
flake8-builtins,
52-
flake8-comprehensions,
53-
flake8-docstrings,
54-
flake8-eradicate,
55-
flake8-print,
56-
flake8-pytest-style,
57-
flake8-todo,
58-
flake8-typing-imports,
59-
flake8-unused-arguments,
60-
pep8-naming,
61-
pydocstyle,
62-
Pygments,
63-
]
41+
- id: ruff
42+
- repo: https://github.com./dosisod/refurb
43+
rev: v1.9.1
44+
hooks:
45+
- id: refurb
46+
args: [--ignore, FURB126]
6447
- repo: https://github.com./econchick/interrogate
6548
rev: 1.5.0
6649
hooks:

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask-parallel) and
88
## 0.3.0 - 2023-xx-xx
99

1010
- {pull}`50` deprecates INI configurations and aligns the package with pytask v0.3.
11+
- {pull}`51` adds ruff and refurb.
1112

1213
## 0.2.1 - 2022-08-19
1314

pyproject.toml

+38
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,41 @@ warn_unused_ignores = true
2222
module = "tests.*"
2323
disallow_untyped_defs = false
2424
ignore_errors = true
25+
26+
27+
[tool.ruff]
28+
target-version = "py37"
29+
select = ["ALL"]
30+
fix = true
31+
extend-ignore = [
32+
# Numpy docstyle
33+
"D107",
34+
"D203",
35+
"D212",
36+
"D213",
37+
"D402",
38+
"D413",
39+
"D415",
40+
"D416",
41+
"D417",
42+
# Others.
43+
"D404", # Do not start module docstring with "This".
44+
"RET504", # unnecessary variable assignment before return.
45+
"S101", # raise errors for asserts.
46+
"B905", # strict parameter for zip that was implemented in py310.
47+
"I", # ignore isort
48+
"ANN101", # type annotating self
49+
"ANN102", # type annotating cls
50+
"FBT", # flake8-boolean-trap
51+
"EM", # flake8-errmsg
52+
"ANN401", # flake8-annotate typing.Any
53+
"PD", # pandas-vet
54+
]
55+
56+
57+
[tool.ruff.per-file-ignores]
58+
"tests/*" = ["D", "ANN"]
59+
60+
61+
[tool.ruff.pydocstyle]
62+
convention = "numpy"

src/pytask_parallel/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""This module is the main namespace of the package."""
12
from __future__ import annotations
23

34
try:

src/pytask_parallel/backends.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
"""This module configures the available backends."""
22
from __future__ import annotations
33

4+
import enum
45
from concurrent.futures import ProcessPoolExecutor
56
from concurrent.futures import ThreadPoolExecutor
6-
from enum import Enum
77

88

99
try:
1010
from loky import get_reusable_executor
1111

1212
except ImportError:
1313

14-
class ParallelBackendChoices(str, Enum):
14+
class ParallelBackendChoices(enum.Enum):
15+
"""Choices for parallel backends."""
16+
1517
PROCESSES = "processes"
1618
THREADS = "threads"
1719

@@ -24,7 +26,9 @@ class ParallelBackendChoices(str, Enum):
2426

2527
else:
2628

27-
class ParallelBackendChoices(str, Enum): # type: ignore[no-redef]
29+
class ParallelBackendChoices(enum.Enum): # type: ignore[no-redef]
30+
"""Choices for parallel backends."""
31+
2832
PROCESSES = "processes"
2933
THREADS = "threads"
3034
LOKY = "loky"

src/pytask_parallel/callbacks.py

-35
This file was deleted.

src/pytask_parallel/execute.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ def pytask_execute_build(session: Session) -> bool | None:
6969
newly_collected_reports = []
7070
n_new_tasks = session.config["n_workers"] - len(running_tasks)
7171

72-
if n_new_tasks >= 1:
73-
ready_tasks = list(session.scheduler.get_ready(n_new_tasks))
74-
else:
75-
ready_tasks = []
72+
ready_tasks = (
73+
list(session.scheduler.get_ready(n_new_tasks))
74+
if n_new_tasks >= 1
75+
else []
76+
)
7677

7778
for task_name in ready_tasks:
7879
task = session.dag.nodes[task_name]["task"]
@@ -83,7 +84,7 @@ def pytask_execute_build(session: Session) -> bool | None:
8384
session.hook.pytask_execute_task_setup(
8485
session=session, task=task
8586
)
86-
except Exception:
87+
except Exception: # noqa: BLE001
8788
report = ExecutionReport.from_task_and_exception(
8889
task, sys.exc_info()
8990
)
@@ -122,7 +123,7 @@ def pytask_execute_build(session: Session) -> bool | None:
122123
session.hook.pytask_execute_task_teardown(
123124
session=session, task=task
124125
)
125-
except Exception:
126+
except Exception: # noqa: BLE001
126127
report = ExecutionReport.from_task_and_exception(
127128
task, sys.exc_info()
128129
)
@@ -146,8 +147,8 @@ def pytask_execute_build(session: Session) -> bool | None:
146147

147148
if session.should_stop:
148149
break
149-
else:
150-
sleeper.sleep()
150+
sleeper.sleep()
151+
151152
except KeyboardInterrupt:
152153
break
153154

@@ -230,7 +231,7 @@ def _unserialize_and_execute_task(
230231

231232
try:
232233
task.execute(**kwargs)
233-
except Exception:
234+
except Exception: # noqa: BLE001
234235
exc_info = sys.exc_info()
235236
processed_exc_info = _process_exception(
236237
exc_info, show_locals, console_options
@@ -282,8 +283,7 @@ def pytask_execute_task(session: Session, task: Task) -> Future[Any] | None:
282283
return session.config["_parallel_executor"].submit(
283284
_mock_processes_for_threads, func=task.execute, **kwargs
284285
)
285-
else:
286-
return None
286+
return None
287287

288288

289289
def _mock_processes_for_threads(
@@ -299,7 +299,7 @@ def _mock_processes_for_threads(
299299
__tracebackhide__ = True
300300
try:
301301
func(**kwargs)
302-
except Exception:
302+
except Exception: # noqa: BLE001
303303
exc_info = sys.exc_info()
304304
else:
305305
exc_info = None

tests/test_callbacks.py

-46
This file was deleted.

tests/test_config.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
from pytask_parallel.backends import ParallelBackendChoices
1010

1111

12-
@pytest.mark.end_to_end
12+
@pytest.mark.end_to_end()
1313
@pytest.mark.parametrize(
14-
"pdb, n_workers, expected",
14+
("pdb", "n_workers", "expected"),
1515
[
1616
(False, 1, 1),
1717
(True, 1, 1),
@@ -25,9 +25,9 @@ def test_interplay_between_debugging_and_parallel(tmp_path, pdb, n_workers, expe
2525
assert session.config["n_workers"] == expected
2626

2727

28-
@pytest.mark.end_to_end
28+
@pytest.mark.end_to_end()
2929
@pytest.mark.parametrize(
30-
"configuration_option, value, exit_code",
30+
("configuration_option", "value", "exit_code"),
3131
[
3232
("n_workers", "auto", ExitCode.OK),
3333
("n_workers", 1, ExitCode.OK),

tests/test_execute.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Session:
2020
pass
2121

2222

23-
@pytest.mark.end_to_end
23+
@pytest.mark.end_to_end()
2424
@pytest.mark.parametrize("parallel_backend", PARALLEL_BACKENDS)
2525
def test_parallel_execution_speedup(tmp_path, parallel_backend):
2626
source = """
@@ -55,7 +55,7 @@ def task_2(produces):
5555
assert session.execution_end - session.execution_start < 10
5656

5757

58-
@pytest.mark.end_to_end
58+
@pytest.mark.end_to_end()
5959
@pytest.mark.parametrize("parallel_backend", PARALLEL_BACKENDS)
6060
def test_parallel_execution_speedup_w_cli(runner, tmp_path, parallel_backend):
6161
source = """
@@ -102,7 +102,7 @@ def task_2(produces):
102102
assert end - start < 10
103103

104104

105-
@pytest.mark.integration
105+
@pytest.mark.integration()
106106
@pytest.mark.parametrize("parallel_backend", PARALLEL_BACKENDS)
107107
def test_pytask_execute_task_w_processes(parallel_backend):
108108
# Local function which cannot be used with multiprocessing.
@@ -142,7 +142,7 @@ def myfunc():
142142
assert exception is None
143143

144144

145-
@pytest.mark.end_to_end
145+
@pytest.mark.end_to_end()
146146
@pytest.mark.parametrize("parallel_backend", PARALLEL_BACKENDS)
147147
def test_stop_execution_when_max_failures_is_reached(tmp_path, parallel_backend):
148148
source = """
@@ -171,7 +171,7 @@ def task_3(): time.sleep(3)
171171
assert len(session.execution_reports) == 2
172172

173173

174-
@pytest.mark.end_to_end
174+
@pytest.mark.end_to_end()
175175
@pytest.mark.parametrize("parallel_backend", PARALLEL_BACKENDS)
176176
def test_task_priorities(tmp_path, parallel_backend):
177177
source = """
@@ -213,7 +213,7 @@ def task_5():
213213
assert last_task_name.endswith("task_2") or last_task_name.endswith("task_5")
214214

215215

216-
@pytest.mark.end_to_end
216+
@pytest.mark.end_to_end()
217217
@pytest.mark.parametrize("parallel_backend", PARALLEL_BACKENDS)
218218
@pytest.mark.parametrize("show_locals", [True, False])
219219
def test_rendering_of_tracebacks_with_rich(
@@ -239,7 +239,7 @@ def task_raising_error():
239239
assert ("[0, 1, 2, 3, 4]" in result.output) is show_locals
240240

241241

242-
@pytest.mark.end_to_end
242+
@pytest.mark.end_to_end()
243243
@pytest.mark.parametrize("parallel_backend", PARALLEL_BACKENDS)
244244
def test_generators_are_removed_from_depends_on_produces(tmp_path, parallel_backend):
245245
"""Only works with pytask >=0.1.9."""
@@ -265,7 +265,7 @@ def task_example(produces):
265265
assert session.exit_code == ExitCode.OK
266266

267267

268-
@pytest.mark.end_to_end
268+
@pytest.mark.end_to_end()
269269
@pytest.mark.parametrize(
270270
"parallel_backend",
271271
# Capturing warnings is not thread-safe.

0 commit comments

Comments
 (0)