Skip to content

Commit

Permalink
Update example in README.md. (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasraabe committed Sep 29, 2023
1 parent f3193ae commit 132f515
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,26 @@ with `task_`. Here is an example.
```python
# Content of task_hello.py.

import pytask
from pathlib import Path

from pytask import Product
from typing_extensions import Annotated

@pytask.mark.produces("hello_earth.txt")
def task_hello_earth(produces):
produces.write_text("Hello, earth!")

def task_hello_earth(path: Annotated[Path, Product] = Path("hello_earth.txt")):
path.write_text("Hello, earth!")
```

Here are some details:
- The purpose of the task is to create the file `hello_earth.txt` and add some content.

- To tell pytask that `hello_earth.txt` is a product and not an input, use the `Product`
annotation.

(If you are not used to type annotations, do not worry. pytask also offers simpler
interfaces without type annotations.)

- Dependencies and products of a task are tracked via markers. Use
`@pytask.mark.depends_on` for dependencies and `@pytask.mark.produces` for products.
Values are strings or `pathlib.Path` and point to files on the disk.
- Use `produces` (and `depends_on`) as function arguments to access the paths inside the
function. pytask converts all paths to `pathlib.Path`'s. Here, `produces` holds the
path to `"hello_earth.txt"`.
- Since you pass a `pathlib.Path` to the function, pytask will check whether the file
exists after the function is executed.

To execute the task, enter `pytask` on the command-line

Expand Down
1 change: 1 addition & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
- {pull}`426` publishes the {mod}`pytask.tree_util` module.
- {pull}`427` fixes type annotations for {attr}`pytask.PTask.depends_on` and
{attr}`pytask.PTask.produces`.
- {pull}`428` updates the example in the readme.

## 0.3.2 - 2023-06-07

Expand Down

0 comments on commit 132f515

Please sign in to comment.