Skip to content

Release 0.0.3 and transition to pytask 0.0.5. #3

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 4 commits into from
Aug 12, 2020
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/pytask/pytask-latex>`_.


0.0.3 - 2020-08-12
------------------

- :gh:`3` prepares pytask-latex for pytask v0.0.5 and releases v0.0.3.


0.0.2 - 2020-07-22
------------------

Expand Down
11 changes: 7 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,25 @@ via the ``@pytask.mark.latex`` marker. The default is the following.

.. code-block:: python

@pytask.mark.latex("--pdf", "--interaction=nonstopmode", "--synctex=1")
@pytask.mark.latex(["--pdf", "--interaction=nonstopmode", "--synctex=1"])
def task_compile_latex_document():
pass

For example, to compile your document with XeLaTeX, use

.. code-block:: python

@pytask.mark.latex("--xelatex", "--interaction=nonstopmode")
@pytask.mark.latex(["--xelatex", "--interaction=nonstopmode"])
def task_compile_latex_document():
pass

The options ``jobname``, ``output-directory`` and the ``.tex`` file which will be
compiled are handled by the ``@pytask.mark.depends_on`` and ``@pytask.mark.produces``
markers and cannot be changed.

You can either pass a string or a list of strings to the ``@pytask.mark.latex``
decorator.


Parametrization
~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -124,8 +127,8 @@ to include the latex decorator in the parametrization just like with
@pytask.mark.parametrize(
"produces, latex",
[
("document.pdf", ["--pdf", "interaction=nonstopmode"]),
("document.dvi", ["--dvi", "interaction=nonstopmode"]),
("document.pdf", (["--pdf", "interaction=nonstopmode"],)),
("document.dvi", (["--dvi", "interaction=nonstopmode"],)),
],
)
def task_compile_latex_document():
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.2
current_version = 0.0.3
parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))(\-?((dev)?(?P<dev>\d+))?)
serialize =
{major}.{minor}.{patch}dev{dev}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="pytask-latex",
version="0.0.2",
version="0.0.3",
packages=find_packages(where="src"),
package_dir={"": "src"},
entry_points={"pytask": ["pytask_latex = pytask_latex.plugin"]},
Expand Down
2 changes: 1 addition & 1 deletion src/pytask_latex/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.2"
__version__ = "0.0.3"
48 changes: 34 additions & 14 deletions src/pytask_latex/collect.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import copy
import functools
import subprocess
from typing import Iterable
from typing import Optional
from typing import Union

import pytask
from pytask.mark import get_markers_from_task
from pytask.mark import has_marker
from pytask.nodes import PythonFunctionTask
from pytask.parametrize import _copy_func
from pytask.shared import to_list
from _pytask.config import hookimpl
from _pytask.mark import get_specific_markers_from_task
from _pytask.mark import has_marker
from _pytask.nodes import PythonFunctionTask
from _pytask.parametrize import _copy_func
from _pytask.shared import to_list


def latex(options: Optional[Union[str, Iterable[str]]] = None):
"""Specify command line options for latexmk.

Parameters
----------
options : Optional[Union[str, Iterable[str]]]
One or multiple command line options passed to latexmk.

"""
if options is None:
options = ["--pdf", "--interaction=nonstopmode", "--synctex=1"]
elif isinstance(options, str):
options = [options]
return options


def compile_latex_document(depends_on, produces, latex):
Expand All @@ -26,7 +45,7 @@ def compile_latex_document(depends_on, produces, latex):
)


@pytask.hookimpl
@hookimpl
def pytask_collect_task(session, path, name, obj):
"""Collect a task which is a function.

Expand All @@ -40,7 +59,7 @@ def pytask_collect_task(session, path, name, obj):
path, name, obj, session
)
latex_function = _copy_func(compile_latex_document)
latex_function.pytestmark = copy.deepcopy(task.function.pytestmark)
latex_function.pytaskmark = copy.deepcopy(task.function.pytaskmark)

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


def _create_command_line_arguments(task):
args = get_markers_from_task(task, "latex")[0].args
if args:
out = list(args)
else:
out = ["--pdf", "--interaction=nonstopmode", "--synctex=1"]
latex_marks = get_specific_markers_from_task(task, "latex")
mark = latex_marks[0]
for mark_ in latex_marks[1:]:
mark = mark.combine_with(mark_)

options = latex(*mark.args, **mark.kwargs)

return out
return options
6 changes: 6 additions & 0 deletions src/pytask_latex/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from _pytask.config import hookimpl


@hookimpl
def pytask_parse_config(config):
config["markers"]["latex"] = "latex: Tasks which compile LaTeX documents."
10 changes: 5 additions & 5 deletions src/pytask_latex/execute.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import shutil

import pytask
from pytask.mark import get_markers_from_task
from pytask.nodes import FilePathNode
from _pytask.config import hookimpl
from _pytask.mark import get_specific_markers_from_task
from _pytask.nodes import FilePathNode


@pytask.hookimpl
@hookimpl
def pytask_execute_task_setup(task):
if get_markers_from_task(task, "latex"):
if get_specific_markers_from_task(task, "latex"):
if shutil.which("latexmk") is None:
raise RuntimeError(
"latexmk is needed to compile LaTeX documents, but it is not found on "
Expand Down
9 changes: 5 additions & 4 deletions src/pytask_latex/parametrize.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytask
from _pytask.config import hookimpl
from _pytask.mark import MARK_GEN as mark # noqa: N811


@pytask.hookimpl
def pytask_generate_tasks_add_marker(obj, kwargs):
@hookimpl
def pytask_parametrize_kwarg_to_marker(obj, kwargs):
if callable(obj):
if "latex" in kwargs:
pytask.mark.__getattr__("latex")(*kwargs.pop("latex"))(obj)
mark.latex(*kwargs.pop("latex"))(obj)
6 changes: 4 additions & 2 deletions src/pytask_latex/plugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import pytask
from _pytask.config import hookimpl
from pytask_latex import collect
from pytask_latex import config
from pytask_latex import execute
from pytask_latex import parametrize


@pytask.hookimpl
@hookimpl
def pytask_add_hooks(pm):
pm.register(collect)
pm.register(config)
pm.register(execute)
pm.register(parametrize)
2 changes: 1 addition & 1 deletion tests/test_collect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from pytask.mark import Mark
from _pytask.mark import Mark
from pytask_latex.collect import _create_command_line_arguments


Expand Down
7 changes: 7 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pytask import main


def test_marker_is_configured(tmp_path):
session = main({"paths": tmp_path})

assert "latex" in session.config["markers"]
16 changes: 8 additions & 8 deletions tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from pathlib import Path

import pytest
from _pytask.mark import Mark
from _pytask.nodes import FilePathNode
from conftest import needs_latexmk
from conftest import skip_on_github_actions_with_win
from pytask.main import main
from pytask.mark import Mark
from pytask.nodes import FilePathNode
from pytask import main
from pytask_latex.execute import pytask_execute_task_setup


Expand Down Expand Up @@ -207,7 +207,7 @@ def test_compile_latex_document_w_xelatex(tmp_path):
task_source = """
import pytask

@pytask.mark.latex("--xelatex", "--interaction=nonstopmode", "--synctex=1")
@pytask.mark.latex(["--xelatex", "--interaction=nonstopmode", "--synctex=1"])
@pytask.mark.depends_on("document.tex")
@pytask.mark.produces("document.pdf")
def task_compile_document():
Expand Down Expand Up @@ -237,8 +237,8 @@ def test_compile_latex_document_w_two_dependencies(tmp_path):
task_source = """
import pytask

@pytask.mark.latex()
@pytask.mark.depends_on("document.tex", "in.txt")
@pytask.mark.latex
@pytask.mark.depends_on(["document.tex", "in.txt"])
@pytask.mark.produces("document.pdf")
def task_compile_document():
pass
Expand Down Expand Up @@ -269,8 +269,8 @@ def test_fail_because_latex_document_is_not_first_dependency(tmp_path):
task_source = """
import pytask

@pytask.mark.latex()
@pytask.mark.depends_on("in.txt", "document.tex")
@pytask.mark.latex
@pytask.mark.depends_on(["in.txt", "document.tex"])
@pytask.mark.produces("document.pdf")
def task_compile_document():
pass
Expand Down
18 changes: 9 additions & 9 deletions tests/test_parametrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest
from conftest import needs_latexmk
from conftest import skip_on_github_actions_with_win
from pytask.main import main
from pytask_latex.parametrize import pytask_generate_tasks_add_marker
from pytask import main
from pytask_latex.parametrize import pytask_parametrize_kwarg_to_marker


def func():
Expand All @@ -17,16 +17,16 @@ def func():
[(len, {}, None), (func, {"latex": ["--dummy-option"]}, func), (func, {}, None)],
)
def test_pytask_generate_tasks_add_marker(obj, kwargs, expected):
pytask_generate_tasks_add_marker(obj, kwargs)
pytask_parametrize_kwarg_to_marker(obj, kwargs)

if expected is None:
assert not hasattr(obj, "pytestmark")
assert not hasattr(obj, "pytaskmark")
else:
assert obj.pytestmark
assert obj.pytaskmark

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


@needs_latexmk
Expand Down Expand Up @@ -73,8 +73,8 @@ def test_parametrizing_latex_options(tmp_path):
import pytask

@pytask.mark.parametrize("depends_on, produces, latex", [
("document.tex", "document.pdf", ("--interaction=nonstopmode", "--pdf")),
("document.tex", "document.dvi", ("--interaction=nonstopmode", "--dvi")),
("document.tex", "document.pdf", (["--interaction=nonstopmode", "--pdf"],)),
("document.tex", "document.dvi", (["--interaction=nonstopmode", "--dvi"],)),
])
def task_compile_latex_document():
pass
Expand Down