Skip to content

Commit 318b668

Browse files
authored
Add more figures to the documentation. (#193)
1 parent df94ebc commit 318b668

22 files changed

+100
-160
lines changed

README.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ projects. Its features include:
6666
<https://pytask-dev.readthedocs.io/en/latest/tutorials/how_to_select_tasks.html>`_
6767
known from pytest.
6868

69-
- **Easily extensible with plugins**. pytask's architecture is based on `pluggy
70-
<https://pluggy.readthedocs.io/en/latest/>`_, a plugin management framework, so that
71-
you can adjust pytask to your needs. Plugins are available for `parallelization
69+
- **Easily extensible with plugins**. pytask is built on top of `pluggy
70+
<https://pluggy.readthedocs.io/en/latest/>`_, a plugin management framework, which
71+
allows you to adjust pytask to your needs. Plugins are available for `parallelization
7272
<https://github.com/pytask-dev/pytask-parallel>`_, `LaTeX
7373
<https://github.com/pytask-dev/pytask-latex>`_, `R
7474
<https://github.com/pytask-dev/pytask-r>`_, and `Stata
75-
<https://github.com/pytask-dev/pytask-stata>`_ and `many more
76-
<https://github.com/topics/pytask>`_. Read `here
75+
<https://github.com/pytask-dev/pytask-stata>`_ and more can be found `here
76+
<https://github.com/topics/pytask>`_. Read in `this tutorial
7777
<https://pytask-dev.readthedocs.io/en/latest/tutorials/how_to_use_plugins.html>`_ how
78-
you can use plugins.
78+
to use and create plugins.
7979

8080
.. end-features
8181
Loading
Loading
Loading
Loading
Loading
24.4 KB
Loading
24.7 KB
Loading
Loading
Loading
20.6 KB
Loading
98.9 KB
Loading

docs/source/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
1111
------------------
1212

1313
- :gh:`191` adds a guide on how to profile pytask to the developer's guide.
14+
- :gh:`193` adds more figures to the documentation.
1415

1516

1617
0.1.5 - 2022-01-10

docs/source/how_to_guides/how_to_write_a_plugin.rst

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ steps.
1616
- Check whether there exist plugins which offer similar functionality. For example, many
1717
plugins provide convenient interfaces to run another program with inputs via the
1818
command line. Naturally, there is a lot of overlap in the structure of the program and
19-
even the the test battery. Finding the right plugin as a template may save you a lot
20-
of time.
19+
even the test battery. Finding the right plugin as a template may save you a lot of
20+
time.
2121

2222
- Make a list of hooks you want to implement. Think about how this plugin relates to
2323
functionality defined in pytask and other plugins. Maybe skim the documentation on
@@ -38,25 +38,38 @@ This section explains some steps which are required for all plugins.
3838
Set up the setuptools entry-point
3939
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4040

41-
pytask discovers plugins via ``setuptools`` entry-points. This is specified in
42-
``setup.py``. See the following example.
41+
pytask discovers plugins via ``setuptools`` entry-points. Following the approach
42+
advocated for by `setuptools_scm <https://github.com/pypa/setuptools_scm>`_, the
43+
entry-point is specified in ``setup.cfg``.
4344

44-
.. code-block:: python
45+
.. code-block:: cfg
46+
47+
# Content of setup.cfg
48+
49+
[metadata]
50+
name = pytask-plugin
51+
52+
[options.packages.find]
53+
where = src
54+
55+
[options.entry_points]
56+
pytask =
57+
pytask_plugin = pytask_plugin.plugin
58+
59+
For ``setuptools_scm`` you also need a ``pyproject.toml`` with the following content.
60+
61+
.. code-block:: toml
4562
46-
# Content of setup.py
63+
# Content of pyproject.toml
4764
48-
from setuptools import find_packages
49-
from setuptools import setup
65+
[build-system]
66+
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]
5067
51-
setup(
52-
name="pytask-plugin",
53-
version="0.0.1",
54-
entry_points={"pytask": ["pytask_plugin = pytask_plugin.plugin"]},
55-
# PyPI classifier for pytask plugins
56-
classifiers=["Framework :: pytask"],
57-
)
68+
[tool.setuptools_scm]
69+
write_to = "src/pytask_plugin/_version.py"
5870
59-
For an example with ``setuptools_scm`` and ``setup.cfg`` see the `pytask-parallel repo
71+
For a complete example with ``setuptools_scm`` and ``setup.cfg`` see the
72+
`pytask-parallel repo
6073
<https://github.com/pytask-dev/pytask-parallel/blob/main/setup.cfg>`_.
6174

6275
The entry-point for pytask is called ``"pytask"`` and points to a module called

docs/source/tutorials/how_to_capture_output.rst

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ You can influence output capturing mechanisms from the command line:
4646

