Skip to content

Commit 19325a1

Browse files
authored
Skip collection of MarkGenerator when using from pytask import mark. (#576)
1 parent c7f3da8 commit 19325a1

9 files changed

+22
-17
lines changed

docs/source/changes.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
55
releases are available on [PyPI](https://pypi.org/project/pytask) and
66
[Anaconda.org](https://anaconda.org/conda-forge/pytask).
77

8+
## 0.4.6 - 2024-03-13
9+
10+
- {pull}`576` fixes accidentally collecting `pytask.MarkGenerator` when using
11+
`from pytask import mark`.
12+
813
## 0.4.5 - 2024-01-09
914

1015
- {pull}`515` enables tests with graphviz in CI. Thanks to {user}`NickCrews`.

docs/source/reference_guides/api.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ For example:
177177

178178
```python
179179
@pytask.mark.timeout(10, "slow", method="thread")
180-
def task_function():
181-
...
180+
def task_function(): ...
182181
```
183182

184183
Will create and attach a {class}`Mark <pytask.Mark>` object to the collected
@@ -195,8 +194,7 @@ Example for using multiple custom markers:
195194
```python
196195
@pytask.mark.timeout(10, "slow", method="thread")
197196
@pytask.mark.slow
198-
def task_function():
199-
...
197+
def task_function(): ...
200198
```
201199

202200
### Classes

docs/source/tutorials/repeating_tasks_with_different_inputs.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ the {func}`@task <pytask.task>` decorator to pass keyword arguments to the task.
328328
for id_, kwargs in ID_TO_KWARGS.items():
329329

330330
@task(id=id_, kwargs=kwargs)
331-
def task_create_random_data(seed, produces):
332-
...
331+
def task_create_random_data(seed, produces): ...
333332
```
334333

335334
Writing a function that creates `ID_TO_KWARGS` would be even more pythonic.
@@ -349,8 +348,7 @@ ID_TO_KWARGS = create_parametrization()
349348
for id_, kwargs in ID_TO_KWARGS.items():
350349

351350
@task(id=id_, kwargs=kwargs)
352-
def task_create_random_data(i, produces):
353-
...
351+
def task_create_random_data(i, produces): ...
354352
```
355353

356354
The {doc}`best-practices guide on parametrizations <../how_to_guides/bp_scaling_tasks>`

docs/source/tutorials/selecting_tasks.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ from pytask import task
9191
for i in range(2):
9292

9393
@task
94-
def task_parametrized(i=i):
95-
...
94+
def task_parametrized(i=i): ...
9695
```
9796

9897
To run the task where `i = 1`, run this command.

docs/source/tutorials/skipping_tasks.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ from config import NO_LONG_RUNNING_TASKS
4242

4343

4444
@pytask.mark.skipif(NO_LONG_RUNNING_TASKS, reason="Skip long-running tasks.")
45-
def task_that_takes_really_long_to_run(path: Path = Path("time_intensive_product.pkl")):
46-
...
45+
def task_that_takes_really_long_to_run(
46+
path: Path = Path("time_intensive_product.pkl"),
47+
): ...
4748
```
4849

4950
## Further reading

docs/source/tutorials/write_a_task.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,14 @@ from pytask import task
136136

137137

138138
@task
139-
def create_random_data():
140-
...
139+
def create_random_data(): ...
141140

142141

143142
# The id will be ".../task_data_preparation.py::create_data".
144143

145144

146145
@task(name="create_data")
147-
def create_random_data():
148-
...
146+
def create_random_data(): ...
149147
```
150148

151149
```{warning}

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ name = "Tobias Raabe"
5353
5454

5555
[project.optional-dependencies]
56-
all = ['universal-pathlib; python_version<"3.12"']
56+
all = ['universal-pathlib<0.2; python_version<"3.12"']
5757
docs = [
5858
"furo",
5959
"ipython",

src/_pytask/collect.py

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from _pytask.console import get_file
2222
from _pytask.exceptions import CollectionError
2323
from _pytask.exceptions import NodeNotCollectedError
24+
from _pytask.mark import MarkGenerator
2425
from _pytask.mark_utils import get_all_marks
2526
from _pytask.mark_utils import has_mark
2627
from _pytask.node_protocols import PNode
@@ -235,6 +236,10 @@ def _is_filtered_object(obj: Any) -> bool:
235236
See :issue:`507`.
236237
237238
"""
239+
# Filter :class:`pytask.mark.MarkGenerator` which can raise errors on some marks.
240+
if isinstance(obj, MarkGenerator):
241+
return True
242+
238243
# Filter :class:`pytask.Task` and :class:`pytask.TaskWithoutPath` objects.
239244
if isinstance(obj, PTask) and inspect.isclass(obj):
240245
return True

tests/test_collect.py

+1
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ def __getattr__(self, name):
692692

693693
result = runner.invoke(cli, [tmp_path.as_posix()])
694694
assert result.exit_code == ExitCode.OK
695+
assert "attr_that_definitely_does_not_exist" not in result.output
695696

696697

697698
@pytest.mark.end_to_end()

0 commit comments

Comments
 (0)