Skip to content

Commit 76a7cfc

Browse files
authored
Release v0.0.2, allow multiple dependencies for LaTeX tasks and better parametrization. (#1)
1 parent 380093a commit 76a7cfc

File tree

14 files changed

+354
-60
lines changed

14 files changed

+354
-60
lines changed

.conda/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ requirements:
2020

2121
run:
2222
- python >=3.6
23-
- pytask >=0.0.3
23+
- pytask >=0.0.4
2424

2525
test:
2626
requires:

.github/workflows/continuous-integration-workflow.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222

2323
steps:
2424
- uses: actions/checkout@v2
25+
- uses: r-lib/actions/setup-tinytex@v1
2526
- uses: goanpeca/setup-miniconda@v1
2627
with:
2728
auto-update-conda: true

CHANGES.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@ Changes
33

44
This is a record of all past pytask-latex releases and what went into them in reverse
55
chronological order. Releases follow `semantic versioning <https://semver.org/>`_ and
6-
all releases are available on `Anaconda.org <https://anaconda.org/pytask/pytask-latex>`_.
6+
all releases are available on `Anaconda.org
7+
<https://anaconda.org/pytask/pytask-latex>`_.
78

89

9-
0.0.1 - 2020-xx-xx
10+
0.0.2 - 2020-07-22
1011
------------------
1112

12-
- :gh:`1` combined the whole effort which went into releasing v0.0.1.
13+
- :gh:`1` allowed LaTeX tasks to have more than one dependency and allows to parametrize
14+
over latex options and latex documents. It also prepares release v0.0.2.
15+
16+
17+
0.0.1 - 2020-07-20
18+
------------------
19+
20+
- Releases v0.0.1.

README.rst

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ Here is an example where you want to compile ``document.tex`` to a PDF.
6161
pass
6262
6363
64+
Note that, the first dependency is always assumed to be the LaTeX document. With
65+
multiple dependencies it may look like this
66+
67+
.. code-block:: python
68+
69+
@pytask.mark.latex
70+
@pytask.mark.depends_on("document.tex", "image.png")
71+
@pytask.mark.produces("document.pdf")
72+
def task_compile_latex_document():
73+
pass
74+
75+
6476
To customize the compilation, you can pass some command line arguments to ``latexmk``
6577
via the ``@pytask.mark.latex`` marker. The default is the following.
6678

@@ -74,7 +86,7 @@ For example, to compile your document with XeLaTeX, use
7486

7587
.. code-block:: python
7688
77-
@pytask.mark.latex("--xelatex", "--interaction=nonstopmode", "--synctex=1")
89+
@pytask.mark.latex("--xelatex", "--interaction=nonstopmode")
7890
def task_compile_latex_document():
7991
pass
8092
@@ -83,6 +95,43 @@ compiled are handled by the ``@pytask.mark.depends_on`` and ``@pytask.mark.produ
8395
markers and cannot be changed.
8496

8597

98+
Parametrization
99+
~~~~~~~~~~~~~~~
100+
101+
You can also parametrize the compilation, meaning compiling multiple .tex documents
102+
as well as compiling a .tex document with different command line arguments.
103+
104+
The following task compiles two latex documents.
105+
106+
.. code-block:: python
107+
108+
@pytask.mark.latex
109+
@pytask.mark.parametrize(
110+
"depends_on, produces",
111+
[("document_1.tex", "document_1.pdf"), ("document_2.tex", "document_2.pdf")],
112+
)
113+
def task_compile_latex_document():
114+
pass
115+
116+
117+
If you want to compile the same document with different command line options, you have
118+
to include the latex decorator in the parametrization just like with
119+
``@pytask.mark.depends_on`` and ``@pytask.mark.produces``.
120+
121+
.. code-block:: python
122+
123+
@pytask.mark.depends_on("document.tex")
124+
@pytask.mark.parametrize(
125+
"produces, latex",
126+
[
127+
("document.pdf", ["--pdf", "interaction=nonstopmode"]),
128+
("document.dvi", ["--dvi", "interaction=nonstopmode"]),
129+
],
130+
)
131+
def task_compile_latex_document():
132+
pass
133+
134+
86135
Changes
87136
-------
88137

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies:
1212
- conda-verify
1313

1414
# Package dependencies
15-
- pytask
15+
- pytask >= 0.0.4
1616

1717
# Misc
1818
- jupyterlab

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ serialize =
99

1010
[bumpversion:file:docs/conf.py]
1111

12-
[bumpversion:file:src/parallel/__init__.py]
12+
[bumpversion:file:src/pytask_latex/__init__.py]

src/pytask_latex/collect.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
from pytask.mark import has_marker
88
from pytask.nodes import PythonFunctionTask
99
from pytask.parametrize import _copy_func
10+
from pytask.shared import to_list
1011

1112

12-
def compile_latex_document(depends_on, produces, args):
13-
if depends_on.stem != produces.stem:
14-
args.append(f"--jobname={produces.stem}")
13+
def compile_latex_document(depends_on, produces, latex):
14+
latex_document = to_list(depends_on)[0]
15+
16+
if latex_document.stem != produces.stem:
17+
latex.append(f"--jobname={produces.stem}")
1518

1619
subprocess.run(
17-
["latexmk"]
18-
+ args
19-
+ [
20+
[
21+
"latexmk",
22+
*latex,
2023
f"--output-directory={produces.parent.as_posix()}",
21-
f"{depends_on.as_posix()}",
24+
f"{latex_document.as_posix()}",
2225
]
2326
)
2427

@@ -40,10 +43,16 @@ def pytask_collect_task(session, path, name, obj):
4043
latex_function.pytestmark = copy.deepcopy(task.function.pytestmark)
4144

4245
args = _create_command_line_arguments(task)
43-
latex_function = functools.partial(latex_function, args=args)
46+
latex_function = functools.partial(latex_function, latex=args)
4447

4548
task.function = latex_function
4649

50+
if task.depends_on[0].value.suffix != ".tex":
51+
raise ValueError(
52+
"The first dependency of a LaTeX task must be the document which will "
53+
"be compiled."
54+
)
55+
4756
return task
4857

4958

src/pytask_latex/execute.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import shutil
2-
from pathlib import Path
32

43
import pytask
54
from pytask.mark import get_markers_from_task
5+
from pytask.nodes import FilePathNode
66

77

88
@pytask.hookimpl
@@ -14,8 +14,20 @@ def pytask_execute_task_setup(task):
1414
"your PATH."
1515
)
1616

17-
if isinstance(task.depends_on, Path):
18-
raise ValueError("'depends_on' must be a path to a single .tex document.")
17+
if not (
18+
isinstance(task.depends_on[0], FilePathNode)
19+
and task.depends_on[0].value.suffix == ".tex"
20+
):
21+
raise ValueError(
22+
"The first or sole dependency must point to the .tex document which "
23+
"will be compiled."
24+
)
1925

20-
if isinstance(task.produces, Path):
21-
raise ValueError("'produces' must be a path to a single .pdf document.")
26+
if not (
27+
isinstance(task.produces[0], FilePathNode)
28+
and task.produces[0].value.suffix in [".pdf", ".ps", ".dvi"]
29+
):
30+
raise ValueError(
31+
"The first or sole product must point to a .pdf, .ps or .dvi file "
32+
"which is the compilation."
33+
)

src/pytask_latex/parametrize.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pytask
2+
3+
4+
@pytask.hookimpl
5+
def pytask_generate_tasks_add_marker(obj, kwargs):
6+
if callable(obj):
7+
if "latex" in kwargs:
8+
pytask.mark.__getattr__("latex")(*kwargs.pop("latex"))(obj)

src/pytask_latex/plugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import pytask
22
from pytask_latex import collect
33
from pytask_latex import execute
4+
from pytask_latex import parametrize
45

56

67
@pytask.hookimpl
78
def pytask_add_hooks(pm):
89
pm.register(collect)
910
pm.register(execute)
11+
pm.register(parametrize)

tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
import shutil
3+
import sys
4+
5+
import pytest
6+
7+
needs_latexmk = pytest.mark.skipif(
8+
shutil.which("latexmk") is None, reason="latexmk needs to be installed."
9+
)
10+
11+
skip_on_github_actions_with_win = pytest.mark.skipif(
12+
os.environ.get("GITHUB_ACTIONS", "false") == "true" and sys.platform == "win32",
13+
reason="TinyTeX does not work on Windows.",
14+
)

0 commit comments

Comments
 (0)