Skip to content

Commit 5ddf29c

Browse files
authored
Implement pytask collect. (#31)
1 parent 07eafbb commit 5ddf29c

File tree

16 files changed

+543
-45
lines changed

16 files changed

+543
-45
lines changed

.conda/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package:
55
version: {{ data.get('version') }}
66

77
source:
8-
# git_url is nice in that it won't capture devenv stuff. However, it only captures
8+
# git_url is nice in that it won't capture devenv stuff. However, it only captures
99
# committed code, so pay attention.
1010
git_url: ../
1111

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
- id: check-yaml
99
exclude: meta.yaml
1010
- id: debug-statements
11-
exclude: (debugging\.py|build\.py|clean\.py|mark/__init__\.py)
11+
exclude: (debugging\.py|build\.py|clean\.py|mark/__init__\.py|collect_command\.py)
1212
- id: end-of-file-fixer
1313
- repo: https://github.com/asottile/pyupgrade
1414
rev: v2.7.2

README.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
------
66

7+
.. start-badges
8+
79
.. image:: https://anaconda.org/pytask/pytask/badges/version.svg
810
:target: https://anaconda.org/pytask/pytask
911

@@ -23,6 +25,9 @@
2325
:target: https://github.com/psf/black
2426

2527

28+
.. end-badges
29+
30+
2631
Features
2732
--------
2833

@@ -52,6 +57,8 @@ explanations/why_do_i_need_a_build_system.html>`_ if you do not know or are not
5257
convinced that you need a build system.
5358

5459

60+
.. start-installation
61+
5562
Installation
5663
------------
5764

@@ -63,6 +70,7 @@ package with
6370
$ conda config --add channels conda-forge --add channels pytask
6471
$ conda install pytask
6572
73+
.. end-installation
6674
6775
Usage
6876
-----

docs/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 `Anaconda.org <https://anaconda.org/pytask/pytask>
1111

1212
- :gh:`30` fixes or adds the session object to some hooks which was missing from the
1313
previous release.
14+
- :gh:`31` adds ``pytask collect`` to show information on collected tasks.
1415

1516

1617
0.0.7 - 2020-10-03

docs/index.rst

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
11
pytask
22
======
33

4-
.. image:: https://anaconda.org/pytask/pytask/badges/version.svg
5-
:target: https://anaconda.org/pytask/pytask
4+
.. include:: ../README.rst
5+
:start-after: start-badges
6+
:end-before: end-badges
67

7-
.. image:: https://anaconda.org/pytask/pytask/badges/platforms.svg
8-
:target: https://anaconda.org/pytask/pytask
98

10-
.. image:: https://readthedocs.org/projects/pytask-dev/badge/?version=latest
11-
:target: https://pytask-dev.readthedocs.io/en/latest
12-
13-
.. image:: https://github.com/pytask-dev/pytask/workflows/Continuous%20Integration%20Workflow/badge.svg?branch=main
14-
:target: https://github.com/pytask-dev/pytask/actions?query=branch%3Amain
15-
16-
17-
.. image:: https://codecov.io/gh/pytask-dev/pytask/branch/main/graph/badge.svg
18-
:target: https://codecov.io/gh/pytask-dev/pytask
19-
20-
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
21-
:target: https://github.com/psf/black
22-
23-
----
24-
25-
This is the documentation of pytask. You can install the package from `Anaconda.org
26-
<https://anaconda.org/pytask/pytask>`_ with
27-
28-
.. code-block:: console
29-
30-
$ conda config --add channels conda-forge --add channels pytask
31-
$ conda install pytask
9+
.. include:: ../README.rst
10+
:start-after: start-installation
11+
:end-before: end-installation
3212

3313
The documentation has four central parts.
3414

docs/reference_guides/hookspecs.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Command Line Interface
3838
Configuration
3939
-------------
4040

41+
The following hooks are used to configure pytask with the information from the command
42+
line and the configuration file as well as making sure that all options play nicely
43+
together.
44+
4145
.. autofunction:: pytask_configure
4246
:noindex:
4347

@@ -51,6 +55,8 @@ Configuration
5155
Collection
5256
----------
5357

58+
The following hooks traverse directories and collect tasks from files.
59+
5460
.. autofunction:: pytask_collect
5561
:noindex:
5662

@@ -99,9 +105,41 @@ duplicates are collected with :func:`pytask_collect_task`.
99105
:noindex:
100106

101107

108+
Resolving Dependencies
109+
----------------------
110+
111+
The following hooks are designed to build a DAG from tasks and dependencies and check
112+
which files have changed and need to be re-run.
113+
114+
.. warning::
115+
116+
This step is still experimental and likely to change in the future. If you are
117+
planning to write a plugin which extends pytask in this dimension, please, start a
118+
discussion before writing a plugin. It may make your life easier if changes in pytask
119+
anticipate your plugin.
120+
121+
122+
.. autofunction:: pytask_resolve_dependencies
123+
:noindex:
124+
125+
.. autofunction:: pytask_resolve_dependencies_create_dag
126+
:noindex:
127+
128+
.. autofunction:: pytask_resolve_dependencies_validate_dag
129+
:noindex:
130+
131+
.. autofunction:: pytask_resolve_dependencies_select_execution_dag
132+
:noindex:
133+
134+
.. autofunction:: pytask_resolve_dependencies_log
135+
:noindex:
136+
137+
102138
Execution
103139
---------
104140

141+
The following hooks execute the tasks and log information on the result in the terminal.
142+
105143
.. autofunction:: pytask_execute
106144
:noindex:
107145

docs/tutorials/how_to_clean.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ and type
1010
.. code-block:: console
1111
1212
$ pytask clean
13-
=============================== Start pytask session ===============================
13+
========================= Start pytask session =========================
1414
Platform: win32 -- Python x.y.z, pytask x.y.z, pluggy x.y.z
1515
Root: .
1616
Collected 3 task(s).
@@ -37,7 +37,7 @@ If you want to delete whole folders instead of only the files in them, use
3737
.. code-block:: console
3838
3939
$ pytask clean -d
40-
=============================== Start pytask session ===============================
40+
========================= Start pytask session =========================
4141
Platform: win32 -- Python x.y.z, pytask x.y.z, pluggy x.y.z
4242
Root: .
4343
Collected 3 task(s).
@@ -48,9 +48,7 @@ If you want to delete whole folders instead of only the files in them, use
4848
Would remove C:\Users\project\obsolete_folder.
4949
5050
51-
Command line options
52-
--------------------
51+
Further reading
52+
---------------
5353

54-
.. click:: _pytask.cli:cli
55-
:commands: clean
56-
:prog: pytask
54+
- :program:`pytask clean` in :doc:`../reference_guides/command_line_interface`.

docs/tutorials/how_to_collect.rst

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
How to collect tasks
2+
====================
3+
4+
If you want to inspect your project and see a summary of all the tasks in the projects,
5+
you can use the :program:`pytask collect` command.
6+
7+
For example, let us take the following task
8+
9+
.. code-block:: python
10+
11+
# Content of task_dummy.py
12+
13+
import pytask
14+
15+
16+
@pytask.mark.depends_on("in.txt")
17+
@pytask.mark.produces("out.txt")
18+
def task_write_file(depends_on, produces):
19+
produces.write_text(depends_on.read_text())
20+
21+
22+
Now, running :program:`pytask collect` will produce the following output.
23+
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_dummy.py>
33+
<Function task_write_file>
34+
35+
========================================================================
36+
37+
If you want to have more information regarding dependencies and products of the task,
38+
append the ``--nodes`` flag.
39+
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_dummy.py>
49+
<Function task_write_file>
50+
<Dependency /.../in.txt>
51+
<Product /.../out.txt>
52+
53+
========================================================================
54+
55+
To restrict the set of tasks you are looking at, use markers, expression and ignore
56+
patterns as usual.
57+
58+
59+
Further reading
60+
---------------
61+
62+
- :program:`pytask collect` in :doc:`../reference_guides/command_line_interface`.

docs/tutorials/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ organize and start your own project.
1616
how_to_configure_pytask
1717
how_to_select_tasks
1818
how_to_clean
19+
how_to_collect
1920
how_to_make_tasks_persist

src/_pytask/clean.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ def clean(**config_from_cli):
7575
session = Session.from_config(config)
7676

7777
except Exception:
78-
traceback.print_exception(*sys.exc_info())
7978
session = Session({}, None)
8079
session.exit_code = ExitCode.CONFIGURATION_FAILED
8180

8281
if config_from_cli.get("pdb"):
82+
traceback.print_exception(*sys.exc_info())
8383
pdb.post_mortem()
8484

8585
else:
@@ -112,13 +112,16 @@ def clean(**config_from_cli):
112112
else:
113113
path.unlink()
114114

115-
click.echo("")
115+
click.echo("\n" + "=" * config["terminal_width"])
116116

117117
except CollectionError:
118118
session.exit_code = ExitCode.COLLECTION_FAILED
119119

120120
except Exception:
121121
traceback.print_exception(*sys.exc_info())
122+
if config["pdb"]:
123+
pdb.post_mortem()
124+
122125
session.exit_code = ExitCode.FAILED
123126

124127
sys.exit(session.exit_code)

0 commit comments

Comments
 (0)