Skip to content
Draft
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
42 changes: 39 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ function signature as explained in this
### Accessing dependencies and products in the script

Dependencies and products registered in the task function signature are used by pytask
to order tasks and track whether they are up-to-date. They are not automatically passed
to the Stata script. Use the `options` argument of the decorator to pass paths or other
values as command line arguments to your Stata executable.
to order tasks and track whether they are up-to-date. If `options` is not used,
pytask-stata writes all dependencies and products from the task function signature to a
YAML file and passes the path to this file as the first command line argument to the
do-file.

#### Command Line Arguments

Use the `options` argument of the decorator to keep the legacy interface and pass paths
or other values as command line arguments to your Stata executable.

For example, pass the path of the product with

Expand Down Expand Up @@ -112,6 +118,36 @@ def task_run_do_file(produces: Path = BLD / "auto.dta"):
pass
```

#### YAML Configuration Files

By default, pytask-stata serializes all task keyword arguments and passes the path to
the generated YAML file as the first argument to the do-file. To read the file inside
Stata, install the user-written `yaml` package.

```stata
ssc install yaml
```

Then read the configuration file in the Stata task.

```python
@mark.stata(script=Path("script.do"))
def task_run_do_file(produces: Path = Path("auto.dta")):
pass
```

```do
args config
yaml read using "`config'", locals replace

sysuse auto, clear
save "`r(yaml_produces)'"
```

Do not combine both interfaces. If `options` is supplied, pytask-stata assumes the
do-file receives all required values through command line arguments and does not create
a YAML configuration file.

### Repeating tasks with different scripts or inputs

You can also parametrize the execution of scripts, meaning executing multiple do-files
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test-ci:

# Run type checking
typing:
uv run --group typing --group test --isolated ty check
uv run --group typing --group test --group test-mock-stata --isolated ty check

# Run linting and formatting
lint:
Expand Down
Loading
Loading