Skip to content

Commit 402bf28

Browse files
authored
Merge 93093ab into 7eac739
2 parents 7eac739 + 93093ab commit 402bf28

File tree

8 files changed

+60
-45
lines changed

8 files changed

+60
-45
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,16 @@ jobs:
2727
fail-fast: false
2828
matrix:
2929
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
30-
python-version: ['3.8', '3.9', '3.10', '3.11']
30+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
3131

3232
steps:
3333
- uses: actions/checkout@v4
34-
- uses: mamba-org/setup-micromamba@v1
34+
- uses: actions/setup-python@v4
3535
with:
36-
environment-name: gha-testing
37-
condarc: |
38-
channels:
39-
- nodefaults
40-
- conda-forge
41-
create-args: >-
42-
python=${{ matrix.python-version }}
43-
mamba
44-
tox-conda
45-
cache-environment: true
46-
47-
- name: Install core dependencies.
48-
shell: bash -l {0}
49-
run: conda install -c conda-forge tox-conda coverage
36+
python-version: ${{ matrix.python-version }}
37+
cache: pip
38+
allow-prereleases: true
39+
- run: pip install tox
5040

5141
# Unit, integration, and end-to-end tests.
5242

@@ -55,24 +45,15 @@ jobs:
5545
run: tox -e pytest -- tests -m "unit or (not integration and not end_to_end)" --cov=./ --cov-report=xml -n auto
5646

