Skip to content

Defer latexmk check after skips. #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/pytask_latex/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
36 changes: 35 additions & 1 deletion tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
Loading