4747
.. code-block:: console
4848
49-
pytask -s # disable all capturing
50-
pytask --capture=sys # replace sys.stdout/stderr with in-mem files
51-
pytask --capture=fd # also point filedescriptors 1 and 2 to temp file
52-
pytask --capture=tee-sys # combines 'sys' and '-s', capturing sys.stdout/stderr
53-
# and passing it along to the actual sys.stdout/stderr
49+
$ pytask -s # disable all capturing
50+
$ pytask --capture=sys # replace sys.stdout/stderr with in-mem files
51+
$ pytask --capture=fd # also point filedescriptors 1 and 2 to temp file
52+
$ pytask --capture=tee-sys # combines 'sys' and '-s', capturing sys.stdout/stderr
53+
# and passing it along to the actual sys.stdout/stderr
5454
5555
5656
Using print statements for debugging
@@ -75,24 +75,4 @@ print statements for debugging:
7575
and running this module will show you precisely the output of the failing function and
7676
hide the other one:
7777

78-
.. code-block:: console
79-
80-
$ pytask -s
81-
========================= Start pytask session =========================
82-
Platform: win32 -- Python 3.x.x, pytask 0.x.x, pluggy 0.13.x
83-
Root: .
84-
Collected 2 task(s).
85-
86-
F.
87-
=============================== Failures ===============================
88-
_________________ Task task_capture.py::task_func2 failed ______________
89-
90-
Traceback (most recent call last):
91-
File "task_capture.py", line 7, in task_func2
92-
assert False
93-
AssertionError
94-
95-
---------------------- Captured stdout during call ---------------------
96-
Debug statement.
97-
98-
==================== 1 succeeded, 1 failed in 0.01s ====================
78+
.. image:: /_static/images/how-to-capture-output.png

docs/source/tutorials/how_to_collect_tasks.rst

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,12 @@ For example, let us take the following task
2121
2222
Now, running :program:`pytask collect` will produce the following output.
2323

24-
.. code-block:: console
25-
26-
$ pytask collect
27-
========================= Start pytask session =========================
28-
Platform: linux -- Python 3.x.y, pytask 0.x.y, pluggy 0.x.y
29-
Root: xxx
30-
Collected 1 task(s).
31-
32-
<Module /.../task_module.py>
33-
<Function task_write_file>
34-
35-
========================================================================
24+
.. image:: /_static/images/pytask-collect.png
3625

3726
If you want to have more information regarding dependencies and products of the task,
3827
append the ``--nodes`` flag.
3928

40-
.. code-block:: console
41-
42-
$ pytask collect
43-
========================= Start pytask session =========================
44-
Platform: linux -- Python 3.x.y, pytask 0.x.y, pluggy 0.x.y
45-
Root: xxx
46-
Collected 1 task(s).
47-
48-
<Module /.../task_module.py>
49-
<Function task_write_file>
50-
<Dependency /.../in.txt>
51-
<Product /.../out.txt>
52-
53-
========================================================================
29+
.. image:: /_static/images/pytask-collect-nodes.png
5430

5531
To restrict the set of tasks you are looking at, use markers, expression and ignore
5632
patterns as usual.
@@ -59,4 +35,7 @@ patterns as usual.
5935
Further reading
6036
---------------
6137

62-
- :program:`pytask collect` in :doc:`../reference_guides/command_line_interface`.
38+
- The documentation on the command line interface of :program:`pytask collect` can be
39+
found :doc:`here <../reference_guides/command_line_interface>`.
40+
- Read :doc:`here <how_to_select_tasks>` about selecting tasks.
41+
- Paths can be ignored with :confval:`ignore`.

docs/source/tutorials/how_to_debug.rst

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,19 @@ Tracebacks
1212
----------
1313

1414
You can enrich the display of tracebacks by showing local variables in each stack frame.
15-
Just execute pytask with
15+
Just execute pytask with :confval:`show_locals`, meaning ``pytask --show-locals``.
1616

17-
.. code-block:: console
18-
19-
$ pytask --show-locals
17+
.. image:: /_static/images/how-to-debug-show-locals.png
2018

2119

2220
Debugging
2321
---------
2422

25-
Running
26-
27-
.. code-block:: console
23+
Using :confval:`pdb` enables the post-mortem debugger. Whenever an exception is raised
24+
inside a task, the prompt will enter the debugger enabling you to find out the cause of
25+
the exception.
2826

29-
$ pytask --pdb
30-
31-
enables the post-mortem debugger. Whenever an exception is raised inside a task, the
32-
prompt will enter the debugger enabling you to discover the source of the exception.
27+
.. image:: /_static/images/how-to-debug-pdb.png
3328

3429
.. seealso::
3530

@@ -46,11 +41,9 @@ prompt will enter the debugger enabling you to discover the source of the except
4641
Tracing
4742
-------
4843