5747
- name: Upload coverage report for unit tests and doctests.
58-
if: runner.os == 'Linux' && matrix.python-version == '3.9'
48+
if: runner.os == 'Linux' && matrix.python-version == '3.10'
5949
shell: bash -l {0}
6050
run: bash <(curl -s https://codecov.io/bash) -F unit -c
6151

62-
# - name: Run integration tests.
63-
# shell: bash -l {0}
64-
# run: tox -e pytest -- tests -m integration --cov=./ --cov-report=xml -n auto
65-
66-
# - name: Upload coverage reports of integration tests.
67-
# if: runner.os == 'Linux' && matrix.python-version == '3.9'
68-
# shell: bash -l {0}
69-
# run: bash <(curl -s https://codecov.io/bash) -F integration -c
70-
7152
- name: Run end-to-end tests.
7253
shell: bash -l {0}
7354
run: tox -e pytest -- tests -m end_to_end --cov=./ --cov-report=xml -n auto
7455

7556
- name: Upload coverage reports of end-to-end tests.
76-
if: runner.os == 'Linux' && matrix.python-version == '3.9'
57+
if: runner.os == 'Linux' && matrix.python-version == '3.10'
7758
shell: bash -l {0}
7859
run: bash <(curl -s https://codecov.io/bash) -F end_to_end -c

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ repos:
88
- id: check-merge-conflict
99
- id: check-vcs-permalinks
1010
- id: check-yaml
11-
- id: debug-statements
1211
- id: end-of-file-fixer
1312
- id: fix-byte-order-marker
1413
- id: mixed-line-ending
@@ -72,9 +71,10 @@ repos:
7271
--ignore-missing-imports,
7372
]
7473
additional_dependencies: [
74+
attrs,
7575
cloudpickle,
76-
optree,
77-
pytask==0.4.0rc2,
76+
loky,
77+
pytask==0.4.0,
7878
rich,
7979
types-attrs,
8080
types-click,

CHANGES.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
55
releases are available on [PyPI](https://pypi.org/project/pytask-parallel) and
66
[Anaconda.org](https://anaconda.org/conda-forge/pytask-parallel).
77

8-
## 0.4.0 - 2023-xx-xx
8+
## 0.4.0 - 2023-10-07
99

1010
- {pull}`62` deprecates Python 3.7.
1111
- {pull}`64` aligns pytask-parallel with pytask v0.4.0rc2.
1212
- {pull}`66` deactivates parallelization for dry-runs.
1313
- {pull}`67` fixes parallelization with partialed task functions.
14-
- {pull}`68` updates dependencies and syntaxes.
14+
- {pull}`68` raises more informative error message when `breakpoint()` was uses when
15+
parallelizing with processes or loky.
1516

1617
## 0.3.1 - 2023-05-27
1718

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies:
1212
- toml
1313

1414
# Package dependencies
15-
- pytask>=0.4.0rc4
15+
- pytask>=0.4.0
1616
- cloudpickle
1717
- loky
1818
- optree

setup.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ install_requires =
2828
click
2929
cloudpickle
3030
loky
31-
optree>=0.9.0
3231
pluggy>=1.0.0
33-
pytask>=0.4.0rc2
32+
pytask>=0.4.0
3433
rich
3534
python_requires = >=3.8
3635
include_package_data = True

src/pytask_parallel/execute.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,28 @@ def pytask_execute_task(session: Session, task: PTask) -> Future[Any] | None:
210210
return None
211211

212212

213+
def _raise_exception_on_breakpoint(*args: Any, **kwargs: Any) -> None: # noqa: ARG001
214+
raise RuntimeError(
215+
"You cannot use 'breakpoint()' or 'pdb.set_trace()' while parallelizing the "
216+
"execution of tasks with pytask-parallel. Please, remove the breakpoint or run "
217+
"the task without parallelization to debug it."
218+
)
219+
220+
221+
def _patch_set_trace_and_breakpoint() -> None:
222+
"""Patch :func:`pdb.set_trace` and :func:`breakpoint`.
223+
224+
Patch sys.breakpointhook to intercept any call of breakpoint() and pdb.set_trace in
225+
a subprocess and print a better exception message.
226+
227+
"""
228+
import pdb # noqa: T100
229+
import sys
230+
231+
pdb.set_trace = _raise_exception_on_breakpoint
232+
sys.breakpointhook = _raise_exception_on_breakpoint
233+
234+
213235
def _execute_task( # noqa: PLR0913
214236
task: PTask,
215237
kwargs: dict[str, Any],
@@ -225,6 +247,7 @@ def _execute_task( # noqa: PLR0913
225247
226248
"""
227249
__tracebackhide__ = True
250+
_patch_set_trace_and_breakpoint()
228251

229252
with warnings.catch_warnings(record=True) as log:
230253
# mypy can't infer that record=True means log is not None; help it.

tests/test_execute.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,17 @@ def test_parallel_execution_is_deactivated(runner, tmp_path, flag, parallel_back
268268
)
269269
assert result.exit_code == ExitCode.OK
270270
assert "Started 2 workers" not in result.output
271+
272+
273+
@pytest.mark.end_to_end()
274+
@pytest.mark.parametrize("code", ["breakpoint()", "import pdb; pdb.set_trace()"])
275+
@pytest.mark.parametrize(
276+
"parallel_backend", [i for i in PARALLEL_BACKENDS if i != ParallelBackend.THREADS]
277+
)
278+
def test_raise_error_on_breakpoint(runner, tmp_path, code, parallel_backend):
279+
tmp_path.joinpath("task_example.py").write_text(f"def task_example(): {code}")
280+
result = runner.invoke(
281+
cli, [tmp_path.as_posix(), "-n 2", "--parallel-backend", parallel_backend]
282+
)
283+
assert result.exit_code == ExitCode.FAILED
284+
assert "You cannot use 'breakpoint()'" in result.output

tox.ini

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@ envlist = pytest
55
usedevelop = true
66

77
[testenv:pytest]
8-
conda_channels =
9-
conda-forge/label/pytask_rc
10-
conda-forge
11-
nodefaults
12-
conda_deps =
8+
deps =
9+
# pytest
10+
pytest
11+
pytest-cov
12+
pytest-xdist
1313
setuptools_scm
1414
toml
1515

16+
# Package
17+
pytask >=0.4.0
1618
cloudpickle
1719
loky
18-
pytask >=0.4.0rc2
19-
pytest
20-
pytest-cov
21-
pytest-xdist
2220
commands =
23-
pip install --no-deps -e .
2421
pytest {posargs}

0 commit comments

Comments
 (0)