diff --git a/CHANGES.md b/CHANGES.md index 26f2a36..115c35d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ releases are available on [Anaconda.org](https://anaconda.org/conda-forge/pytask - {pull}`75` adds rye. - {pull}`81` adds support for Python 3.13 and drops support for Python 3.8. - {pull}`82` remove setup with tox-uv. +- {pull}`83` defers latexmk check after the evaluation of skips. ## 0.4.2 - 2023-11-30 diff --git a/src/pytask_latex/execute.py b/src/pytask_latex/execute.py index cb72bf7..b687cca 100644 --- a/src/pytask_latex/execute.py +++ b/src/pytask_latex/execute.py @@ -9,9 +9,10 @@ from pytask import hookimpl -@hookimpl +@hookimpl(trylast=True) def pytask_execute_task_setup(task: PTask) -> None: """Check that latexmk is found on the PATH if a LaTeX task should be executed.""" + _rich_traceback_omit = True if has_mark(task, "latex") and shutil.which("latexmk") is None: msg = ( "latexmk is needed to compile LaTeX documents, but it is not found on " diff --git a/tests/test_execute.py b/tests/test_execute.py index fe7a16e..fd3d54b 100644 --- a/tests/test_execute.py +++ b/tests/test_execute.py @@ -6,6 +6,7 @@ import pytest from pytask import ExitCode from pytask import Mark +from pytask import Skipped from pytask import Task from pytask import build from pytask import cli @@ -156,7 +157,6 @@ def task_compile_document(): assert result.exit_code == ExitCode.OK -@needs_latexmk @skip_on_github_actions_with_win @pytest.mark.end_to_end def test_raise_error_if_latexmk_is_not_found(tmp_path, monkeypatch): @@ -190,6 +190,40 @@ def task_compile_document(): assert isinstance(session.execution_reports[0].exc_info[1], RuntimeError) +@skip_on_github_actions_with_win +@pytest.mark.end_to_end +def test_skip_even_if_latexmk_is_not_found(tmp_path, monkeypatch): + task_source = """ + from pytask import mark + + @mark.skip(reason="Skip it.") + @mark.latex(script="document.tex", document="document.pdf") + def task_compile_document(): + pass + """ + tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(task_source)) + + latex_source = r""" + \documentclass{report} + \begin{document} + Ein Fuchs muss tun, was ein Fuchs tun muss. Luxus und Ruhm und rulen bis zum + Schluss. + \end{document} + """ + tmp_path.joinpath("document.tex").write_text(textwrap.dedent(latex_source)) + + # Hide latexmk if available. + monkeypatch.setattr( + "pytask_latex.execute.shutil.which", + lambda x: None, # noqa: ARG005 + ) + + session = build(paths=tmp_path) + + assert session.exit_code == ExitCode.OK + assert isinstance(session.execution_reports[0].exc_info[1], Skipped) + + @needs_latexmk @skip_on_github_actions_with_win @pytest.mark.end_to_end