49-
If you want to enter the debugger at the start of every task, use
50-
51-
.. code-block:: console
44+
If you want to enter the debugger at the start of every task, use :confval:`trace`.
5245

53-
$ pytask --trace
46+
.. image:: /_static/images/how-to-debug-trace.png
5447

5548

5649
Custom debugger
Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
How to make tasks persist
22
=========================
33

4-
Sometimes you want to skip the execution. It means that if all dependencies
5-
and products exist, the task will not be executed even though a dependency, the task's
6-
source file or a product has changed. Instead, the state of the dependencies, the source
7-
file and the products is updated in the database such that the next execution will skip
8-
the task successfully.
4+
Sometimes you want to skip the execution of a task and pretend like nothing has changed.
5+
6+
A common scenario is that you have a long running task which will be executed again if
7+
you would format the task's source file with `black <https://github.com/psf/black>`_.
8+
9+
In this case, you can apply the ``@pytask.mark.persist`` decorator to the task which
10+
will skip its execution as long as all products exist.
11+
12+
Internally, the state of the dependencies, the source file and the products is updated
13+
in the database such that the next execution will skip the task successfully.
14+
915

1016
When is this useful?
1117
--------------------
1218

13-
- You ran a formatter like Black on the files in your project.
19+
- You ran a formatter like Black on the files in your project and want to prevent the
20+
longest running tasks from being rerun.
1421

1522
- You extend a parametrization, but do not want to rerun all tasks.
1623

@@ -30,12 +37,11 @@ How to do it?
3037

3138
To create a persisting task, apply the correct decorator and, et voilà, it is done.
3239

33-
Let us take the second scenario as an example. First, we define the tasks, the
34-
dependency and the product and save everything in the same folder.
40+
To see the whole process, first, we create some task and its dependency.
3541

3642
.. code-block:: python
3743
38-
# Content of task_file.py
44+
# Content of task_module.py
3945
4046
import pytask
4147
@@ -47,45 +53,25 @@ dependency and the product and save everything in the same folder.
4753
produces.write_text("**" + depends_on.read_text() + "**")
4854
4955
50-
.. code-block::
56+
.. code-block:: md
5157
52-
# Content of input.md. Do not copy this line.
58+
<!-- Content of input.md. -->
5359
5460
Here is the text.
5561
62+
If you execute the task with pytask, the task will be executed since the product is
63+
missing.
5664

57-
.. code-block::
58-
59-
# Content of output.md. Do not copy this line.
60-
61-
**Here is the text.**
62-
63-
64-
If you run pytask in this folder, you get the following output.
65-
66-
.. code-block:: console
67-
68-
$ pytask demo
69-
========================= Start pytask session =========================
70-
Platform: win32 -- Python 3.8.5, pytask 0.0.6, pluggy 0.13.1
71-
Root: xxx/demo
72-
Collected 1 task(s).
73-
74-
p
75-
====================== 1 succeeded in 1 second(s) ======================
76-
77-
The green p signals that the task persisted. Another execution will show the following.
65+
.. image:: /_static/images/persist-executed.png
7866

79-
.. code-block:: console
67+
After that, we change the source file of the task accidentally by formatting the file
68+
with black. Without the ``@pytask.mark.persist`` decorator the task would run again
69+
since it has changed. With the decorator, the execution is skipped which is signaled by
70+
a green p.
8071

81-
$ pytask demo
82-
========================= Start pytask session =========================
83-
Platform: win32 -- Python 3.8.5, pytask 0.0.6, pluggy 0.13.1
84-
Root: xxx/demo
85-
Collected 1 task(s).
72+
.. image:: /_static/images/persist-persisted.png
8673

87-
s
88-
====================== 1 succeeded in 1 second(s) ======================
74+
If we now run the task again, it is skipped because nothing has changed and not because
75+
it is marked with ``@pytask.mark.persist``.
8976

90-
Now, the task is skipped successfully because nothing has changed compared to the
91-
previous run.
77+
.. image:: /_static/images/persist-skipped-successfully.png

docs/source/tutorials/how_to_profile_tasks.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ display the information, enter
77
.. code-block:: console
88
99
$ pytask profile
10+
11+
Here is an example
12+
13+
.. image:: /_static/images/pytask-profile.png

docs/source/tutorials/how_to_use_plugins.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Plugins can be found in many places.
2626
How to use plugins
2727
------------------
2828

29-
To use a plugin, simply follow the installation instructions. A plugin will enable
30-
itself by using pytask's entry-point.
29+
To use a plugin, simply follow the installation instructions and the accompanying
30+
documentation. A plugin will usually enable itself by using pytask's entry-point.
3131

3232

3333
How to implement your own plugin

0 commit comments

Comments
 (0)