Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip collection of MarkGenerator when using from pytask import mark. #576

Merged
merged 8 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
releases are available on [PyPI](https://pypi.org/project/pytask) and
[Anaconda.org](https://anaconda.org/conda-forge/pytask).

## 0.4.6 - 2024-03-13

- {pull}`576` fixes accidentally collecting `pytask.MarkGenerator` when using
`from pytask import mark`.

## 0.4.5 - 2024-01-09

- {pull}`515` enables tests with graphviz in CI. Thanks to {user}`NickCrews`.
Expand Down
6 changes: 2 additions & 4 deletions docs/source/reference_guides/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ For example:

```python
@pytask.mark.timeout(10, "slow", method="thread")
def task_function():
...
def task_function(): ...
```

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

### Classes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ the {func}`@task <pytask.task>` decorator to pass keyword arguments to the task.
for id_, kwargs in ID_TO_KWARGS.items():

@task(id=id_, kwargs=kwargs)
def task_create_random_data(seed, produces):
...
def task_create_random_data(seed, produces): ...
```

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

@task(id=id_, kwargs=kwargs)
def task_create_random_data(i, produces):
...
def task_create_random_data(i, produces): ...
```

The {doc}`best-practices guide on parametrizations <../how_to_guides/bp_scaling_tasks>`
Expand Down
3 changes: 1 addition & 2 deletions docs/source/tutorials/selecting_tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ from pytask import task
for i in range(2):

@task
def task_parametrized(i=i):
...
def task_parametrized(i=i): ...
```

To run the task where `i = 1`, run this command.
Expand Down
5 changes: 3 additions & 2 deletions docs/source/tutorials/skipping_tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ from config import NO_LONG_RUNNING_TASKS


@pytask.mark.skipif(NO_LONG_RUNNING_TASKS, reason="Skip long-running tasks.")
def task_that_takes_really_long_to_run(path: Path = Path("time_intensive_product.pkl")):
...
def task_that_takes_really_long_to_run(
path: Path = Path("time_intensive_product.pkl"),
): ...
```

## Further reading
Expand Down
6 changes: 2 additions & 4 deletions docs/source/tutorials/write_a_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,14 @@ from pytask import task


@task
def create_random_data():
...
def create_random_data(): ...


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


@task(name="create_data")
def create_random_data():
...
def create_random_data(): ...
```

```{warning}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ name = "Tobias Raabe"
email = "raabe@posteo.de"

[project.optional-dependencies]
all = ['universal-pathlib; python_version<"3.12"']
all = ['universal-pathlib<0.2; python_version<"3.12"']
docs = [
"furo",
"ipython",
Expand Down
5 changes: 5 additions & 0 deletions src/_pytask/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from _pytask.console import get_file
from _pytask.exceptions import CollectionError
from _pytask.exceptions import NodeNotCollectedError
from _pytask.mark import MarkGenerator
from _pytask.mark_utils import get_all_marks
from _pytask.mark_utils import has_mark
from _pytask.node_protocols import PNode
Expand Down Expand Up @@ -235,6 +236,10 @@
See :issue:`507`.

"""
# Filter :class:`pytask.mark.MarkGenerator` which can raise errors on some marks.
if isinstance(obj, MarkGenerator):
return True

Check warning on line 241 in src/_pytask/collect.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/collect.py#L241

Added line #L241 was not covered by tests

# Filter :class:`pytask.Task` and :class:`pytask.TaskWithoutPath` objects.
if isinstance(obj, PTask) and inspect.isclass(obj):
return True
Expand Down
1 change: 1 addition & 0 deletions tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@

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

Check warning on line 695 in tests/test_collect.py

View check run for this annotation

Codecov / codecov/patch

tests/test_collect.py#L695

Added line #L695 was not covered by tests


@pytest.mark.end_to_end()
Expand Down
Loading