Skip to content

Commit 3927e90

Browse files
authored
Release 0.0.3 and transition to pytask 0.0.5. (#3)
1 parent 064b2eb commit 3927e90

File tree

14 files changed

+95
-50
lines changed

14 files changed

+95
-50
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ all releases are available on `Anaconda.org
77
<https://anaconda.org/pytask/pytask-latex>`_.
88

99

10+
0.0.3 - 2020-08-12
11+
------------------
12+
13+
- :gh:`3` prepares pytask-latex for pytask v0.0.5 and releases v0.0.3.
14+
15+
1016
0.0.2 - 2020-07-22
1117
------------------
1218

README.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,25 @@ via the ``@pytask.mark.latex`` marker. The default is the following.
7878

7979
.. code-block:: python
8080
81-
@pytask.mark.latex("--pdf", "--interaction=nonstopmode", "--synctex=1")
81+
@pytask.mark.latex(["--pdf", "--interaction=nonstopmode", "--synctex=1"])
8282
def task_compile_latex_document():
8383
pass
8484
8585
For example, to compile your document with XeLaTeX, use
8686

8787
.. code-block:: python
8888
89-
@pytask.mark.latex("--xelatex", "--interaction=nonstopmode")
89+
@pytask.mark.latex(["--xelatex", "--interaction=nonstopmode"])
9090
def task_compile_latex_document():
9191
pass
9292
9393
The options ``jobname``, ``output-directory`` and the ``.tex`` file which will be
9494
compiled are handled by the ``@pytask.mark.depends_on`` and ``@pytask.mark.produces``
9595
markers and cannot be changed.
9696

97+
You can either pass a string or a list of strings to the ``@pytask.mark.latex``
98+
decorator.
99+
97100

98101
Parametrization
99102
~~~~~~~~~~~~~~~
@@ -124,8 +127,8 @@ to include the latex decorator in the parametrization just like with
124127
@pytask.mark.parametrize(
125128
"produces, latex",
126129
[
127-
("document.pdf", ["--pdf", "interaction=nonstopmode"]),
128-
("document.dvi", ["--dvi", "interaction=nonstopmode"]),
130+
("document.pdf", (["--pdf", "interaction=nonstopmode"],)),
131+
("document.dvi", (["--dvi", "interaction=nonstopmode"],)),
129132
],
130133
)
131134
def task_compile_latex_document():

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.0.2
2+
current_version = 0.0.3
33
parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))(\-?((dev)?(?P<dev>\d+))?)
44
serialize =
55
{major}.{minor}.{patch}dev{dev}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="pytask-latex",
6-
version="0.0.2",
6+
version="0.0.3",
77
packages=find_packages(where="src"),
88
package_dir={"": "src"},
99
entry_points={"pytask": ["pytask_latex = pytask_latex.plugin"]},

src/pytask_latex/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.2"
1+
__version__ = "0.0.3"

src/pytask_latex/collect.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
import copy
22
import functools
33
import subprocess
4+
from typing import Iterable
5+
from typing import Optional
6+
from typing import Union
47

5-
import pytask
6-
from pytask.mark import get_markers_from_task
7-
from pytask.mark import has_marker
8-
from pytask.nodes import PythonFunctionTask
9-
from pytask.parametrize import _copy_func
10-
from pytask.shared import to_list
8+
from _pytask.config import hookimpl
9+
from _pytask.mark import get_specific_markers_from_task
10+
from _pytask.mark import has_marker
11+
from _pytask.nodes import PythonFunctionTask
12+
from _pytask.parametrize import _copy_func
13+
from _pytask.shared import to_list
14+
15+
16+
def latex(options: Optional[Union[str, Iterable[str]]] = None):
17+
"""Specify command line options for latexmk.
18+
19+
Parameters
20+
----------
21+
options : Optional[Union[str, Iterable[str]]]
22+
One or multiple command line options passed to latexmk.
23+
24+
"""
25+
if options is None:
26+
options = ["--pdf", "--interaction=nonstopmode", "--synctex=1"]
27+
elif isinstance(options, str):
28+
options = [options]
29+
return options
1130

