Skip to content

Deprecate the old API without compilation steps. #34

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 3 commits into from
Apr 15, 2022
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
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ all releases are available on `Anaconda.org
<https://anaconda.org/conda-forge/pytask-latex>`_.


0.2.0 - 2022-xx-xx
------------------

- :pull:`34` deprecates the old api.


0.1.2 - 2022-03-26
------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = MIT
license_file = LICENSE
platforms = any
classifiers =
Development Status :: 3 - Alpha
Development Status :: 4 - Beta
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Programming Language :: Python :: 3
Expand Down
50 changes: 11 additions & 39 deletions src/pytask_latex/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

import copy
import functools
import warnings
from subprocess import CalledProcessError
from typing import Any
from typing import Callable
from typing import Iterable
from typing import Sequence

import latex_dependency_scanner as lds
Expand All @@ -21,27 +19,7 @@
from pytask_latex.utils import to_list


_DEPRECATION_WARNING = """The old syntax for using @pytask.mark.latex is deprecated \
and will be removed in v0.2.0. To pass custom options to latexmk and the compilation \
process convert

@pytask.mark.latex(options)
def task_func():
...

to

from pytask_latex import compilation_steps as cs

@pytask.mark.latex(compilation_steps=cs.latexmk(options))
def task_func():
...

"""


