Skip to content

Commit 98a82f1

Browse files
committed
Fix errors and remove callback modules.
1 parent b59a993 commit 98a82f1

File tree

7 files changed

+32
-108
lines changed

7 files changed

+32
-108
lines changed

src/pytask_parallel/__init__.py

Lines changed: 1 addition & 0 deletions
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

Lines changed: 7 additions & 3 deletions
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

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/pytask_parallel/execute.py

Lines changed: 12 additions & 12 deletions
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

Lines changed: 0 additions & 46 deletions
This file was deleted.

tests/test_config.py

Lines changed: 4 additions & 4 deletions
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

Lines changed: 8 additions & 8 deletions
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)