1231

1332
def compile_latex_document(depends_on, produces, latex):
@@ -26,7 +45,7 @@ def compile_latex_document(depends_on, produces, latex):
2645
)
2746

2847

29-
@pytask.hookimpl
48+
@hookimpl
3049
def pytask_collect_task(session, path, name, obj):
3150
"""Collect a task which is a function.
3251
@@ -40,7 +59,7 @@ def pytask_collect_task(session, path, name, obj):
4059
path, name, obj, session
4160
)
4261
latex_function = _copy_func(compile_latex_document)
43-
latex_function.pytestmark = copy.deepcopy(task.function.pytestmark)
62+
latex_function.pytaskmark = copy.deepcopy(task.function.pytaskmark)
4463

4564
args = _create_command_line_arguments(task)
4665
latex_function = functools.partial(latex_function, latex=args)
@@ -57,10 +76,11 @@ def pytask_collect_task(session, path, name, obj):
5776

5877

5978
def _create_command_line_arguments(task):
60-
args = get_markers_from_task(task, "latex")[0].args
61-
if args:
62-
out = list(args)
63-
else:
64-
out = ["--pdf", "--interaction=nonstopmode", "--synctex=1"]
79+
latex_marks = get_specific_markers_from_task(task, "latex")
80+
mark = latex_marks[0]
81+
for mark_ in latex_marks[1:]:
82+
mark = mark.combine_with(mark_)
83+
84+
options = latex(*mark.args, **mark.kwargs)
6585

66-
return out
86+
return options

src/pytask_latex/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from _pytask.config import hookimpl
2+
3+
4+
@hookimpl
5+
def pytask_parse_config(config):
6+
config["markers"]["latex"] = "latex: Tasks which compile LaTeX documents."

src/pytask_latex/execute.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import shutil
22

3-
import pytask
4-
from pytask.mark import get_markers_from_task
5-
from pytask.nodes import FilePathNode
3+
from _pytask.config import hookimpl
4+
from _pytask.mark import get_specific_markers_from_task
5+
from _pytask.nodes import FilePathNode
66

77

8-
@pytask.hookimpl
8+
@hookimpl
99
def pytask_execute_task_setup(task):
10-
if get_markers_from_task(task, "latex"):
10+
if get_specific_markers_from_task(task, "latex"):
1111
if shutil.which("latexmk") is None:
1212
raise RuntimeError(
1313
"latexmk is needed to compile LaTeX documents, but it is not found on "

src/pytask_latex/parametrize.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import pytask
1+
from _pytask.config import hookimpl
2+
from _pytask.mark import MARK_GEN as mark # noqa: N811
23

34

4-
@pytask.hookimpl
5-
def pytask_generate_tasks_add_marker(obj, kwargs):
5+
@hookimpl
6+
def pytask_parametrize_kwarg_to_marker(obj, kwargs):
67
if callable(obj):
78
if "latex" in kwargs:
8-
pytask.mark.__getattr__("latex")(*kwargs.pop("latex"))(obj)
9+
mark.latex(*kwargs.pop("latex"))(obj)

src/pytask_latex/plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import pytask
1+
from _pytask.config import hookimpl
22
from pytask_latex import collect
3+
from pytask_latex import config
34
from pytask_latex import execute
45
from pytask_latex import parametrize
56

67

7-
@pytask.hookimpl
8+
@hookimpl
89
def pytask_add_hooks(pm):
910
pm.register(collect)
11+
pm.register(config)
1012
pm.register(execute)
1113
pm.register(parametrize)

tests/test_collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from pytask.mark import Mark
2+
from _pytask.mark import Mark
33
from pytask_latex.collect import _create_command_line_arguments
44

55

tests/test_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pytask import main
2+
3+
4+
def test_marker_is_configured(tmp_path):
5+
session = main({"paths": tmp_path})
6+
7+
assert "latex" in session.config["markers"]

tests/test_execute.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from pathlib import Path
44

55
import pytest
6+
from _pytask.mark import Mark
7+
from _pytask.nodes import FilePathNode
68
from conftest import needs_latexmk
79
from conftest import skip_on_github_actions_with_win
8-
from pytask.main import main
9-
from pytask.mark import Mark
10-
from pytask.nodes import FilePathNode
10+
from pytask import main
1111
from pytask_latex.execute import pytask_execute_task_setup
1212

1313

@@ -207,7 +207,7 @@ def test_compile_latex_document_w_xelatex(tmp_path):
207207
task_source = """
208208
import pytask
209209
210-
@pytask.mark.latex("--xelatex", "--interaction=nonstopmode", "--synctex=1")
210+
@pytask.mark.latex(["--xelatex", "--interaction=nonstopmode", "--synctex=1"])
211211
@pytask.mark.depends_on("document.tex")
212212
@pytask.mark.produces("document.pdf")
213213
def task_compile_document():
@@ -237,8 +237,8 @@ def test_compile_latex_document_w_two_dependencies(tmp_path):
237237
task_source = """
238238
import pytask
239239
240-
@pytask.mark.latex()
241-
@pytask.mark.depends_on("document.tex", "in.txt")
240+
@pytask.mark.latex
241+
@pytask.mark.depends_on(["document.tex", "in.txt"])
242242
@pytask.mark.produces("document.pdf")
243243
def task_compile_document():
244244
pass
@@ -269,8 +269,8 @@ def test_fail_because_latex_document_is_not_first_dependency(tmp_path):
269269
task_source = """
270270
import pytask
271271
272-
@pytask.mark.latex()
273-
@pytask.mark.depends_on("in.txt", "document.tex")
272+
@pytask.mark.latex
273+
@pytask.mark.depends_on(["in.txt", "document.tex"])
274274
@pytask.mark.produces("document.pdf")
275275
def task_compile_document():
276276
pass