def latex(
options: str | Iterable[str] | None = None,
*,
compilation_steps: str
| Callable[..., Any]
Expand All @@ -59,23 +37,17 @@ def latex(
"""
compilation_steps = ["latexmk"] if compilation_steps is None else compilation_steps

if options is not None:
warnings.warn(_DEPRECATION_WARNING, DeprecationWarning)
out = [cs.latexmk(options)]

else:
out = []
for step in to_list(compilation_steps):
if isinstance(step, str):
try:
parsed_step = getattr(cs, step)
except AttributeError:
raise ValueError(f"Compilation step {step!r} is unknown.")
out.append(parsed_step())
elif callable(step):
out.append(step)
else:
raise ValueError(f"Compilation step {step!r} is not a valid step.")
out = []
for step in to_list(compilation_steps):
if isinstance(step, str):
parsed_step = getattr(cs, step)
if parsed_step is None:
raise ValueError(f"Compilation step {step!r} is unknown.")
out.append(parsed_step())
elif callable(step):
out.append(step)
else:
raise ValueError(f"Compilation step {step!r} is not a valid step.")

return out

Expand Down
68 changes: 0 additions & 68 deletions tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,39 +249,6 @@ def task_compile_document():
def test_compile_latex_document_w_xelatex(runner, tmp_path):
task_source = """
import pytask

@pytask.mark.latex(
["--xelatex", "--interaction=nonstopmode", "--synctex=1", "--cd"]
)
@pytask.mark.depends_on("document.tex")
@pytask.mark.produces("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}
I got, I got, I got, I got loyalty, got royalty inside my DNA.
\end{document}
"""
tmp_path.joinpath("document.tex").write_text(textwrap.dedent(latex_source))

with pytest.warns(DeprecationWarning, match="The old syntax"):
result = runner.invoke(cli, [tmp_path.as_posix()])

assert result.exit_code == 0
assert tmp_path.joinpath("document.pdf").exists()


@needs_latexmk
@skip_on_github_actions_with_win
@pytest.mark.end_to_end
def test_compile_latex_document_w_xelatex_new_api(runner, tmp_path):
task_source = """
import pytask
from pytask_latex import compilation_steps

@pytask.mark.latex(
Expand Down Expand Up @@ -428,41 +395,6 @@ def test_compile_document_w_wrong_flag(tmp_path):
"""Test that wrong flags raise errors."""
tmp_path.joinpath("sub").mkdir(parents=True)

task_source = """
import pytask

@pytask.mark.latex(["--wrong-flag"])
@pytask.mark.depends_on("document.tex")
@pytask.mark.produces("out/document.pdf")
def task_compile_document():
pass

"""
tmp_path.joinpath("sub", "task_dummy.py").write_text(textwrap.dedent(task_source))

latex_source = r"""
\documentclass{report}
\begin{document}
The book of love is long and boring ...
\end{document}
"""
tmp_path.joinpath("sub", "document.tex").write_text(textwrap.dedent(latex_source))

with pytest.warns(DeprecationWarning, match="The old syntax"):
session = main({"paths": tmp_path})

assert session.exit_code == 1
assert len(session.tasks) == 1
assert isinstance(session.execution_reports[0].exc_info[1], RuntimeError)


@needs_latexmk
@skip_on_github_actions_with_win
@pytest.mark.end_to_end
def test_compile_document_w_wrong_flag_new_api(tmp_path):
"""Test that wrong flags raise errors."""
tmp_path.joinpath("sub").mkdir(parents=True)

task_source = """
import pytask
from pytask_latex import compilation_steps
Expand Down
55 changes: 0 additions & 55 deletions tests/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,61 +86,6 @@ def task_compile_latex_document():
def test_parallel_parametrization_over_source_file(runner, tmp_path):
source = """
import pytask

@pytask.mark.depends_on("document.tex")
@pytask.mark.parametrize(
"produces, latex",
[
(
"document.pdf",
("--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd")
),
(
"document.dvi",
("--dvi", "--interaction=nonstopmode", "--synctex=1", "--cd")
),
],
)
def task_compile_latex_document():
pass
"""
tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(source))

latex_source = r"""
\documentclass{report}
\begin{document}
Ma il mio mistero e chiuso in me
\end{document}
"""
tmp_path.joinpath("document.tex").write_text(textwrap.dedent(latex_source))

start = time.time()
with pytest.warns(DeprecationWarning, match="The old syntax"):
result = runner.invoke(cli, [tmp_path.as_posix()])

assert result.exit_code == 0
duration_normal = time.time() - start

for name in ["document.pdf", "document.dvi"]:
tmp_path.joinpath(name).unlink()

start = time.time()
with pytest.warns(DeprecationWarning, match="The old syntax"):
result = runner.invoke(cli, [tmp_path.as_posix(), "-n", 2])

assert result.exit_code == 0
duration_parallel = time.time() - start

assert duration_parallel < duration_normal


@xfail_on_remote
@needs_latexmk
@skip_on_github_actions_with_win
@pytest.mark.end_to_end
def test_parallel_parametrization_over_source_file_new_api(runner, tmp_path):
source = """
import pytask
from pytask_latex import compilation_steps

@pytask.mark.depends_on("document.tex")
Expand Down
40 changes: 0 additions & 40 deletions tests/test_parametrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,46 +73,6 @@ def task_compile_latex_document():
def test_parametrizing_latex_options(tmp_path):
task_source = """
import pytask

@pytask.mark.parametrize("depends_on, produces, latex", [
(
"document.tex",
"document.pdf",
("--interaction=nonstopmode", "--pdf", "--cd")
),
(
"document.tex",
"document.dvi",
("--interaction=nonstopmode", "--dvi", "--cd")
),
])
def task_compile_latex_document():
pass
"""
tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(task_source))

latex_source = r"""
\documentclass{report}
\begin{document}
I can't stop this feeling. Deep inside of me.
\end{document}
"""
tmp_path.joinpath("document.tex").write_text(textwrap.dedent(latex_source))

with pytest.warns(DeprecationWarning, match="The old syntax"):
session = main({"paths": tmp_path})

assert session.exit_code == 0
assert tmp_path.joinpath("document.pdf").exists()
assert tmp_path.joinpath("document.dvi").exists()


@needs_latexmk
@skip_on_github_actions_with_win
@pytest.mark.end_to_end
def test_parametrizing_latex_options_new_api(tmp_path):
task_source = """
import pytask
from pytask_latex import compilation_steps

@pytask.mark.parametrize("depends_on, produces, latex", [
Expand Down