Skip to content

Commit 08d20e2

Browse files
authored
Replace pytest.mark with pytask.mark. (#12)
1 parent 82186ef commit 08d20e2

29 files changed

+632
-64
lines changed

.conda/meta.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ requirements:
2929
- networkx
3030
- pluggy
3131
- pony >=0.7.13
32-
- pytest
3332

3433
test:
3534
imports:
@@ -41,8 +40,9 @@ test:
4140
- tox.ini
4241
- tests
4342
commands:
44-
- pytask --version
4543
- pytask --help
44+
- pytask --markers
45+
- pytask --version
4646

4747
- pytest tests
4848

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
How to configure pytask
2+
=======================
3+
4+
pytask can be configured via the command-line interface or permanently with a
5+
configuration file.
6+
7+
8+
The configuration file
9+
----------------------
10+
11+
pytask accepts configurations in three files which are ``pytask.ini``, ``tox.ini`` and
12+
``setup.cfg``. Place a ``[pytask]`` section in those files and add your configuration
13+
below.
14+
15+
.. code-block:: ini
16+
17+
# Content of tox.ini
18+
19+
[pytask]
20+
ignore =
21+
some_path
22+
23+
You can also leave the section empty. It will still have the benefit that pytask has a
24+
stable root and will store the information about tasks, dependencies, and products in
25+
the same directory as the configuration file.
26+
27+
28+
.. _tutorial_configure_markers:
29+
30+
markers
31+
-------
32+
33+
pytask uses markers to attach additional information to task functions. To see which
34+
markers are available, type
35+
36+
.. code-block:: bash
37+
38+
$ pytask --markers
39+
40+
on the command-line interface.
41+
42+
If you use a marker which has not been configured, you will get a warning. To silence
43+
the warning and document the marker, provide the following information in your pytask
44+
configuration file.
45+
46+
.. code-block:: ini
47+
48+
markers =
49+
wip: Work-in-progress. These are tasks which I am currently working on.

docs/tutorials/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ Tutorials help you to get started with pytask.
1717
how_to_debug
1818
how_to_parametrize_a_task
1919
how_to_set_up_a_project
20+
how_to_configure_pytask
2021
how_to_select_tasks

src/pytask/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import pluggy
2-
from pytask.mark import MARK_GEN as mark # noqa: F401, N811
2+
from pytask.mark.structures import MARK_GEN as mark # noqa: F401, N811
33

4-
__version__ = "0.0.4"
4+
hookimpl = pluggy.HookimplMarker("pytask")
55

66

7-
hookimpl = pluggy.HookimplMarker("pytask")
7+
__version__ = "0.0.4"
8+
9+
__all__ = ["hookimpl", "mark"]

src/pytask/cli.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from pathlib import Path
33

44
import click
5-
import pytask
6-
from pytask.main import main
5+
import pytask.mark.cli
76
from pytask.pluginmanager import get_plugin_manager
87

98

@@ -17,19 +16,33 @@ def add_parameters(func):
1716
pm.hook.pytask_add_hooks(pm=pm)
1817
pm.hook.pytask_add_parameters_to_cli(command=func)
1918

19+
# Hack to pass the plugin manager via a hidden option to the ``config_from_cli``.
20+
func.params.append(click.Option(["--pm"], default=pm, hidden=True))
21+
2022
return func
2123

2224

2325
@pytask.hookimpl
2426
def pytask_add_hooks(pm):
27+
"""Add some hooks and plugins.
28+
29+
This hook implementation registers only plugins which extend the command line
30+
interface or patch the main entry-point :func:`pytask.hookspecs.pytask_main`.
31+
32+
"""
2533
from pytask import database
2634
from pytask import debugging
35+
from pytask import main
36+
from pytask.mark import cli as mark_cli
2737

2838
pm.register(database)
2939
pm.register(debugging)
40+
pm.register(main)
41+
pm.register(mark_cli)
3042

3143

3244
def _to_path(ctx, param, value): # noqa: U100
45+
"""Callback for :class:`click.Argument` or :class:`click.Option`."""
3346
return [Path(i).resolve() for i in value]
3447

3548

@@ -45,7 +58,11 @@ def pytask_add_parameters_to_cli(command):
4558
multiple=True,
4659
help="Ignore path (globs and multi allowed).",
4760
),
48-
click.Option(["--debug-pytask"], is_flag=True, help="Debug pytask."),
61+
click.Option(
62+
["--debug-pytask"],
63+
is_flag=True,
64+
help="Debug pytask by tracing all hook calls.",
65+
),
4966
]
5067
command.params.extend(additional_parameters)
5168

