diff --git a/CHANGES.md b/CHANGES.md index 4bc9009..d003de2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ releases are available on [Anaconda.org](https://anaconda.org/conda-forge/pytask ## 0.3.0 - 2022-12-xx +- {pull}`49` removes support for INI configurations. - {pull}`50` removes the deprecation message and related code to the old API. ## 0.2.1 - 2022-04-19 diff --git a/README.md b/README.md index 6d72645..5affd71 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![image](https://img.shields.io/conda/vn/conda-forge/pytask-latex.svg)](https://anaconda.org/conda-forge/pytask-latex) [![image](https://img.shields.io/conda/pn/conda-forge/pytask-latex.svg)](https://anaconda.org/conda-forge/pytask-latex) [![PyPI - License](https://img.shields.io/pypi/l/pytask-latex)](https://pypi.org/project/pytask-latex) -[![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) +[![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) [![image](https://codecov.io/gh/pytask-dev/pytask-latex/branch/main/graph/badge.svg)](https://codecov.io/gh/pytask-dev/pytask-latex) [![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) [![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) diff --git a/environment.yml b/environment.yml index 8d14852..11da13d 100644 --- a/environment.yml +++ b/environment.yml @@ -11,7 +11,7 @@ dependencies: - toml # Package dependencies - - pytask >= 0.2 + - pytask >= 0.3 - pytask-parallel >= 0.1 - latex-dependency-scanner >=0.1.1 - pybaum >=0.1.1 diff --git a/setup.cfg b/setup.cfg index b1dbb30..063d8b5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,7 +27,7 @@ install_requires = click latex-dependency-scanner>=0.1.1 pybaum>=0.1.1 - pytask>=0.2 + pytask>=0.3 python_requires = >=3.7 include_package_data = True package_dir = =src diff --git a/src/pytask_latex/config.py b/src/pytask_latex/config.py index c3e964f..d78b012 100644 --- a/src/pytask_latex/config.py +++ b/src/pytask_latex/config.py @@ -2,61 +2,12 @@ from __future__ import annotations from typing import Any -from typing import Callable from pytask import hookimpl @hookimpl -def pytask_parse_config(config, config_from_file): +def pytask_parse_config(config: dict[str, Any]) -> None: """Register the latex marker in the configuration.""" config["markers"]["latex"] = "Tasks which compile LaTeX documents." - config["infer_latex_dependencies"] = _get_first_non_none_value( - config_from_file, - key="infer_latex_dependencies", - callback=_convert_truthy_or_falsy_to_bool, - default=True, - ) - - -def _convert_truthy_or_falsy_to_bool(x: bool | str | None) -> bool: - """Convert truthy or falsy value in .ini to Python boolean.""" - if x in [True, "True", "true", "1"]: - out = True - elif x in [False, "False", "false", "0"]: - out = False - elif x in [None, "None", "none"]: - out = None - else: - raise ValueError( - f"Input {x!r} is neither truthy (True, true, 1) or falsy (False, false, 0)." - ) - return out - - -def _get_first_non_none_value( - *configs: dict[str, Any], - key: str, - default: Any | None = None, - callback: Callable[..., Any] | None = None, -) -> Any: - """Get the first non-None value for a key from a list of dictionaries. - - This function allows to prioritize information from many configurations by changing - the order of the inputs while also providing a default. - - Examples - -------- - >>> _get_first_non_none_value({"a": None}, {"a": 1}, key="a") - 1 - >>> _get_first_non_none_value({"a": None}, {"a": None}, key="a", default="default") - 'default' - >>> _get_first_non_none_value({}, {}, key="a", default="default") - 'default' - >>> _get_first_non_none_value({"a": None}, {"a": "b"}, key="a") - 'b' - - """ - callback = (lambda x: x) if callback is None else callback # noqa: E731 - processed_values = (callback(config.get(key)) for config in configs) - return next((value for value in processed_values if value is not None), default) + config["infer_latex_dependencies"] = config.get("infer_latex_dependencies", True) diff --git a/tests/test_config.py b/tests/test_config.py index 3ed5b90..8dc4f93 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,37 +1,10 @@ from __future__ import annotations -from contextlib import ExitStack as does_not_raise # noqa: N813 - import pytest from pytask import main -from pytask_latex.config import _convert_truthy_or_falsy_to_bool @pytest.mark.end_to_end def test_marker_is_configured(tmp_path): session = main({"paths": tmp_path}) assert "latex" in session.config["markers"] - - -@pytest.mark.unit -@pytest.mark.parametrize( - "value, expectation, expected", - [ - (True, does_not_raise(), True), - ("True", does_not_raise(), True), - ("true", does_not_raise(), True), - ("1", does_not_raise(), True), - (False, does_not_raise(), False), - ("False", does_not_raise(), False), - ("false", does_not_raise(), False), - ("0", does_not_raise(), False), - (None, does_not_raise(), None), - ("None", does_not_raise(), None), - ("none", does_not_raise(), None), - ("asklds", pytest.raises(ValueError, match="Input"), None), - ], -) -def test_convert_truthy_or_falsy_to_bool(value, expectation, expected): - with expectation: - result = _convert_truthy_or_falsy_to_bool(value) - assert result == expected diff --git a/tests/test_latex_dependency_scanner.py b/tests/test_latex_dependency_scanner.py index 30682cb..7c8783a 100644 --- a/tests/test_latex_dependency_scanner.py +++ b/tests/test_latex_dependency_scanner.py @@ -13,16 +13,7 @@ @skip_on_github_actions_with_win @pytest.mark.end_to_end @pytest.mark.parametrize("infer_dependencies", ["true", "false"]) -@pytest.mark.parametrize( - "config_file, content", - [ - ("pytask.ini", "[pytask]\ninfer_latex_dependencies = {}"), - ("pyproject.toml", "[tool.pytask.ini_options]\ninfer_latex_dependencies = {}"), - ], -) -def test_infer_dependencies_from_task( - tmp_path, infer_dependencies, config_file, content -): +def test_infer_dependencies_from_task(tmp_path, infer_dependencies): task_source = """ import pytask @@ -41,7 +32,9 @@ def task_compile_document(): tmp_path.joinpath("document.tex").write_text(textwrap.dedent(latex_source)) tmp_path.joinpath("sub_document.tex").write_text("Lorem ipsum.") - tmp_path.joinpath(config_file).write_text(content.format(infer_dependencies)) + tmp_path.joinpath("pyproject.toml").write_text( + f"[tool.pytask.ini_options]\ninfer_latex_dependencies = {infer_dependencies}" + ) session = main({"paths": tmp_path}) assert session.exit_code == ExitCode.OK