Skip to content

Commit 7976315

Browse files
authored
Deprecate INI configuration. (#49)
1 parent 008fc55 commit 7976315

File tree

7 files changed

+10
-92
lines changed

7 files changed

+10
-92
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ releases are available on [Anaconda.org](https://anaconda.org/conda-forge/pytask
66

77
## 0.3.0 - 2022-12-xx
88

9+
- {pull}`49` removes support for INI configurations.
910
- {pull}`50` removes the deprecation message and related code to the old API.
1011

1112
## 0.2.1 - 2022-04-19

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![image](https://img.shields.io/conda/vn/conda-forge/pytask-latex.svg)](https://anaconda.org/conda-forge/pytask-latex)
66
[![image](https://img.shields.io/conda/pn/conda-forge/pytask-latex.svg)](https://anaconda.org/conda-forge/pytask-latex)
77
[![PyPI - License](https://img.shields.io/pypi/l/pytask-latex)](https://pypi.org/project/pytask-latex)
8-
[![image](https://img.shields.io/github/workflow/status/pytask-dev/pytask-latex/main/main)](https://github.com/pytask-dev/pytask-latex/actions?query=branch%3Amain)
8+
[![image](https://img.shields.io/github/actions/workflow/status/pytask-dev/pytask-latex/main.yml?branch=main)](https://github.com/pytask-dev/pytask-latex/actions?query=branch%3Amain)
99
[![image](https://codecov.io/gh/pytask-dev/pytask-latex/branch/main/graph/badge.svg)](https://codecov.io/gh/pytask-dev/pytask-latex)
1010
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/pytask-dev/pytask-latex/main.svg)](https://results.pre-commit.ci/latest/github/pytask-dev/pytask-latex/main)
1111
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies:
1111
- toml
1212

1313
# Package dependencies
14-
- pytask >= 0.2
14+
- pytask >= 0.3
1515
- pytask-parallel >= 0.1
1616
- latex-dependency-scanner >=0.1.1
1717
- pybaum >=0.1.1

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ install_requires =
2727
click
2828
latex-dependency-scanner>=0.1.1
2929
pybaum>=0.1.1
30-
pytask>=0.2
30+
pytask>=0.3
3131
python_requires = >=3.7
3232
include_package_data = True
3333
package_dir = =src

src/pytask_latex/config.py

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,12 @@
22
from __future__ import annotations
33

44
from typing import Any
5-
from typing import Callable
65

76
from pytask import hookimpl
87

98

109
@hookimpl
11-
def pytask_parse_config(config, config_from_file):
10+
def pytask_parse_config(config: dict[str, Any]) -> None:
1211
"""Register the latex marker in the configuration."""
1312
config["markers"]["latex"] = "Tasks which compile LaTeX documents."
14-
config["infer_latex_dependencies"] = _get_first_non_none_value(
15-
config_from_file,
16-
key="infer_latex_dependencies",
17-
callback=_convert_truthy_or_falsy_to_bool,
18-
default=True,
19-
)
20-
21-
22-
def _convert_truthy_or_falsy_to_bool(x: bool | str | None) -> bool:
23-
"""Convert truthy or falsy value in .ini to Python boolean."""
24-
if x in [True, "True", "true", "1"]:
25-
out = True
26-
elif x in [False, "False", "false", "0"]:
27-
out = False
28-
elif x in [None, "None", "none"]:
29-
out = None
30-
else:
31-
raise ValueError(
32-
f"Input {x!r} is neither truthy (True, true, 1) or falsy (False, false, 0)."
33-
)
34-
return out
35-
36-
37-
def _get_first_non_none_value(
38-
*configs: dict[str, Any],
39-
key: str,
40-
default: Any | None = None,
41-
callback: Callable[..., Any] | None = None,
42-
) -> Any:
43-
"""Get the first non-None value for a key from a list of dictionaries.
44-
45-
This function allows to prioritize information from many configurations by changing
46-
the order of the inputs while also providing a default.
47-
48-
Examples
49-
--------
50-
>>> _get_first_non_none_value({"a": None}, {"a": 1}, key="a")
51-
1
52-
>>> _get_first_non_none_value({"a": None}, {"a": None}, key="a", default="default")
53-
'default'
54-
>>> _get_first_non_none_value({}, {}, key="a", default="default")
55-
'default'
56-
>>> _get_first_non_none_value({"a": None}, {"a": "b"}, key="a")
57-
'b'
58-
59-
"""
60-
callback = (lambda x: x) if callback is None else callback # noqa: E731
61-
processed_values = (callback(config.get(key)) for config in configs)
62-
return next((value for value in processed_values if value is not None), default)
13+
config["infer_latex_dependencies"] = config.get("infer_latex_dependencies", True)

tests/test_config.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,10 @@
11
from __future__ import annotations
22

3-
from contextlib import ExitStack as does_not_raise # noqa: N813
4-
53
import pytest
64
from pytask import main
7-
from pytask_latex.config import _convert_truthy_or_falsy_to_bool
85

96

107
@pytest.mark.end_to_end
118
def test_marker_is_configured(tmp_path):
129
session = main({"paths": tmp_path})
1310
assert "latex" in session.config["markers"]
14-
15-
16-
@pytest.mark.unit
17-
@pytest.mark.parametrize(
18-
"value, expectation, expected",
19-
[
20-
(True, does_not_raise(), True),
21-
("True", does_not_raise(), True),
22-
("true", does_not_raise(), True),
23-
("1", does_not_raise(), True),
24-
(False, does_not_raise(), False),
25-
("False", does_not_raise(), False),
26-
("false", does_not_raise(), False),
27-
("0", does_not_raise(), False),
28-
(None, does_not_raise(), None),
29-
("None", does_not_raise(), None),
30-
("none", does_not_raise(), None),
31-
("asklds", pytest.raises(ValueError, match="Input"), None),
32-
],
33-
)
34-
def test_convert_truthy_or_falsy_to_bool(value, expectation, expected):
35-
with expectation:
36-
result = _convert_truthy_or_falsy_to_bool(value)
37-
assert result == expected

tests/test_latex_dependency_scanner.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,7 @@
1313
@skip_on_github_actions_with_win
1414
@pytest.mark.end_to_end
1515
@pytest.mark.parametrize("infer_dependencies", ["true", "false"])
16-
@pytest.mark.parametrize(
17-
"config_file, content",
18-
[
19-
("pytask.ini", "[pytask]\ninfer_latex_dependencies = {}"),
20-
("pyproject.toml", "[tool.pytask.ini_options]\ninfer_latex_dependencies = {}"),
21-
],
22-
)
23-
def test_infer_dependencies_from_task(
24-
tmp_path, infer_dependencies, config_file, content
25-
):
16+
def test_infer_dependencies_from_task(tmp_path, infer_dependencies):
2617
task_source = """
2718
import pytask
2819
@@ -41,7 +32,9 @@ def task_compile_document():
4132
tmp_path.joinpath("document.tex").write_text(textwrap.dedent(latex_source))
4233
tmp_path.joinpath("sub_document.tex").write_text("Lorem ipsum.")
4334

44-
tmp_path.joinpath(config_file).write_text(content.format(infer_dependencies))
35+
tmp_path.joinpath("pyproject.toml").write_text(
36+
f"[tool.pytask.ini_options]\ninfer_latex_dependencies = {infer_dependencies}"
37+
)
4538

4639
session = main({"paths": tmp_path})
4740
assert session.exit_code == ExitCode.OK

0 commit comments

Comments
 (0)