Skip to content

Commit ed179b5

Browse files
Implementation of build steps and support for old API (#32)
Co-authored-by: Tobias Raabe <[email protected]>
1 parent a114ce1 commit ed179b5

File tree

13 files changed

+480
-253
lines changed

13 files changed

+480
-253
lines changed

CHANGES.rst

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,96 +7,103 @@ all releases are available on `Anaconda.org
77
<https://anaconda.org/conda-forge/pytask-latex>`_.
88

99

10+
0.1.2 - 2022-xx-xx
11+
------------------
12+
13+
- :pull:`32` implements a new interface to the compilation process which consists of
14+
composable compilation steps. (Many thanks to :user:`axtimhaus`!:tada:)
15+
16+
1017
0.1.1 - 2022-02-08
1118
------------------
1219

13-
- :gh:`30` skips concurrent CI builds.
14-
- :gh:`31` deprecates Python 3.6 and add support for Python 3.10.
20+
- :pull:`30` skips concurrent CI builds.
21+
- :pull:`31` deprecates Python 3.6 and add support for Python 3.10.
1522

1623

1724
0.1.0 - 2021-07-21
1825
------------------
1926

20-
- :gh:`23` updates the ``README.rst``.
21-
- :gh:`24` replaces versioneer with setuptools-scm.
22-
- :gh:`26` aligns pytask-latex with pytask v0.1.0.
27+
- :pull:`23` updates the ``README.rst``.
28+
- :pull:`24` replaces versioneer with setuptools-scm.
29+
- :pull:`26` aligns pytask-latex with pytask v0.1.0.
2330

2431

2532
0.0.12 - 2021-03-05
2633
-------------------
2734

28-
- :gh:`19` fixes some post-release issues.
29-
- :gh:`21` adds dependencies to ``setup.py`` and install via ``conda-forge``.
35+
- :pull:`19` fixes some post-release issues.
36+
- :pull:`21` adds dependencies to ``setup.py`` and install via ``conda-forge``.
3037

3138

3239
0.0.11 - 2021-02-25
3340
-------------------
3441

35-
- :gh:`18` prepares pytask-latex to be published on PyPI, adds versioneer and more.
42+
- :pull:`18` prepares pytask-latex to be published on PyPI, adds versioneer and more.
3643

3744

3845
0.0.10 - 2021-01-16
3946
-------------------
4047

41-
- :gh:`16` fixes the scanner by keeping only scanned dependencies which exist. Convert
48+
- :pull:`16` fixes the scanner by keeping only scanned dependencies which exist. Convert
4249
args to strings.
4350

4451

4552
0.0.9 - 2020-12-28
4653
------------------
4754

48-
- :gh:`12` integrates the latex-dependency-scanner to automatically detect dependencies
49-
of a LaTeX document and releases v0.0.9.
50-
- :gh:`13` fixes the CI.
55+
- :pull:`12` integrates the latex-dependency-scanner to automatically detect
56+
dependencies of a LaTeX document and releases v0.0.9.
57+
- :pull:`13` fixes the CI.
5158

5259

5360
0.0.8 - 2020-10-29
5461
------------------
5562

56-
- :gh:`11` makes pytask-latex work with pytask v0.0.9.
63+
- :pull:`11` makes pytask-latex work with pytask v0.0.9.
5764

5865

5966
0.0.7 - 2020-10-14
6067
------------------
6168

62-
- :gh:`10` fixes error that ``outputdirectory`` has to be relative to latex document due
63-
to security problems.
69+
- :pull:`10` fixes error that ``outputdirectory`` has to be relative to latex document
70+
due to security problems.
6471

6572

6673
0.0.6 - 2020-10-14
6774
------------------
6875

69-
- :gh:`9` fixes the last release and the ``pytask_collect_task_teardown`` call.
76+
- :pull:`9` fixes the last release and the ``pytask_collect_task_teardown`` call.
7077

7178

7279
0.0.5 - 2020-10-04
7380
------------------
7481

75-
- :gh:`5` fixes some errors in the test suite due to pytask v0.0.6.
76-
- :gh:`6` check that exit codes are equal to zero.
77-
- :gh:`7` fixes the README.
78-
- :gh:`8` works with pytask v0.0.7 and releases v0.0.5.
82+
- :pull:`5` fixes some errors in the test suite due to pytask v0.0.6.
83+
- :pull:`6` check that exit codes are equal to zero.
84+
- :pull:`7` fixes the README.
85+
- :pull:`8` works with pytask v0.0.7 and releases v0.0.5.
7986

8087

8188
0.0.4 - 2020-08-21
8289
------------------
8390

84-
- :gh:`4` changes the default options. latexmk will step into the source directory
91+
- :pull:`4` changes the default options. latexmk will step into the source directory
8592
before compiling the document. Releases 0.0.4.
8693

8794

8895
0.0.3 - 2020-08-12
8996
------------------
9097

91-
- :gh:`3` prepares pytask-latex for pytask v0.0.5 and releases v0.0.3.
98+
- :pull:`3` prepares pytask-latex for pytask v0.0.5 and releases v0.0.3.
9299

93100

94101
0.0.2 - 2020-07-22
95102
------------------
96103

97-
- :gh:`1` allowed LaTeX tasks to have more than one dependency and allows to parametrize
98-
over latex options and latex documents. It also prepares release v0.0.2.
99-
- :gh:`2` fixes the release.
104+
- :pull:`1` allowed LaTeX tasks to have more than one dependency and allows to
105+
parametrize over latex options and latex documents. It also prepares release v0.0.2.
106+
- :pull:`2` fixes the release.
100107

101108

102109
0.0.1 - 2020-07-20

README.rst

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
pytask-latex
3535
============
3636

37-
pytask-latex allows you to compile LaTeX documents.
37+
pytask-latex allows you to compile LaTeX documents with pytask
3838

39-
It also tries to infer the dependency of the LaTeX document such as included images,
40-
bibliography files and other .tex files automatically to compile LaTeX documents when it
41-
is possible.
39+
It also uses `latex-dependency-scanner
40+
<https://github.com/pytask-dev/latex-dependency-scanner>`_ to automatically infer the
41+
dependencies of the LaTeX document such as images, bibliographies and other ``.tex``
42+
files which are necessary to compile the LaTeX document.
4243

4344

4445
Installation
@@ -65,14 +66,14 @@ following on the command line
6566
$ latexmk --help
6667
6768
If an error is shown instead of a help page, you can install ``latexmk`` with one of the
68-
popular LaTeX distributions, like `MiKTeX <https://miktex.org/>`_, `TeX Live
69-
<https://www.tug.org/texlive/>`_, `MacTeX <http://www.tug.org/mactex/>`_ or others.
69+
popular LaTeX distributions, like `TeX Live <https://www.tug.org/texlive/>`_, `MiKTeX
70+
<https://miktex.org/>`_, `MacTeX <http://www.tug.org/mactex/>`_ or others.
7071

7172

7273
Usage
7374
-----
7475

75-
Here is an example where you want to compile ``document.tex`` to a PDF.
76+
Compiling your PDF can be as simple as writing the following task.
7677

7778
.. code-block:: python
7879
@@ -85,9 +86,9 @@ Here is an example where you want to compile ``document.tex`` to a PDF.
8586
def task_compile_latex_document():
8687
pass
8788
88-
When the task is executed, you find a ``document.pdf`` in the same folder as your
89-
``document.tex``, but you could also compile the report into a another folder by
90-
changing the path in ``produces``.
89+
Use ``@pytask.mark.latex`` to indicate that this task compiles a LaTeX document.
90+
``@pytask.mark.depends_on`` points to the source file which is compiled and
91+
``@pytask.mark.produces`` is the path of the compiled PDF.
9192

9293

9394
Multiple dependencies and products
@@ -139,46 +140,82 @@ The same applies to the compiled document which is either in the first position,
139140
the key ``"document"`` or ``0``.
140141

141142

142-
Command Line Arguments
143-
~~~~~~~~~~~~~~~~~~~~~~
143+
Customizing the compilation
144+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
144145

145-
To customize the compilation, you can pass some command line arguments to ``latexmk``
146-
via the ``@pytask.mark.latex`` marker. The default is the following.
146+
pytask-latex uses latexmk by default to compile the document because it handles most
147+
use-cases automatically. The following is equivalent to a bare ``@pytask.mark.latex``
148+
decorator.
147149

148150
.. code-block:: python
149151
150-
@pytask.mark.latex(["--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd"])
152+
@pytask.mark.latex(compilation_steps="latexmk")
151153
def task_compile_latex_document():
152-
pass
154+
...
155+
156+
The ``@pytask.mark.latex`` decorator has a keyword argument called ``compilation_steps``
157+
which accepts which accepts strings or list of strings pointing to internally
158+
implemented compilation steps. Using strings will use the default configuration of this
159+
compilation step. It is equivalent to the following.
160+
161+
.. code-block::
162+
163+
from pytask_latex import compilation_steps
164+
165+
166+
@pytask.mark.latex(
167+
compilation_steps=compilation_steps.latexmk(
168+
options=("--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd")
169+
)
170+
)
171+
def task_compile_latex_document():
172+
...
153173
154-
For example, to compile your document with XeLaTeX, use
174+
In this example, ``compilation_steps.latexmk`` is a compilation step constructor which
175+
accepts a set of options and creates a compilation step function.
176+
177+
You can pass different options to change the compilation process with latexmk. Here is
178+
an example for generating a ``.dvi``.
155179

156180
.. code-block:: python
157181
158-
@pytask.mark.latex(["--xelatex", "--interaction=nonstopmode"])
182+
@pytask.mark.latex(
183+
compilation_steps=compilation_steps.latexmk(
184+
options=("--dvi", "--interaction=nonstopmode", "--synctex=1", "--cd")
185+
)
186+
)
159187
def task_compile_latex_document():
160-
pass
188+
...
161189
162-
The options ``--jobname``, ``--output-directory`` and the ``.tex`` file which will be
163-
compiled are automatically handled and inferred from the ``@pytask.mark.depends_on`` and
164-
``@pytask.mark.produces`` markers.
190+
``compilation_step.latexmk(options)`` generates a compilation step which is a function
191+
with the following signature:
165192

166-
The ``@pytask.mark.latex`` accepts both, a string or a list of strings with options.
193+
.. code-block::
167194
168-
For more options and their explanations, visit the `latexmk manual
169-
<https://man.cx/latexmk>`_ or type the following commands.
195+
from pathlib import Path
196+
import subprocess
170197
171-
.. code-block:: console
172198
173-
$ latexmk -h
174-
$ latexmk -showextraoptions
199+
def custom_compilation_step(path_to_tex: Path, path_to_document: Path) -> None:
200+
...
201+
subproces.run(..., check=True)
202+
203+
You can also pass your custom compilation step with the same signature to the
204+
``compilation_steps`` keyword argument of the decorator.
205+
206+
Each compilation step receives the path to the LaTeX source file and the path to the
207+
final document which it uses to call some program on the command line to run another
208+
step in the compilation process.
209+
210+
In the future, pytask-latex will provide more compilation steps for compiling
211+
bibliographies, glossaries and the like.
175212

176213

177214
Parametrization
178215
~~~~~~~~~~~~~~~
179216

180-
You can also parametrize the compilation, meaning compiling multiple .tex documents
181-
as well as compiling a .tex document with different command line arguments.
217+
You can also parametrize the compilation, meaning compiling multiple ``.tex`` documents
218+
as well as compiling a ``.tex`` document with different command line arguments.
182219

183220
The following task compiles two latex documents.
184221

@@ -195,7 +232,8 @@ The following task compiles two latex documents.
195232
196233
If you want to compile the same document with different command line options, you have
197234
to include the latex decorator in the parametrization just like with
198-
``@pytask.mark.depends_on`` and ``@pytask.mark.produces``.
235+
``@pytask.mark.depends_on`` and ``@pytask.mark.produces``. Pass a dictionary for
236+
possible compilation steps and their options.
199237

200238
.. code-block:: python
201239
@@ -205,11 +243,19 @@ to include the latex decorator in the parametrization just like with
205243
[
206244
(
207245
"document.pdf",
208-
("--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd"),
246+
{
247+
"compilation_steps": compilation_steps.latexmk(
248+
("--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd")
249+
)
250+
},
209251
),
210252
(
211253
"document.dvi",
212-
("--dvi", "--interaction=nonstopmode", "--synctex=1", "--cd"),
254+
{
255+
"compilation_steps": compilation_steps.latexmk(
256+
("--dvi", "--interaction=nonstopmode", "--synctex=1", "--cd")
257+
)
258+
},
213259
),
214260
],
215261
)

environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ dependencies:
1919
- black
2020
- jupyterlab
2121
- matplotlib
22-
- pdbpp
2322
- pre-commit
2423
- pytest
2524
- pytest-cov

0 commit comments

Comments
 (0)