From e145e93a924787111ea810a59cc47bc63fc2aefd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Jan 2023 20:37:31 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pygrep-hooks: v1.9.0 → v1.10.0](https://github.com/pre-commit/pygrep-hooks/compare/v1.9.0...v1.10.0) - [github.com/asottile/blacken-docs: v1.12.1 → 1.13.0](https://github.com/asottile/blacken-docs/compare/v1.12.1...1.13.0) - [github.com/charliermarsh/ruff-pre-commit: v0.0.215 → v0.0.223](https://github.com/charliermarsh/ruff-pre-commit/compare/v0.0.215...v0.0.223) - [github.com/dosisod/refurb: v1.9.1 → v1.10.0](https://github.com/dosisod/refurb/compare/v1.9.1...v1.10.0) --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8d4b16b..de507e5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: args: [--branch, main] - id: trailing-whitespace - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.9.0 # Use the ref you want to point at + rev: v1.10.0 # Use the ref you want to point at hooks: - id: python-check-blanket-noqa - id: python-check-mock-methods @@ -44,16 +44,16 @@ repos: hooks: - id: black - repo: https://github.com/asottile/blacken-docs - rev: v1.12.1 + rev: 1.13.0 hooks: - id: blacken-docs additional_dependencies: [black] - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.215 + rev: v0.0.223 hooks: - id: ruff - repo: https://github.com/dosisod/refurb - rev: v1.9.1 + rev: v1.10.0 hooks: - id: refurb args: [--ignore, FURB126] From 7227cde0a8582e8be153e1728d536cd28ad29068 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Jan 2023 20:40:22 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pytask_latex/collect.py | 22 +++++++++++----------- src/pytask_latex/compilation_steps.py | 4 ++-- src/pytask_latex/execute.py | 2 +- tests/conftest.py | 2 +- tests/test_execute.py | 8 ++++---- tests/test_latex_dependency_scanner.py | 2 +- tests/test_normal_execution_w_plugin.py | 2 +- tests/test_parallel.py | 4 ++-- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/pytask_latex/collect.py b/src/pytask_latex/collect.py index be2d52f..483aa78 100644 --- a/src/pytask_latex/collect.py +++ b/src/pytask_latex/collect.py @@ -74,7 +74,7 @@ def compile_latex_document( @hookimpl def pytask_collect_task( - session: Session, path: Path, name: str, obj: Any + session: Session, path: Path, name: str, obj: Any, ) -> Task | None: """Perform some checks.""" __tracebackhide__ = True @@ -89,7 +89,7 @@ def pytask_collect_task( if len(marks) > 1: raise ValueError( f"Task {name!r} has multiple @pytask.mark.latex marks, but only one is " - "allowed." + "allowed.", ) latex_mark = marks[0] script, document, compilation_steps = latex(**latex_mark.kwargs) @@ -115,10 +115,10 @@ def pytask_collect_task( ) script_node = session.hook.pytask_collect_node( - session=session, path=path, node=script + session=session, path=path, node=script, ) document_node = session.hook.pytask_collect_node( - session=session, path=path, node=document + session=session, path=path, node=document, ) if not ( @@ -126,7 +126,7 @@ def pytask_collect_task( ): raise ValueError( "The 'script' keyword of the @pytask.mark.latex decorator must point " - "to LaTeX file with the .tex suffix." + "to LaTeX file with the .tex suffix.", ) if not ( @@ -135,7 +135,7 @@ def pytask_collect_task( ): raise ValueError( "The 'document' keyword of the @pytask.mark.latex decorator must point " - "to a .pdf, .ps or .dvi file." + "to a .pdf, .ps or .dvi file.", ) if isinstance(task.depends_on, dict): @@ -195,7 +195,7 @@ def _add_latex_dependencies_retroactively(task: Task, session: Session) -> Task: # Collect new dependencies and add them to the task. collected_dependencies = tree_map( - lambda x: _collect_node(session, task.path, task.name, x), new_numbered_deps + lambda x: _collect_node(session, task.path, task.name, x), new_numbered_deps, ) task.depends_on["__scanned_dependencies"] = collected_dependencies @@ -231,7 +231,7 @@ def _copy_func(func: FunctionType) -> FunctionType: def _collect_node( - session: Session, path: Path, name: str, node: str | Path + session: Session, path: Path, name: str, node: str | Path, ) -> dict[str, MetaNode]: """Collect nodes for a task. @@ -258,19 +258,19 @@ def _collect_node( """ collected_node = session.hook.pytask_collect_node( - session=session, path=path, node=node + session=session, path=path, node=node, ) if collected_node is None: raise NodeNotCollectedError( f"{node!r} cannot be parsed as a dependency or product for task " - f"{name!r} in {path!r}." + f"{name!r} in {path!r}.", ) return collected_node def _parse_compilation_steps( - compilation_steps: str | Callable[..., Any] | Sequence[str | Callable[..., Any]] + compilation_steps: str | Callable[..., Any] | Sequence[str | Callable[..., Any]], ) -> list[Callable[..., Any]]: """Parse compilation steps.""" __tracebackhide__ = True diff --git a/src/pytask_latex/compilation_steps.py b/src/pytask_latex/compilation_steps.py index b6595d1..4f2fa5a 100644 --- a/src/pytask_latex/compilation_steps.py +++ b/src/pytask_latex/compilation_steps.py @@ -24,7 +24,7 @@ def compilation_step(path_to_tex: Path, path_to_document: Path): def latexmk( options: str | list[str] - | tuple[str, ...] = ("--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd") + | tuple[str, ...] = ("--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd"), ) -> Callable[..., Any]: """Compilation step that calls latexmk.""" options = [str(i) for i in to_list(options)] @@ -32,7 +32,7 @@ def latexmk( def run_latexmk(path_to_tex: Path, path_to_document: Path) -> None: job_name_opt = [f"--jobname={path_to_document.stem}"] out_dir_opt = [ - f"--output-directory={relative_to(path_to_tex, path_to_document.parent)}" + f"--output-directory={relative_to(path_to_tex, path_to_document.parent)}", ] cmd = ( ["latexmk", *options] diff --git a/src/pytask_latex/execute.py b/src/pytask_latex/execute.py index 7603bb1..c923322 100644 --- a/src/pytask_latex/execute.py +++ b/src/pytask_latex/execute.py @@ -14,5 +14,5 @@ def pytask_execute_task_setup(task: Task) -> None: if has_mark(task, "latex") and shutil.which("latexmk") is None: raise RuntimeError( "latexmk is needed to compile LaTeX documents, but it is not found on " - "your PATH." + "your PATH.", ) diff --git a/tests/conftest.py b/tests/conftest.py index 1ae27ba..71a9582 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,7 +14,7 @@ needs_latexmk = pytest.mark.skipif( - shutil.which("latexmk") is None, reason="latexmk needs to be installed." + shutil.which("latexmk") is None, reason="latexmk needs to be installed.", ) skip_on_github_actions_with_win = pytest.mark.skipif( diff --git a/tests/test_execute.py b/tests/test_execute.py index ce893bc..f6652fd 100644 --- a/tests/test_execute.py +++ b/tests/test_execute.py @@ -20,10 +20,10 @@ def test_pytask_execute_task_setup(monkeypatch): """Make sure that the task setup raises errors.""" # Act like latexmk is installed since we do not test this. monkeypatch.setattr( - "pytask_latex.execute.shutil.which", lambda x: None # noqa: ARG005 + "pytask_latex.execute.shutil.which", lambda x: None, # noqa: ARG005 ) task = Task( - base_name="example", path=Path(), function=None, markers=[Mark("latex", (), {})] + base_name="example", path=Path(), function=None, markers=[Mark("latex", (), {})], ) with pytest.raises(RuntimeError, match="latexmk is needed"): pytask_execute_task_setup(task) @@ -178,7 +178,7 @@ def task_compile_document(): # Hide latexmk if available. monkeypatch.setattr( - "pytask_latex.execute.shutil.which", lambda x: None # noqa: ARG005 + "pytask_latex.execute.shutil.which", lambda x: None, # noqa: ARG005 ) session = main({"paths": tmp_path}) @@ -500,7 +500,7 @@ def task_compile_document(): ], ) def test_compile_latex_document_w_unknown_compilation_step( - runner, tmp_path, step, message + runner, tmp_path, step, message, ): """Test simple compilation.""" task_source = f""" diff --git a/tests/test_latex_dependency_scanner.py b/tests/test_latex_dependency_scanner.py index 6a14990..da58f96 100644 --- a/tests/test_latex_dependency_scanner.py +++ b/tests/test_latex_dependency_scanner.py @@ -33,7 +33,7 @@ def task_compile_document(): tmp_path.joinpath("sub_document.tex").write_text("Lorem ipsum.") tmp_path.joinpath("pyproject.toml").write_text( - f"[tool.pytask.ini_options]\ninfer_latex_dependencies = {infer_dependencies}" + f"[tool.pytask.ini_options]\ninfer_latex_dependencies = {infer_dependencies}", ) session = main({"paths": tmp_path}) diff --git a/tests/test_normal_execution_w_plugin.py b/tests/test_normal_execution_w_plugin.py index 78d67cc..edb21ab 100644 --- a/tests/test_normal_execution_w_plugin.py +++ b/tests/test_normal_execution_w_plugin.py @@ -15,7 +15,7 @@ ) @pytest.mark.parametrize("products", [("out.txt",), ("out_1.txt", "out_2.txt")]) def test_execution_w_varying_dependencies_products( - runner, tmp_path, dependencies, products + runner, tmp_path, dependencies, products, ): source = f""" import pytask diff --git a/tests/test_parallel.py b/tests/test_parallel.py index 92bab10..75c1348 100644 --- a/tests/test_parallel.py +++ b/tests/test_parallel.py @@ -21,11 +21,11 @@ pytestmark = pytest.mark.skipif( - not _IS_PYTASK_PARALLEL_INSTALLED, reason="Tests require pytask-parallel." + not _IS_PYTASK_PARALLEL_INSTALLED, reason="Tests require pytask-parallel.", ) xfail_on_remote = pytest.mark.xfail( - condition=os.environ.get("CI") == "true", reason="Does not succeed on CI." + condition=os.environ.get("CI") == "true", reason="Does not succeed on CI.", ) From 79f323d27021fa8eb8f51ba23277775393fb308e Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Sat, 21 Jan 2023 13:55:17 +0100 Subject: [PATCH 3/3] Fix. --- pyproject.toml | 3 ++- src/pytask_latex/collect.py | 25 +++++++++++++------------ src/pytask_latex/compilation_steps.py | 4 ++-- src/pytask_latex/execute.py | 2 +- src/pytask_latex/parametrize.py | 2 +- tests/conftest.py | 2 +- tests/test_execute.py | 8 ++++---- tests/test_latex_dependency_scanner.py | 2 +- tests/test_normal_execution_w_plugin.py | 2 +- tests/test_parallel.py | 4 ++-- 10 files changed, 28 insertions(+), 26 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 91df5d9..27c35ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,11 +51,12 @@ extend-ignore = [ "EM", # flake8-errmsg "ANN401", # flake8-annotate typing.Any "PD", # pandas-vet + "COM812", # trailing comma missing, but black takes care of that ] [tool.ruff.per-file-ignores] -"tests/*" = ["D", "ANN"] +"tests/*" = ["D", "ANN", "PLR2004"] [tool.ruff.pydocstyle] diff --git a/src/pytask_latex/collect.py b/src/pytask_latex/collect.py index 483aa78..e87c14f 100644 --- a/src/pytask_latex/collect.py +++ b/src/pytask_latex/collect.py @@ -74,7 +74,7 @@ def compile_latex_document( @hookimpl def pytask_collect_task( - session: Session, path: Path, name: str, obj: Any, + session: Session, path: Path, name: str, obj: Any ) -> Task | None: """Perform some checks.""" __tracebackhide__ = True @@ -89,7 +89,7 @@ def pytask_collect_task( if len(marks) > 1: raise ValueError( f"Task {name!r} has multiple @pytask.mark.latex marks, but only one is " - "allowed.", + "allowed." ) latex_mark = marks[0] script, document, compilation_steps = latex(**latex_mark.kwargs) @@ -115,18 +115,19 @@ def pytask_collect_task( ) script_node = session.hook.pytask_collect_node( - session=session, path=path, node=script, + session=session, path=path, node=script ) document_node = session.hook.pytask_collect_node( - session=session, path=path, node=document, + session=session, path=path, node=document ) if not ( - isinstance(script_node, FilePathNode) and script_node.value.suffix == ".tex" + isinstance(script_node, FilePathNode) + and script_node.value.suffix == ".tex" # noqa: PLR2004 ): raise ValueError( "The 'script' keyword of the @pytask.mark.latex decorator must point " - "to LaTeX file with the .tex suffix.", + "to LaTeX file with the .tex suffix." ) if not ( @@ -135,7 +136,7 @@ def pytask_collect_task( ): raise ValueError( "The 'document' keyword of the @pytask.mark.latex decorator must point " - "to a .pdf, .ps or .dvi file.", + "to a .pdf, .ps or .dvi file." ) if isinstance(task.depends_on, dict): @@ -195,7 +196,7 @@ def _add_latex_dependencies_retroactively(task: Task, session: Session) -> Task: # Collect new dependencies and add them to the task. collected_dependencies = tree_map( - lambda x: _collect_node(session, task.path, task.name, x), new_numbered_deps, + lambda x: _collect_node(session, task.path, task.name, x), new_numbered_deps ) task.depends_on["__scanned_dependencies"] = collected_dependencies @@ -231,7 +232,7 @@ def _copy_func(func: FunctionType) -> FunctionType: def _collect_node( - session: Session, path: Path, name: str, node: str | Path, + session: Session, path: Path, name: str, node: str | Path ) -> dict[str, MetaNode]: """Collect nodes for a task. @@ -258,19 +259,19 @@ def _collect_node( """ collected_node = session.hook.pytask_collect_node( - session=session, path=path, node=node, + session=session, path=path, node=node ) if collected_node is None: raise NodeNotCollectedError( f"{node!r} cannot be parsed as a dependency or product for task " - f"{name!r} in {path!r}.", + f"{name!r} in {path!r}." ) return collected_node def _parse_compilation_steps( - compilation_steps: str | Callable[..., Any] | Sequence[str | Callable[..., Any]], + compilation_steps: str | Callable[..., Any] | Sequence[str | Callable[..., Any]] ) -> list[Callable[..., Any]]: """Parse compilation steps.""" __tracebackhide__ = True diff --git a/src/pytask_latex/compilation_steps.py b/src/pytask_latex/compilation_steps.py index 4f2fa5a..b6595d1 100644 --- a/src/pytask_latex/compilation_steps.py +++ b/src/pytask_latex/compilation_steps.py @@ -24,7 +24,7 @@ def compilation_step(path_to_tex: Path, path_to_document: Path): def latexmk( options: str | list[str] - | tuple[str, ...] = ("--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd"), + | tuple[str, ...] = ("--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd") ) -> Callable[..., Any]: """Compilation step that calls latexmk.""" options = [str(i) for i in to_list(options)] @@ -32,7 +32,7 @@ def latexmk( def run_latexmk(path_to_tex: Path, path_to_document: Path) -> None: job_name_opt = [f"--jobname={path_to_document.stem}"] out_dir_opt = [ - f"--output-directory={relative_to(path_to_tex, path_to_document.parent)}", + f"--output-directory={relative_to(path_to_tex, path_to_document.parent)}" ] cmd = ( ["latexmk", *options] diff --git a/src/pytask_latex/execute.py b/src/pytask_latex/execute.py index c923322..7603bb1 100644 --- a/src/pytask_latex/execute.py +++ b/src/pytask_latex/execute.py @@ -14,5 +14,5 @@ def pytask_execute_task_setup(task: Task) -> None: if has_mark(task, "latex") and shutil.which("latexmk") is None: raise RuntimeError( "latexmk is needed to compile LaTeX documents, but it is not found on " - "your PATH.", + "your PATH." ) diff --git a/src/pytask_latex/parametrize.py b/src/pytask_latex/parametrize.py index 6bd5266..a51a6f9 100644 --- a/src/pytask_latex/parametrize.py +++ b/src/pytask_latex/parametrize.py @@ -10,5 +10,5 @@ @hookimpl def pytask_parametrize_kwarg_to_marker(obj: Any, kwargs: dict[str, Any]) -> None: """Register kwargs as latex marker.""" - if callable(obj) and "latex" in kwargs: + if callable(obj) and "latex" in kwargs: # noqa: PLR2004 pytask.mark.latex(**kwargs.pop("latex"))(obj) diff --git a/tests/conftest.py b/tests/conftest.py index 71a9582..1ae27ba 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,7 +14,7 @@ needs_latexmk = pytest.mark.skipif( - shutil.which("latexmk") is None, reason="latexmk needs to be installed.", + shutil.which("latexmk") is None, reason="latexmk needs to be installed." ) skip_on_github_actions_with_win = pytest.mark.skipif( diff --git a/tests/test_execute.py b/tests/test_execute.py index f6652fd..ce893bc 100644 --- a/tests/test_execute.py +++ b/tests/test_execute.py @@ -20,10 +20,10 @@ def test_pytask_execute_task_setup(monkeypatch): """Make sure that the task setup raises errors.""" # Act like latexmk is installed since we do not test this. monkeypatch.setattr( - "pytask_latex.execute.shutil.which", lambda x: None, # noqa: ARG005 + "pytask_latex.execute.shutil.which", lambda x: None # noqa: ARG005 ) task = Task( - base_name="example", path=Path(), function=None, markers=[Mark("latex", (), {})], + base_name="example", path=Path(), function=None, markers=[Mark("latex", (), {})] ) with pytest.raises(RuntimeError, match="latexmk is needed"): pytask_execute_task_setup(task) @@ -178,7 +178,7 @@ def task_compile_document(): # Hide latexmk if available. monkeypatch.setattr( - "pytask_latex.execute.shutil.which", lambda x: None, # noqa: ARG005 + "pytask_latex.execute.shutil.which", lambda x: None # noqa: ARG005 ) session = main({"paths": tmp_path}) @@ -500,7 +500,7 @@ def task_compile_document(): ], ) def test_compile_latex_document_w_unknown_compilation_step( - runner, tmp_path, step, message, + runner, tmp_path, step, message ): """Test simple compilation.""" task_source = f""" diff --git a/tests/test_latex_dependency_scanner.py b/tests/test_latex_dependency_scanner.py index da58f96..6a14990 100644 --- a/tests/test_latex_dependency_scanner.py +++ b/tests/test_latex_dependency_scanner.py @@ -33,7 +33,7 @@ def task_compile_document(): tmp_path.joinpath("sub_document.tex").write_text("Lorem ipsum.") tmp_path.joinpath("pyproject.toml").write_text( - f"[tool.pytask.ini_options]\ninfer_latex_dependencies = {infer_dependencies}", + f"[tool.pytask.ini_options]\ninfer_latex_dependencies = {infer_dependencies}" ) session = main({"paths": tmp_path}) diff --git a/tests/test_normal_execution_w_plugin.py b/tests/test_normal_execution_w_plugin.py index edb21ab..78d67cc 100644 --- a/tests/test_normal_execution_w_plugin.py +++ b/tests/test_normal_execution_w_plugin.py @@ -15,7 +15,7 @@ ) @pytest.mark.parametrize("products", [("out.txt",), ("out_1.txt", "out_2.txt")]) def test_execution_w_varying_dependencies_products( - runner, tmp_path, dependencies, products, + runner, tmp_path, dependencies, products ): source = f""" import pytask diff --git a/tests/test_parallel.py b/tests/test_parallel.py index 75c1348..92bab10 100644 --- a/tests/test_parallel.py +++ b/tests/test_parallel.py @@ -21,11 +21,11 @@ pytestmark = pytest.mark.skipif( - not _IS_PYTASK_PARALLEL_INSTALLED, reason="Tests require pytask-parallel.", + not _IS_PYTASK_PARALLEL_INSTALLED, reason="Tests require pytask-parallel." ) xfail_on_remote = pytest.mark.xfail( - condition=os.environ.get("CI") == "true", reason="Does not succeed on CI.", + condition=os.environ.get("CI") == "true", reason="Does not succeed on CI." )