Skip to content

Commit ff32f7c

Browse files
authored
Deprecate INI configurations and align with pytask v0.3. (#28)
1 parent 55321ad commit ff32f7c

12 files changed

+26
-198
lines changed

Diff for: .pre-commit-config.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
args: [--branch, main]
1717
- id: trailing-whitespace
1818
- repo: https://github.com/pre-commit/pygrep-hooks
19-
rev: v1.9.0 # Use the ref you want to point at
19+
rev: v1.9.0
2020
hooks:
2121
- id: python-check-blanket-noqa
2222
- id: python-check-mock-methods
@@ -100,7 +100,6 @@ repos:
100100
types-setuptools
101101
]
102102
pass_filenames: false
103-
language_version: "3.9"
104103
- repo: https://github.com/mgedmin/check-manifest
105104
rev: "0.48"
106105
hooks:

Diff for: CHANGES.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
55
releases are available on [PyPI](https://pypi.org/project/pytask-stata) and
66
[Anaconda.org](https://anaconda.org/conda-forge/pytask-stata).
77

8-
## 0.2.0 - 2022-xx-xx
8+
## 0.3.0 - 2023-xx-xx
9+
10+
- {pull}`25` adds docformatter.
11+
- {pull}`26` adds Python 3.11 to CI.
12+
- {pull}`28` aligns the package with pytask v0.3.
13+
14+
## 0.2.0 - 2022-04-16
915

1016
- {pull}`18` adds typing to the package.
1117
- {pull}`20` removes an unnecessary hook implementation.
18+
- {pull}`22` aligns the package with pytask v0.2.
1219

1320
## 0.1.2 - 2022-02-08
1421

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![image](https://img.shields.io/conda/vn/conda-forge/pytask-stata.svg)](https://anaconda.org/conda-forge/pytask-stata)
66
[![image](https://img.shields.io/conda/pn/conda-forge/pytask-stata.svg)](https://anaconda.org/conda-forge/pytask-stata)
77
[![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)
8+
[![image](https://img.shields.io/github/actions/workflow/status/pytask-dev/pytask-stata/main.yml?branch=main)](https://github.com/pytask-dev/pytask-stata/actions?query=branch%3Amain)
99
[![image](https://codecov.io/gh/pytask-dev/pytask-stata/branch/main/graph/badge.svg)](https://codecov.io/gh/pytask-dev/pytask-stata)
1010
[![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)
1111
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Diff for: environment.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ channels:
55
- nodefaults
66

77
dependencies:
8-
- python >3.7
8+
- python >=3.7
99
- pip
1010
- setuptools_scm
1111
- toml
1212

1313
# Package dependencies
14-
- pytask >=0.2
15-
- pytask-parallel >=0.2
14+
- pytask >=0.3
15+
- pytask-parallel >=0.3
1616

1717
# Misc
1818
- black
1919
- pre-commit
2020
- pytest-cov
2121
- pytest-xdist
2222
- tox-conda
23+
24+
- pip:
25+
- -e .

Diff for: setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ project_urls =
2929
packages = find:
3030
install_requires =
3131
click
32-
pytask>=0.2
32+
pytask>=0.3
3333
python_requires = >=3.7
3434
include_package_data = True
3535
package_dir = =src

Diff for: src/pytask_stata/cli.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,17 @@ def pytask_extend_command_line_interface(cli: click.Group) -> None:
1111
additional_parameters = [
1212
click.Option(
1313
["--stata-keep-log"],
14-
help=(
15-
"Do not remove the log files produced while running do-files. "
16-
"[default: False]"
17-
),
14+
help="Do not remove the log files produced while running do-files.",
1815
is_flag=True,
19-
default=None,
2016
),
2117
click.Option(
2218
["--stata-check-log-lines"],
2319
help=(
2420
"Number of lines of the log file to consider when searching for "
25-
"non-zero exit codes. [default: 10]"
21+
"non-zero exit codes."
2622
),
27-
type=int,
28-
default=None,
23+
type=click.IntRange(min=1),
24+
default=10,
2925
),
3026
]
3127
cli.commands["build"].params.extend(additional_parameters)

Diff for: src/pytask_stata/collect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def pytask_collect_task(
102102

103103

104104
def _parse_stata_mark(mark: Mark) -> Mark:
105-
"""Parse a Julia mark."""
105+
"""Parse a Stata mark."""
106106
script, options = stata(**mark.kwargs)
107107

108108
parsed_kwargs = {}

Diff for: src/pytask_stata/config.py

+2-85
Original file line numberDiff line numberDiff line change
@@ -4,102 +4,19 @@
44
import shutil
55
import sys
66
from typing import Any
7-
from typing import Callable
87

98
from pytask import hookimpl
109
from pytask_stata.shared import STATA_COMMANDS
1110

1211

1312
@hookimpl
14-
def pytask_parse_config(
15-
config: dict[str, Any],
16-
config_from_cli: dict[str, Any],
17-
config_from_file: dict[str, Any],
18-
) -> None:
13+
def pytask_parse_config(config: dict[str, Any]) -> None:
1914
"""Register the r marker."""
2015
config["markers"]["stata"] = "Tasks which are executed with Stata."
2116
config["platform"] = sys.platform
2217

23-
if config_from_file.get("stata"):
24-
config["stata"] = config_from_file["stata"]
25-
else:
18+
if not config.get("stata"):
2619
config["stata"] = next(
2720
(executable for executable in STATA_COMMANDS if shutil.which(executable)),
2821
None,
2922
)
30-
31-
config["stata_keep_log"] = _get_first_non_none_value(
32-
config_from_cli,
33-
config_from_file,
34-
key="stata_keep_log",
35-
callback=_convert_truthy_or_falsy_to_bool,
36-
default=False,
37-
)
38-
39-
config["stata_check_log_lines"] = _get_first_non_none_value(
40-
config_from_cli,
41-
config_from_file,
42-
key="stata_check_log_lines",
43-
callback=_nonnegative_nonzero_integer,
44-
default=10,
45-
)
46-
47-
48-
def _nonnegative_nonzero_integer(x: Any) -> int:
49-
"""Check for nonnegative and nonzero integer."""
50-
if x is not None:
51-
try:
52-
x = int(x)
53-
except ValueError:
54-
raise ValueError(
55-
"'stata_check_log_lines' must be a nonzero and nonnegative integer, "
56-
f"but it is '{x}'."
57-
)
58-
59-
if x <= 0:
60-
raise ValueError("'stata_check_log_lines' must be greater than zero.")
61-
62-
return x
63-
64-
65-
def _get_first_non_none_value(
66-
*configs: dict[str, Any],
67-
key: str,
68-
default: Any | None = None,
69-
callback: Callable[..., Any] | None = None,
70-
) -> Any:
71-
"""Get the first non-None value for a key from a list of dictionaries.
72-
73-
This function allows to prioritize information from many configurations by changing
74-
the order of the inputs while also providing a default.
75-
76-
Examples
77-
--------
78-
>>> _get_first_non_none_value({"a": None}, {"a": 1}, key="a")
79-
1
80-
>>> _get_first_non_none_value({"a": None}, {"a": None}, key="a", default="default")
81-
'default'
82-
>>> _get_first_non_none_value({}, {}, key="a", default="default")
83-
'default'
84-
>>> _get_first_non_none_value({"a": None}, {"a": "b"}, key="a")
85-
'b'
86-
87-
"""
88-
callback = (lambda x: x) if callback is None else callback # noqa: E731
89-
processed_values = (callback(config.get(key)) for config in configs)
90-
return next((value for value in processed_values if value is not None), default)
91-
92-
93-
def _convert_truthy_or_falsy_to_bool(x: bool | str | None) -> bool:
94-
"""Convert truthy or falsy value in .ini to Python boolean."""
95-
if x in [True, "True", "true", "1"]:
96-
out = True
97-
elif x in [False, "False", "false", "0"]:
98-
out = False
99-
elif x in [None, "None", "none"]:
100-
out = None
101-
else:
102-
raise ValueError(
103-
f"Input {x!r} is neither truthy (True, true, 1) or falsy (False, false, 0)."
104-
)
105-
return out

Diff for: src/pytask_stata/shared.py

+1-37
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,8 @@
3838
STATA_COMMANDS = []
3939

4040

41-
_ERROR_MSG = """The old syntax for @pytask.mark.stata was suddenly deprecated starting \
42-
with pytask-stata v0.2 to provide a better user experience. Thank you for your \
43-
understanding!
44-
45-
It is recommended to upgrade to the new syntax, so you enjoy all the benefits of v0.2 \
46-
of pytask and pytask-stata.
47-
48-
You can find a manual here: \
49-
https://github.com/pytask-dev/pytask-stata/blob/v0.2.0/README.md
50-
51-
Upgrading can be as easy as rewriting your current task from
52-
53-
@pytask.mark.stata(["--option", "path_to_dependency.txt"])
54-
@pytask.mark.depends_on("script.do")
55-
@pytask.mark.produces("out.csv")
56-
def task_r():
57-
...
58-
59-
to
60-
61-
@pytask.mark.stata(script="script.do", options="--option")
62-
@pytask.mark.depends_on("path_to_dependency.txt")
63-
@pytask.mark.produces("out.csv")
64-
def task_r():
65-
...
66-
67-
You can also fix the version of pytask and pytask-stata to <0.2, so you do not have to \
68-
to upgrade. At the same time, you will not enjoy the improvements released with \
69-
version v0.2 of pytask and pytask-stata.
70-
71-
"""
72-
73-
7441
def stata(
75-
*args: Any,
42+
*,
7643
script: str | Path | None = None,
7744
options: str | Iterable[str] | None = None,
7845
) -> tuple[str | Path | None, str | Iterable[str] | None]:
@@ -84,9 +51,6 @@ def stata(
8451
One or multiple command line options passed to Stata.
8552
8653
"""
87-
if args or script is None:
88-
raise RuntimeError(_ERROR_MSG)
89-
9054
options = [] if options is None else list(map(str, _to_list(options)))
9155
return script, options
9256

Diff for: tests/test_collect.py

-23
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@
1212
@pytest.mark.parametrize(
1313
"args, kwargs, expectation, expected",
1414
[
15-
((), {}, pytest.raises(RuntimeError, match="The old syntax"), None),
16-
(
17-
("-o"),
18-
{"script": "script.do"},
19-
pytest.raises(RuntimeError, match="The old syntax"),
20-
None,
21-
),
22-
(
23-
(),
24-
{"options": ("-o")},
25-
pytest.raises(RuntimeError, match="The old syntax"),
26-
None,
27-
),
2815
(
2916
(),
3017
{"script": "script.do", "options": "--option"},
@@ -49,16 +36,6 @@ def test_stata(args, kwargs, expectation, expected):
4936
@pytest.mark.parametrize(
5037
"mark, expectation, expected",
5138
[
52-
(
53-
Mark("stata", (), {}),
54-
pytest.raises(RuntimeError, match="The old syntax for @pytask.mark.stata"),
55-
Mark("stata", (), {"script": None, "options": []}),
56-
),
57-
(
58-
Mark("stata", ("-o"), {}),
59-
pytest.raises(RuntimeError, match="The old syntax for @pytask.mark.stata"),
60-
None,
61-
),
6239
(
6340
Mark("stata", (), {"script": "script.do"}),
6441
does_not_raise(),

Diff for: tests/test_config.py

-35
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import pytest
44
from pytask import main
5-
from pytask_stata.config import _nonnegative_nonzero_integer
65

76

87
@pytest.mark.end_to_end
@@ -11,37 +10,3 @@ def test_marker_is_configured(tmp_path):
1110

1211
assert "stata" in session.config
1312
assert "stata" in session.config["markers"]
14-
15-
16-
@pytest.mark.unit
17-
@pytest.mark.parametrize("x, expected", [(None, None), (1, 1), ("1", 1), (1.5, 1)])
18-
def test_nonnegative_nonzero_integer(x, expected):
19-
assert _nonnegative_nonzero_integer(x) == expected
20-
21-
22-
@pytest.mark.unit
23-
@pytest.mark.parametrize(
24-
"x, expectation",
25-
[
26-
(
27-
-1,
28-
pytest.raises(ValueError, match="'stata_check_log_lines' must be greater"),
29-
),
30-
(
31-
"-1",
32-
pytest.raises(ValueError, match="'stata_check_log_lines' must be greater"),
33-
),
34-
(0, pytest.raises(ValueError, match="'stata_check_log_lines' must be greater")),
35-
(
36-
"0",
37-
pytest.raises(ValueError, match="'stata_check_log_lines' must be greater"),
38-
),
39-
(
40-
"1.5",
41-
pytest.raises(ValueError, match="'stata_check_log_lines' must be a"),
42-
),
43-
],
44-
)
45-
def test_nonnegative_nonzero_integer_raises_error(x, expectation):
46-
with expectation:
47-
_nonnegative_nonzero_integer(x)

Diff for: tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ conda_channels =
1313
conda-forge
1414
nodefaults
1515
conda_deps =
16-
pytask >=0.2
16+
pytask >=0.3
1717
pytest
1818
pytest-cov
1919
pytest-xdist

0 commit comments

Comments
 (0)