Skip to content

Commit 821ee83

Browse files
authored
Add documentation on rtd. (#93)
1 parent ac2fda1 commit 821ee83

22 files changed

+844
-88
lines changed

.pre-commit-config.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ repos:
3535
rev: 0.7.1
3636
hooks:
3737
- id: nbstripout
38+
- repo: https://github.com/executablebooks/mdformat
39+
rev: 0.7.17
40+
hooks:
41+
- id: mdformat
42+
additional_dependencies: [
43+
mdformat-myst,
44+
mdformat-black,
45+
mdformat-pyproject,
46+
]
47+
files: (docs/.)
3848
# Conflicts with admonitions.
3949
# - repo: https://github.com/executablebooks/mdformat
4050
# rev: 0.7.17

.readthedocs.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
3+
build:
4+
os: ubuntu-22.04
5+
tools:
6+
python: "3.10"
7+
8+
sphinx:
9+
configuration: docs/source/conf.py
10+
fail_on_warning: true
11+
12+
python:
13+
install:
14+
- method: pip
15+
path: .
16+
extra_requirements:
17+
- docs

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
prune docs
12
prune tests
23

34
exclude *.md

README.md

+15-88
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
[![image](https://img.shields.io/github/actions/workflow/status/pytask-dev/pytask-parallel/main.yml?branch=main)](https://github.com/pytask-dev/pytask-parallel/actions?query=branch%3Amain)
99
[![image](https://codecov.io/gh/pytask-dev/pytask-parallel/branch/main/graph/badge.svg)](https://codecov.io/gh/pytask-dev/pytask-parallel)
1010
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/pytask-dev/pytask-parallel/main.svg)](https://results.pre-commit.ci/latest/github/pytask-dev/pytask-parallel/main)
11-
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
11+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
1212

1313
______________________________________________________________________
1414

15-
Parallelize the execution of tasks with `pytask-parallel` which is a plugin for
15+
Parallelize the execution of tasks with `pytask-parallel`, a plugin for
1616
[pytask](https://github.com/pytask-dev/pytask).
1717

1818
## Installation
@@ -28,11 +28,14 @@ $ pip install pytask-parallel
2828
$ conda install -c conda-forge pytask-parallel
2929
```
3030

31-
By default, the plugin uses `concurrent.futures.ProcessPoolExecutor`.
31+
By default, the plugin uses loky's reusable executor.
3232

33-
It is also possible to select the executor from loky or `ThreadPoolExecutor` from the
34-
[concurrent.futures](https://docs.python.org/3/library/concurrent.futures.html) module
35-
as backends to execute tasks asynchronously.
33+
The following backends are available:
34+
35+
- loky's [`get_reusable_executor`](https://loky.readthedocs.io/en/stable/API.html#loky.get_reusable_executor)
36+
- `ProcessPoolExecutor` or `ThreadPoolExecutor` from
37+
[concurrent.futures](https://docs.python.org/3/library/concurrent.futures.html)
38+
- dask's [`ClientExecutor`](https://distributed.dask.org/en/stable/api.html#distributed.Client.get_executor) allows in combination with [coiled](https://docs.coiled.io/user_guide/index.html) to spawn clusters and workers on AWS, GCP, and other providers with minimal configuration.
3639

3740
## Usage
3841

@@ -65,98 +68,22 @@ You can also set the options in a `pyproject.toml`.
6568

6669
[tool.pytask.ini_options]
6770
n_workers = 1
68-
parallel_backend = "processes" # or loky or threads
69-
```
70-
71-
## Custom Executor
72-
73-
> [!NOTE]
74-
>
75-
> The interface for custom executors is rudimentary right now and there is not a lot of
76-
> support by public functions. Please, give some feedback if you are trying or managed
77-
> to use a custom backend.
78-
>
79-
> Also, please contribute your custom executors if you consider them useful to others.
80-
81-
pytask-parallel allows you to use your parallel backend as long as it follows the
82-
interface defined by
83-
[`concurrent.futures.Executor`](https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.Executor).
84-
85-
In some cases, adding a new backend can be as easy as registering a builder function
86-
that receives some arguments (currently only `n_workers`) and returns the instantiated
87-
executor.
88-
89-
```python
90-
from concurrent.futures import Executor
91-
from my_project.executor import CustomExecutor
92-
93-
from pytask_parallel import ParallelBackend, registry
94-
95-
96-
def build_custom_executor(n_workers: int) -> Executor:
97-
return CustomExecutor(max_workers=n_workers)
98-
99-
100-
registry.register_parallel_backend(ParallelBackend.CUSTOM, build_custom_executor)
101-
```
102-
103-
Now, build the project requesting your custom backend.
104-
105-
```console
106-
pytask --parallel-backend custom
71+
parallel_backend = "loky" # or processes or threads
10772
```
10873

109-
Realistically, it is not the only necessary adjustment for a nice user experience. There
110-
are two other important things. pytask-parallel does not implement them by default since
111-
it seems more tightly coupled to your backend.
112-
113-
1. A wrapper for the executed function that captures warnings, catches exceptions and
114-
saves products of the task (within the child process!).
115-
116-
As an example, see
117-
[`def _execute_task()`](https://github.com/pytask-dev/pytask-parallel/blob/c441dbb75fa6ab3ab17d8ad5061840c802dc1c41/src/pytask_parallel/processes.py#L91-L155)
118-
that does all that for the processes and loky backend.
119-
120-
1. To apply the wrapper, you need to write a custom hook implementation for
121-
`def pytask_execute_task()`. See
122-
[`def pytask_execute_task()`](https://github.com/pytask-dev/pytask-parallel/blob/c441dbb75fa6ab3ab17d8ad5061840c802dc1c41/src/pytask_parallel/processes.py#L41-L65)
123-
for an example. Use the
124-
[`hook_module`](https://pytask-dev.readthedocs.io/en/stable/how_to_guides/extending_pytask.html#using-hook-module-and-hook-module)
125-
configuration value to register your implementation.
126-
127-
Another example of an implementation can be found as a
128-
[test](https://github.com/pytask-dev/pytask-parallel/blob/c441dbb75fa6ab3ab17d8ad5061840c802dc1c41/tests/test_backends.py#L35-L78).
129-
130-
## Some implementation details
131-
132-
### Parallelization and Debugging
74+
## Parallelization and Debugging
13375

13476
It is not possible to combine parallelization with debugging. That is why `--pdb` or
13577
`--trace` deactivate parallelization.
13678

13779
If you parallelize the execution of your tasks using two or more workers, do not use
13880
`breakpoint()` or `import pdb; pdb.set_trace()` since both will cause exceptions.
13981

140-
### Threads and warnings
82+
## Documentation
14183

142-
Capturing warnings is not thread-safe. Therefore, warnings cannot be captured reliably
143-
when tasks are parallelized with `--parallel-backend threads`.
84+
You find the documentation at <https://pytask-parallel.readthedocs.io/en/stable>.
14485

14586
## Changes
14687

147-
Consult the [release notes](CHANGES.md) to find out about what is new.
148-
149-
## Development
150-
151-
- `pytask-parallel` does not call the `pytask_execute_task_protocol` hook
152-
specification/entry-point because `pytask_execute_task_setup` and
153-
`pytask_execute_task` need to be separated from `pytask_execute_task_teardown`. Thus,
154-
plugins that change this hook specification may not interact well with the
155-
parallelization.
156-
157-
- Two PRs for CPython try to re-enable setting custom reducers which should have been
158-
working but does not. Here are the references.
159-
160-
- https://bugs.python.org/issue28053
161-
- https://github.com/python/cpython/pull/9959
162-
- https://github.com/python/cpython/pull/15058
88+
Consult the [release notes](https://pytask-parallel.readthedocs.io/en/stable/changes.html) to
89+
find out about what is new.

docs/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?= -W --keep-going
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/make.bat

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

docs/source/_static/images/pytask.ico

3.78 KB
Binary file not shown.

docs/source/_static/images/pytask.png

40.6 KB
Loading

docs/source/_static/images/pytask.svg

+29
Loading
10.1 KB
Loading
Loading
Loading

CHANGES.md docs/source/changes.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ releases are available on [PyPI](https://pypi.org/project/pytask-parallel) and
1313
- {pull}`89` restructures the package.
1414
- {pull}`92` redirects stdout and stderr from processes and loky and shows them in error
1515
reports.
16+
- {pull}`93` adds documentation on readthedocs.
17+
- {pull}`94` implements `ParallelBackend.NONE` as the default backend.
1618

1719
## 0.4.1 - 2024-01-12
1820

0 commit comments

Comments
 (0)