10
10
[ ![ pre-commit.ci status] ( https://results.pre-commit.ci/badge/github/pytask-dev/pytask-stata/main.svg )] ( https://results.pre-commit.ci/latest/github/pytask-dev/pytask-stata/main )
11
11
[ ![ image] ( https://img.shields.io/badge/code%20style-black-000000.svg )] ( https://github.com/psf/black )
12
12
13
- ------------------------------------------------------------------------
13
+ ______________________________________________________________________
14
14
15
- Run Stata\ ' s do-files with pytask.
15
+ Run Stata's do-files with pytask.
16
16
17
17
## Installation
18
18
19
- pytask-stata is available on
20
- [ PyPI] ( https://pypi.org/project/pytask-stata ) and
21
- [ Anaconda.org] ( https://anaconda.org/conda-forge/pytask-stata ) . Install
22
- it with
19
+ pytask-stata is available on [ PyPI] ( https://pypi.org/project/pytask-stata ) and
20
+ [ Anaconda.org] ( https://anaconda.org/conda-forge/pytask-stata ) . Install it with
23
21
24
- ``` console
22
+ ``` console
25
23
$ pip install pytask-stata
26
24
27
25
# or
28
26
29
27
$ conda install -c conda-forge pytask-stata
30
28
```
31
29
32
- You also need to have Stata installed on your system and have the
33
- executable on your system\ ' s PATH. If you do not know how to do it,
34
- [ here ] ( https://superuser.com/a/284351 ) is an explanation.
30
+ You also need to have Stata installed on your system and have the executable on your
31
+ system's PATH. If you do not know how to do it, [ here ] ( https://superuser.com/a/284351 )
32
+ is an explanation.
35
33
36
34
## Usage
37
35
38
- Similarly to normal task functions which execute Python code, you define
39
- tasks to execute scripts written in Stata with Python functions. The
40
- difference is that the function body does not contain any logic, but the
41
- decorator tells pytask how to handle the task.
36
+ Similarly to normal task functions which execute Python code, you define tasks to
37
+ execute scripts written in Stata with Python functions. The difference is that the
38
+ function body does not contain any logic, but the decorator tells pytask how to handle
39
+ the task.
42
40
43
41
Here is an example where you want to run ` script.do ` .
44
42
45
- ``` python
43
+ ``` python
46
44
import pytask
47
45
48
46
@@ -52,24 +50,23 @@ def task_run_do_file():
52
50
pass
53
51
```
54
52
55
- When executing a do-file, the current working directory changes to the
56
- directory where the script is located. This allows you, for example, to
57
- reference every data set you want to read with a relative path from the
58
- script.
53
+ When executing a do-file, the current working directory changes to the directory where
54
+ the script is located. This allows you, for example, to reference every data set you
55
+ want to read with a relative path from the script.
59
56
60
57
### Dependencies and Products
61
58
62
- Dependencies and products can be added as with a normal pytask task
63
- using the ` @pytask.mark.depends_on ` and ` @pytask.mark.produces `
64
- decorators. which is explained in this
59
+ Dependencies and products can be added as with a normal pytask task using the
60
+ ` @pytask.mark.depends_on ` and ` @pytask.mark.produces ` decorators. which is explained in
61
+ this
65
62
[ tutorial] ( https://pytask-dev.readthedocs.io/en/stable/tutorials/defining_dependencies_products.html ) .
66
63
67
64
### Accessing dependencies and products in the script
68
65
69
- The decorator can be used to pass command line arguments to your Stata
70
- executable. For example, pass the path of the product with
66
+ The decorator can be used to pass command line arguments to your Stata executable. For
67
+ example, pass the path of the product with
71
68
72
- ``` python
69
+ ``` python
73
70
@pytask.mark.stata (script = " script.do" , options = " auto.dta" )
74
71
@pytask.mark.produces (" auto.dta" )
75
72
def task_run_do_file ():
@@ -78,22 +75,21 @@ def task_run_do_file():
78
75
79
76
And in your ` script.do ` , you can intercept the value with
80
77
81
- ``` do
78
+ ``` do
82
79
* Intercept command line argument and save to macro named 'produces'.
83
80
args produces
84
81
85
82
sysuse auto, clear
86
83
save "`produces'"
87
84
```
88
85
89
- The relative path inside the do-file works only because the pytask-stata
90
- switches the current working directory to the directory of the do-file
91
- before the task is executed.
86
+ The relative path inside the do-file works only because the pytask-stata switches the
87
+ current working directory to the directory of the do-file before the task is executed.
92
88
93
- To make the task independent from the current working directory, pass
94
- the full path as an command line argument. Here is an example.
89
+ To make the task independent from the current working directory, pass the full path as
90
+ an command line argument. Here is an example.
95
91
96
- ``` python
92
+ ``` python
97
93
# Absolute path to the build directory.
98
94
from src.config import BLD
99
95
@@ -106,14 +102,12 @@ def task_run_do_file():
106
102
107
103
### Repeating tasks with different scripts or inputs
108
104
109
- You can also parametrize the execution of scripts, meaning executing
110
- multiple do-files as well as passing different command line arguments to
111
- the same do-file.
105
+ You can also parametrize the execution of scripts, meaning executing multiple do-files
106
+ as well as passing different command line arguments to the same do-file.
112
107
113
- The following task executes two do-files which produce different
114
- outputs.
108
+ The following task executes two do-files which produce different outputs.
115
109
116
- ``` python
110
+ ``` python
117
111
for i in range (2 ):
118
112
119
113
@pytask.mark.task
@@ -129,25 +123,22 @@ pytask-stata can be configured with the following options.
129
123
130
124
* ` stata_keep_log ` *
131
125
132
- Use this option to keep the ` .log ` files which are produced for
133
- every task. This option is useful to debug Stata tasks. Set the
134
- option via the configuration file with
126
+ Use this option to keep the ` .log ` files which are produced for every task. This option
127
+ is useful to debug Stata tasks. Set the option via the configuration file with
135
128
136
129
``` toml
137
130
[tool .pytask .ini_options ]
138
131
stata_keep_log = true
139
132
```
140
133
141
- The option is also available in the command line interface via the
142
- ` --stata-keep-log ` flag.
143
-
134
+ The option is also available in the command line interface via the ` --stata-keep-log `
135
+ flag.
144
136
145
137
* ` stata_check_log_lines ` *
146
138
147
- Use this option to vary the number of lines in the log file which
148
- are checked for error codes. It also controls the number of lines
149
- displayed on errors. Use any integer greater than zero. Here is the
150
- entry in the configuration file
139
+ Use this option to vary the number of lines in the log file which are checked for error
140
+ codes. It also controls the number of lines displayed on errors. Use any integer greater
141
+ than zero. Here is the entry in the configuration file
151
142
152
143
``` toml
153
144
[tool .pytask .ini_options ]
@@ -156,7 +147,7 @@ stata_check_log_lines = 10
156
147
157
148
and here via the command line interface
158
149
159
- ``` console
150
+ ``` console
160
151
$ pytask build --stata-check-log-lines 10
161
152
```
162
153
0 commit comments