Skip to content

Commit b17e689

Browse files
authored
Defer latexmk check after skips. (#83)
1 parent de25afb commit b17e689

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ releases are available on [Anaconda.org](https://anaconda.org/conda-forge/pytask
99
- {pull}`75` adds rye.
1010
- {pull}`81` adds support for Python 3.13 and drops support for Python 3.8.
1111
- {pull}`82` remove setup with tox-uv.
12+
- {pull}`83` defers latexmk check after the evaluation of skips.
1213

1314
## 0.4.2 - 2023-11-30
1415

src/pytask_latex/execute.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
from pytask import hookimpl
1010

1111

12-
@hookimpl
12+
@hookimpl(trylast=True)
1313
def pytask_execute_task_setup(task: PTask) -> None:
1414
"""Check that latexmk is found on the PATH if a LaTeX task should be executed."""
15+
_rich_traceback_omit = True
1516
if has_mark(task, "latex") and shutil.which("latexmk") is None:
1617
msg = (
1718
"latexmk is needed to compile LaTeX documents, but it is not found on "

tests/test_execute.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77
from pytask import ExitCode
88
from pytask import Mark
9+
from pytask import Skipped
910
from pytask import Task
1011
from pytask import build
1112
from pytask import cli
@@ -156,7 +157,6 @@ def task_compile_document():
156157
assert result.exit_code == ExitCode.OK
157158

158159

159-
@needs_latexmk
160160
@skip_on_github_actions_with_win
161161
@pytest.mark.end_to_end
162162
def test_raise_error_if_latexmk_is_not_found(tmp_path, monkeypatch):
@@ -190,6 +190,40 @@ def task_compile_document():
190190
assert isinstance(session.execution_reports[0].exc_info[1], RuntimeError)
191191

192192

193+
@skip_on_github_actions_with_win
194+
@pytest.mark.end_to_end
195+
def test_skip_even_if_latexmk_is_not_found(tmp_path, monkeypatch):
196+
task_source = """
197+
from pytask import mark
198+
199+
@mark.skip(reason="Skip it.")
200+
@mark.latex(script="document.tex", document="document.pdf")
201+
def task_compile_document():
202+
pass
203+
"""
204+
tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(task_source))
205+
206+
latex_source = r"""
207+
\documentclass{report}
208+
\begin{document}
209+
Ein Fuchs muss tun, was ein Fuchs tun muss. Luxus und Ruhm und rulen bis zum
210+
Schluss.
211+
\end{document}
212+
"""
213+
tmp_path.joinpath("document.tex").write_text(textwrap.dedent(latex_source))
214+
215+
# Hide latexmk if available.
216+
monkeypatch.setattr(
217+
"pytask_latex.execute.shutil.which",
218+
lambda x: None, # noqa: ARG005
219+
)
220+
221+
session = build(paths=tmp_path)
222+
223+
assert session.exit_code == ExitCode.OK
224+
assert isinstance(session.execution_reports[0].exc_info[1], Skipped)
225+
226+
193227
@needs_latexmk
194228
@skip_on_github_actions_with_win
195229
@pytest.mark.end_to_end

0 commit comments

Comments
 (0)