tests/test_parametrize.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import pytest
44
from conftest import needs_latexmk
55
from conftest import skip_on_github_actions_with_win
6-
from pytask.main import main
7-
from pytask_latex.parametrize import pytask_generate_tasks_add_marker
6+
from pytask import main
7+
from pytask_latex.parametrize import pytask_parametrize_kwarg_to_marker
88

99

1010
def func():
@@ -17,16 +17,16 @@ def func():
1717
[(len, {}, None), (func, {"latex": ["--dummy-option"]}, func), (func, {}, None)],
1818
)
1919
def test_pytask_generate_tasks_add_marker(obj, kwargs, expected):
20-
pytask_generate_tasks_add_marker(obj, kwargs)
20+
pytask_parametrize_kwarg_to_marker(obj, kwargs)
2121

2222
if expected is None:
23-
assert not hasattr(obj, "pytestmark")
23+
assert not hasattr(obj, "pytaskmark")
2424
else:
25-
assert obj.pytestmark
25+
assert obj.pytaskmark
2626

2727
# Cleanup necessary since func is changed in-place.
28-
if hasattr(obj, "pytestmark"):
29-
delattr(obj, "pytestmark")
28+
if hasattr(obj, "pytaskmark"):
29+
delattr(obj, "pytaskmark")
3030

3131

3232
@needs_latexmk
@@ -73,8 +73,8 @@ def test_parametrizing_latex_options(tmp_path):
7373
import pytask
7474
7575
@pytask.mark.parametrize("depends_on, produces, latex", [
76-
("document.tex", "document.pdf", ("--interaction=nonstopmode", "--pdf")),
77-
("document.tex", "document.dvi", ("--interaction=nonstopmode", "--dvi")),
76+
("document.tex", "document.pdf", (["--interaction=nonstopmode", "--pdf"],)),
77+
("document.tex", "document.dvi", (["--interaction=nonstopmode", "--dvi"],)),
7878
])
7979
def task_compile_latex_document():
8080
pass

0 commit comments

Comments
 (0)