@@ -55,5 +72,6 @@ def pytask_add_parameters_to_cli(command):
5572
@click.version_option()
5673
def pytask(**config_from_cli):
5774
"""Command-line interface for pytask."""
58-
session = main(config_from_cli)
75+
pm = config_from_cli["pm"]
76+
session = pm.hook.pytask_main(config_from_cli=config_from_cli)
5977
sys.exit(session.exit_code)

src/pytask/collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pytask
1212
from pytask.exceptions import CollectionError
1313
from pytask.exceptions import TaskDuplicatedError
14-
from pytask.mark import has_marker
14+
from pytask.mark.structures import has_marker
1515
from pytask.nodes import FilePathNode
1616
from pytask.nodes import PythonFunctionTask
1717
from pytask.report import CollectionReportFile

src/pytask/config.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import click
1010
import pytask
11+
from pytask.mark.structures import MARK_GEN
1112
from pytask.shared import get_first_not_none_value
1213
from pytask.shared import to_list
1314

@@ -23,13 +24,20 @@
2324
def pytask_configure(pm, config_from_cli):
2425
config = {"pm": pm, "terminal_width": _get_terminal_width()}
2526

26-
paths = get_first_not_none_value(config_from_cli, key="paths", callback=to_list)
27+
paths = get_first_not_none_value(
28+
config_from_cli, key="paths", default=[Path.cwd()], callback=to_list
29+
)
2730
paths = [Path(p).resolve() for path in paths for p in glob.glob(path.as_posix())]
2831
config["paths"] = paths if paths else [Path.cwd().resolve()]
2932

3033
config["root"], config["ini"] = _find_project_root_and_ini(config["paths"])
3134
config_from_file = _read_config(config["ini"]) if config["ini"] is not None else {}
3235

36+
config["markers"] = {
37+
"depends_on": "Attach a dependency/dependencies to a task.",
38+
"produces": "Attach a product/products to a task.",
39+
}
40+
3341
config["pm"].hook.pytask_parse_config(
3442
config=config,
3543
config_from_cli=config_from_cli,
@@ -38,6 +46,8 @@ def pytask_configure(pm, config_from_cli):
3846

3947
config["pm"].hook.pytask_post_parse(config=config)
4048

49+
MARK_GEN.config = config
50+
4151
return config
4252

4353

src/pytask/execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from pytask.database import create_or_update_state
1313
from pytask.exceptions import ExecutionError
1414
from pytask.exceptions import NodeNotFoundError
15-
from pytask.mark import Mark
15+
from pytask.mark.structures import Mark
1616
from pytask.nodes import FilePathNode
1717
from pytask.report import ExecutionReport
1818
from pytask.report import format_execute_footer

src/pytask/hookspecs.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ def pytask_add_parameters_to_cli(command: click.Command):
1818
"""Add parameter to :class:`click.Command`."""
1919

2020

21+
# Hooks for the pytask_main interface.
22+
23+
24+
@hookspec(firstresult=True)
25+
def pytask_main(config_from_cli: dict):
26+
"""Take the cli config, create the configuration and start the session."""
27+
28+
2129
# Hooks for the configuration.
2230

2331

src/pytask/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
@pytask.hookimpl
1515
def pytask_add_hooks(pm):
16-
from pytask import cli
1716
from pytask import collect
1817
from pytask import config
1918
from pytask import database
@@ -23,8 +22,8 @@ def pytask_add_hooks(pm):
2322
from pytask import parametrize
2423
from pytask import resolve_dependencies
2524
from pytask import skipping
25+
from pytask.mark import config as mark_config
2626

27-
pm.register(cli)
2827
pm.register(collect)
2928
pm.register(config)
3029
pm.register(database)
@@ -34,9 +33,11 @@ def pytask_add_hooks(pm):
3433
pm.register(parametrize)
3534
pm.register(resolve_dependencies)
3635
pm.register(skipping)
36+
pm.register(mark_config)
3737

3838

39-
def main(config_from_cli):
39+
@pytask.hookimpl
40+
def pytask_main(config_from_cli):
4041
try:
4142
pm = get_plugin_manager()
4243
pm.register(sys.modules[__name__])

0 commit comments

Comments
 (0)