Skip to content

Commit 0d5fffa

Browse files
authored
Release v0.0.3. (#3)
1 parent 8d63937 commit 0d5fffa

18 files changed

+192
-107
lines changed

.conda/meta.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ requirements:
2121
run:
2222
- python >=3.6
2323
- cloudpickle
24-
- pytask >=0.0.5
24+
- pytask >=0.0.6
2525

2626
test:
2727
requires:
@@ -32,6 +32,8 @@ test:
3232
commands:
3333
- pytask --version
3434
- pytask --help
35+
- pytask clean
36+
- pytask markers
3537

3638
- pytest tests
3739

.pre-commit-config.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ repos:
1919
hooks:
2020
- id: reorder-python-imports
2121
- repo: https://github.com/psf/black
22-
rev: 19.10b0
22+
rev: 20.8b1
2323
hooks:
2424
- id: black
2525
- repo: https://github.com/asottile/blacken-docs
26-
rev: v1.7.0
26+
rev: v1.8.0
2727
hooks:
2828
- id: blacken-docs
2929
additional_dependencies: [black]
@@ -48,9 +48,14 @@ repos:
4848
Pygments,
4949
]
5050
- repo: https://github.com/PyCQA/doc8
51-
rev: 0.8.1rc3
51+
rev: 0.9.0a1
5252
hooks:
5353
- id: doc8
54+
- repo: https://github.com/econchick/interrogate
55+
rev: 1.3.1
56+
hooks:
57+
- id: interrogate
58+
args: [-v, --fail-under=40, src, tests]
5459
- repo: https://github.com/codespell-project/codespell
5560
rev: v1.17.1
5661
hooks:

CHANGES.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ chronological order. Releases follow `semantic versioning <https://semver.org/>`
66
all releases are available on `Anaconda.org <https://anaconda.org/pytask/pytask-parallel>`_.
77

88

9+
0.0.3 - 2020-09-12
10+
------------------
11+
12+
- :gh:`3` align the program with pytask v0.0.6.
13+
14+
915
0.0.2 - 2020-08-12
1016
------------------
1117

12-
- :gh:`2` prepares the plugin for pytask v0.0.5.
13-
- :gh:`3` better parsing and callbacks.
18+
- :gh:`1` prepares the plugin for pytask v0.0.5.
19+
- :gh:`2` better parsing and callbacks.
1420

1521

1622
0.0.1 - 2020-07-17

environment.yml

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

1414
# Package dependencies
15-
- pytask >= 0.0.5
15+
- pytask >= 0.0.6
1616
- cloudpickle
1717

1818
# Misc

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.0.2
2+
current_version = 0.0.3
33
parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))(\-?((dev)?(?P<dev>\d+))?)
44
serialize =
55
{major}.{minor}.{patch}dev{dev}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="pytask-parallel",
6-
version="0.0.2",
6+
version="0.0.3",
77
packages=find_packages(where="src"),
88
package_dir={"": "src"},
99
entry_points={"pytask": ["pytask_parallel = pytask_parallel.plugin"]},

src/pytask_parallel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.2"
1+
__version__ = "0.0.3"
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
"""Extend the build command."""
12
import click
23
from _pytask.config import hookimpl
3-
from pytask_parallel.callbacks import delay_click_callback
4-
from pytask_parallel.callbacks import n_workers_click_callback
54

65

76
@hookimpl
8-
def pytask_add_parameters_to_cli(command):
7+
def pytask_extend_command_line_interface(cli):
8+
"""Extend the command line interface."""
99
additional_parameters = [
1010
click.Option(
1111
["-n", "--n-workers"],
@@ -14,12 +14,13 @@ def pytask_add_parameters_to_cli(command):
1414
"os.cpu_count() - 1. [default: 1 (no parallelization)]"
1515
),
1616
metavar="[INTEGER|auto]",
17-
callback=n_workers_click_callback,
17+
default=None,
1818
),
1919
click.Option(
2020
["--parallel-backend"],
2121
type=click.Choice(["processes", "threads"]),
2222
help="Backend for the parallelization. [default: processes]",
23+
default=None,
2324
),
2425
click.Option(
2526
["--delay"],
@@ -28,7 +29,7 @@ def pytask_add_parameters_to_cli(command):
2829
"(seconds)]"
2930
),
3031
metavar="NUMBER > 0",
31-
callback=delay_click_callback,
32+
default=None,
3233
),
3334
]
34-
command.params.extend(additional_parameters)
35+
cli.commands["build"].params.extend(additional_parameters)

src/pytask_parallel/callbacks.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,42 @@
1-
import click
2-
3-
4-
def n_workers_click_callback(ctx, name, value): # noqa: U100
5-
return n_workers_callback(value)
1+
"""Validate command line inputs and configuration values."""
62

73

84
def n_workers_callback(value):
9-
error_occurred = False
5+
"""Validate the n-workers option."""
106
if value == "auto":
117
pass
12-
elif value is None:
13-
pass
8+
elif value is None or value == "None":
9+
value = None
1410
elif isinstance(value, int) and 1 <= value:
1511
pass
12+
elif isinstance(value, str) and value.isdigit():
13+
value = int(value)
1614
else:
17-
try:
18-
value = int(value)
19-
except ValueError:
20-
error_occurred = True
21-
else:
22-
if value < 1:
23-
error_occurred = True
24-
25-
if error_occurred:
26-
raise click.UsageError("n-processes can either be an integer >= 1 or 'auto'.")
15+
raise ValueError("n_processes can either be an integer >= 1, 'auto' or None.")
2716

2817
return value
2918

3019

