Skip to content

Commit 6f2a3d2

Browse files
authored
Align pytask-stata with pytask v0.2. (#22)
1 parent 8d54085 commit 6f2a3d2

28 files changed

+825
-705
lines changed

.coveragerc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[report]
2+
exclude_lines =
3+
pragma: no cover
4+
if TYPE_CHECKING.*:
5+
\.\.\.

.github/pull_request_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Provide a description and/or bullet points to describe the changes in this PR.
66

77
- [ ] Reference issues which can be closed due to this PR with "Closes #x".
88
- [ ] Review whether the documentation needs to be updated.
9-
- [ ] Document PR in docs/changes.rst.
9+
- [ ] Document PR in CHANGES.md.

.github/workflows/main.yml

-9
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,6 @@ jobs:
4848
shell: bash -l {0}
4949
run: bash <(curl -s https://codecov.io/bash) -F unit -c
5050

51-
# - name: Run integration tests.
52-
# shell: bash -l {0}
53-
# run: tox -e pytest -- -m integration --cov=./ --cov-report=xml -n auto
54-
55-
# - name: Upload coverage reports of integration tests.
56-
# if: runner.os == 'Linux' && matrix.python-version == '3.8'
57-
# shell: bash -l {0}
58-
# run: bash <(curl -s https://codecov.io/bash) -F integration -c
59-
6051
- name: Run end-to-end tests.
6152
shell: bash -l {0}
6253
run: tox -e pytest -- -m end_to_end --cov=./ --cov-report=xml -n auto

.pre-commit-config.yaml

+2-13
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ repos:
2323
- id: python-no-eval
2424
- id: python-no-log-warn
2525
- id: python-use-type-annotations
26-
- id: rst-backticks
27-
- id: rst-directive-colons
28-
- id: rst-inline-touching-normal
2926
- id: text-unicode-replacement-char
3027
- repo: https://github.com/asottile/pyupgrade
3128
rev: v2.32.0
@@ -45,11 +42,6 @@ repos:
4542
rev: 22.3.0
4643
hooks:
4744
- id: black
48-
- repo: https://github.com/asottile/blacken-docs
49-
rev: v1.12.1
50-
hooks:
51-
- id: blacken-docs
52-
additional_dependencies: [black]
5345
- repo: https://github.com/PyCQA/flake8
5446
rev: 4.0.1
5547
hooks:
@@ -71,10 +63,6 @@ repos:
7163
pydocstyle,
7264
Pygments,
7365
]
74-
- repo: https://github.com/PyCQA/doc8
75-
rev: 0.11.1
76-
hooks:
77-
- id: doc8
7866
- repo: https://github.com/econchick/interrogate
7967
rev: 1.5.0
8068
hooks:
@@ -84,11 +72,12 @@ repos:
8472
rev: v2.1.0
8573
hooks:
8674
- id: codespell
87-
args: [-L unparseable]
8875
- repo: https://github.com/mgedmin/check-manifest
8976
rev: "0.48"
9077
hooks:
9178
- id: check-manifest
79+
args: [--no-build-isolation]
80+
additional_dependencies: [setuptools-scm, toml]
9281
- repo: meta
9382
hooks:
9483
- id: check-hooks-apply

CHANGES.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Changes
2+
3+
This is a record of all past pytask-stata releases and what went into
4+
them in reverse chronological order. Releases follow [semantic
5+
versioning](https://semver.org/) and all releases are available on
6+
[PyPI](https://pypi.org/project/pytask-stata) and
7+
[Anaconda.org](https://anaconda.org/conda-forge/pytask-stata).
8+
9+
## 0.2.0 - 2022-xx-xx
10+
11+
- {pull}`20` removes an unnecessary hook implementation.
12+
13+
## 0.1.2 - 2022-02-08
14+
15+
- {pull}`19` fixes the minimum python and
16+
pytask version.
17+
18+
## 0.1.1 - 2022-02-07
19+
20+
- {pull}`16` skips concurrent CI builds.
21+
- {pull}`17` deprecates Python 3.6 and adds
22+
support for Python 3.10.
23+
24+
## 0.1.0 - 2021-07-21
25+
26+
- {pull}`11` fixes the `README.rst`.
27+
- {pull}`13` replaces versioneer with
28+
setuptools-scm.
29+
- {pull}`14` fixes tests and aligns
30+
pytask-stata with pytask v0.1.0.
31+
32+
## 0.0.6 - 2021-03-05
33+
34+
- {pull}`10` fixes the version of the package.
35+
36+
## 0.0.5 - 2021-03-04
37+
38+
- {pull}`7` fix some post-release issues.
39+
- {pull}`9` adds dependencies to `setup.py`.
40+
41+
## 0.0.4 - 2021-02-25
42+
43+
- {pull}`6` prepares pytask-stata to be
44+
published on PyPI, adds versioneer and more.
45+
46+
## 0.0.3 - 2021-01-16
47+
48+
- {pull}`4` removes log file handling on UNIX
49+
and raises an error if run in parallel.
50+
51+
## 0.0.2 - 2020-10-30
52+
53+
- {pull}`1` makes pytask-stata work with pytask
54+
v0.0.9.
55+
56+
## 0.0.1 - 2020-10-04
57+
58+
- Release v0.0.1.

CHANGES.rst

-70
This file was deleted.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2020-2021 Tobias Raabe
1+
Copyright 2020 Tobias Raabe
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this
44
software and associated documentation files (the "Software"), to deal in the Software

MANIFEST.in

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
prune .conda
21
prune tests
32

4-
exclude *.rst
3+
exclude .coveragerc
4+
exclude *.md
55
exclude *.yml
66
exclude *.yaml
77
exclude tox.ini
88

9-
include README.rst
9+
include README.md
1010
include LICENSE
11-
include versioneer.py
12-
include src/pytask_stata/_version.py

README.md

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# pytask-stata
2+
3+
[![PyPI](https://img.shields.io/pypi/v/pytask-stata?color=blue)](https://pypi.org/project/pytask-stata)
4+
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytask-stata)](https://pypi.org/project/pytask-stata)
5+
[![image](https://img.shields.io/conda/vn/conda-forge/pytask-stata.svg)](https://anaconda.org/conda-forge/pytask-stata)
6+
[![image](https://img.shields.io/conda/pn/conda-forge/pytask-stata.svg)](https://anaconda.org/conda-forge/pytask-stata)
7+
[![PyPI - License](https://img.shields.io/pypi/l/pytask-stata)](https://pypi.org/project/pytask-stata)
8+
[![image](https://img.shields.io/github/workflow/status/pytask-dev/pytask-stata/main/main)](https://github.com/pytask-dev/pytask-stata/actions?query=branch%3Amain)
9+
[![image](https://codecov.io/gh/pytask-dev/pytask-stata/branch/main/graph/badge.svg)](https://codecov.io/gh/pytask-dev/pytask-stata)
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+
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
12+
13+
------------------------------------------------------------------------
14+
15+
Run Stata\'s do-files with pytask.
16+
17+
## Installation
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
23+
24+
``` console
25+
$ pip install pytask-stata
26+
27+
# or
28+
29+
$ conda install -c conda-forge pytask-stata
30+
```
31+
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.
35+
36+
## Usage
37+
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.
42+
43+
Here is an example where you want to run `script.do`.
44+
45+
``` python
46+
import pytask
47+
48+
49+
@pytask.mark.stata(script="script.do")
50+
@pytask.mark.produces("auto.dta")
51+
def task_run_do_file():
52+
pass
53+
```
54+
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.
59+
60+
### Dependencies and Products
61+
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
65+
[tutorial](https://pytask-dev.readthedocs.io/en/stable/tutorials/defining_dependencies_products.html).
66+
67+
### Accessing dependencies and products in the script
68+
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
71+
72+
``` python
73+
@pytask.mark.stata(script="script.do", options="auto.dta")
74+
@pytask.mark.produces("auto.dta")
75+
def task_run_do_file():
76+
pass
77+
```
78+
79+
And in your `script.do`, you can intercept the value with
80+
81+
``` do
82+
* Intercept command line argument and save to macro named 'produces'.
83+
args produces
84+
85+
sysuse auto, clear
86+
save "`produces'"
87+
```
88+
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.
92+
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.
95+
96+
``` python
97+
# Absolute path to the build directory.
98+
from src.config import BLD
99+
100+
101+
@pytask.mark.stata(script="script.do", options=BLD / "auto.dta")
102+
@pytask.mark.produces(BLD / "auto.dta")
103+
def task_run_do_file():
104+
pass
105+
```
106+
107+
### Repeating tasks with different scripts or inputs
108+
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.
112+
113+
The following task executes two do-files which produce different
114+
outputs.
115+
116+
``` python
117+
for i in range(2):
118+
119+
@pytask.mark.task
120+
@pytask.mark.stata(script=f"script_{i}.do", options=f"{i}.dta")
121+
@pytask.mark.produces(f"{i}.dta")
122+
def task_execute_do_file():
123+
pass
124+
```
125+
126+
## Configuration
127+
128+
pytask-stata can be configured with the following options.
129+
130+
*`stata_keep_log`*
131+
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
135+
136+
```toml
137+
[tool.pytask.ini_options]
138+
stata_keep_log = true
139+
```
140+
141+
The option is also available in the command line interface via the
142+
`--stata-keep-log` flag.
143+
144+
145+
*`stata_check_log_lines`*
146+
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
151+
152+
```toml
153+
[tool.pytask.ini_options]
154+
stata_check_log_lines = 10
155+
```
156+
157+
and here via the command line interface
158+
159+
``` console
160+
$ pytask build --stata-check-log-lines 10
161+
```
162+
163+
## Changes
164+
165+
Consult the [release notes](CHANGES.md) to find out about what is new.

0 commit comments

Comments
 (0)