3120
def parallel_backend_callback(value):
21+
"""Validate the input for the parallel backend."""
22+
if value == "None":
23+
value = None
3224
if value not in ["processes", "threads", None]:
33-
raise click.UsageError("parallel_backend has to be 'processes' or 'threads'.")
25+
raise ValueError("parallel_backend has to be 'processes' or 'threads'.")
3426
return value
3527

3628

37-
def delay_click_callback(ctx, name, value): # noqa: U100
38-
return delay_callback(value)
39-
40-
4129
def delay_callback(value):
42-
error_occurred = False
43-
if isinstance(value, float) and 0 < value:
44-
pass
45-
elif value is None:
46-
pass
30+
"""Validate the delay option."""
31+
if value is None or value == "None":
32+
value = None
4733
else:
4834
try:
4935
value = float(value)
5036
except ValueError:
51-
error_occurred = True
52-
else:
53-
if value < 0:
54-
error_occurred = True
37+
pass
5538

56-
if error_occurred:
57-
raise click.UsageError("delay has to be a number greater than 0.")
39+
if not (isinstance(value, float) and value > 0):
40+
raise ValueError("delay has to be a number greater than 0.")
5841

5942
return value

src/pytask_parallel/config.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
"""Configure pytask."""
12
import os
23

34
from _pytask.config import hookimpl
4-
from _pytask.shared import get_first_not_none_value
5+
from _pytask.shared import get_first_non_none_value
6+
from pytask_parallel.callbacks import delay_callback
57
from pytask_parallel.callbacks import n_workers_callback
68
from pytask_parallel.callbacks import parallel_backend_callback
79

810

911
@hookimpl
1012
def pytask_parse_config(config, config_from_cli, config_from_file):
11-
config["n_workers"] = get_first_not_none_value(
13+
"""Parse the configuration."""
14+
config["n_workers"] = get_first_non_none_value(
1215
config_from_cli,
1316
config_from_file,
1417
key="n_workers",
@@ -18,11 +21,15 @@ def pytask_parse_config(config, config_from_cli, config_from_file):
1821
if config["n_workers"] == "auto":
1922
config["n_workers"] = max(os.cpu_count() - 1, 1)
2023

21-
config["delay"] = get_first_not_none_value(
22-
config_from_cli, config_from_file, key="delay", default=0.1, callback=float
24+
config["delay"] = get_first_non_none_value(
25+
config_from_cli,
26+
config_from_file,
27+
key="delay",
28+
default=0.1,
29+
callback=delay_callback,
2330
)
2431

25-
config["parallel_backend"] = get_first_not_none_value(
32+
config["parallel_backend"] = get_first_non_none_value(
2633
config_from_cli,
2734
config_from_file,
2835
key="parallel_backend",

src/pytask_parallel/execute.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
@hookimpl
1919
def pytask_post_parse(config):
20+
"""Register the parallel backend."""
2021
if config["parallel_backend"] == "processes":
2122
config["pm"].register(ProcessesNameSpace)
2223
elif config["parallel_backend"] == "threads":
@@ -25,6 +26,7 @@ def pytask_post_parse(config):
2526

2627
@hookimpl(tryfirst=True)
2728
def pytask_execute_create_scheduler(session):
29+
"""Create the scheduler."""
2830
if session.config["n_workers"] > 1:
2931
task_names = {task.name for task in session.tasks}
3032
task_dict = {
@@ -41,6 +43,16 @@ def pytask_execute_create_scheduler(session):
4143

4244
@hookimpl(tryfirst=True)
4345
def pytask_execute_build(session):
46+
"""Execute tasks with a parallel backend.
47+
48+
There are three phases while the scheduler has tasks which need to be executed.
49+
50+
1. Take all ready tasks, set up their execution and submit them.
51+
2. For all tasks which are running, find those which have finished and turn them
52+
into a report.
53+
3. Process all reports and report the result on the command line.
54+
55+
"""
4456
if session.config["n_workers"] > 1:
4557
reports = []
4658
running_tasks = {}
@@ -124,18 +136,35 @@ def pytask_execute_build(session):
124136
class ProcessesNameSpace:
125137
@hookimpl(tryfirst=True)
126138
def pytask_execute_task(session, task): # noqa: N805
139+
"""Execute a task.
140+
141+
Take a task, pickle it and send the bytes over to another process.
142+
143+
"""
127144
if session.config["n_workers"] > 1:
128145
bytes_ = cloudpickle.dumps(task)
129146
return session.executor.submit(unserialize_and_execute_task, bytes_)
130147

131148

132149
def unserialize_and_execute_task(bytes_):
150+
"""Unserialize and execute task.
151+
152+
This function receives bytes and unpickles them to a task which is them execute in a
153+
spawned process or thread.
154+
155+
"""
133156
task = cloudpickle.loads(bytes_)
134157
task.execute()
135158

136159

137160
class ThreadsNameSpace:
138161
@hookimpl(tryfirst=True)
139162
def pytask_execute_task(session, task): # noqa: N805
163+
"""Execute a task.
164+
165+
Since threads share their memory, it is not necessary to pickle and unpickle the
166+
task.
167+
168+
"""
140169
if session.config["n_workers"] > 1:
141170
return session.executor.submit(task.execute)

src/pytask_parallel/plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
"""Entry-point for the plugin."""
12
from _pytask.config import hookimpl
2-
from pytask_parallel import cli
3+
from pytask_parallel import build
34
from pytask_parallel import config
45
from pytask_parallel import execute
56

67

78
@hookimpl
89
def pytask_add_hooks(pm):
9-
pm.register(cli)
10+
"""Register plugins."""
11+
pm.register(build)
1012
pm.register(config)
1113
pm.register(execute)

tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
from click.testing import CliRunner
3+
4+
5+
@pytest.fixture()
6+
def runner():
7+
return CliRunner()

0 commit comments

Comments
 (0)