Skip to content

Commit 8fef42c

Browse files
[pre-commit.ci] pre-commit autoupdate (#64)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tobias Raabe <[email protected]>
1 parent f5818a5 commit 8fef42c

File tree

11 files changed

+96
-98
lines changed

11 files changed

+96
-98
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,15 @@ repos:
3030
hooks:
3131
- id: reorder-python-imports
3232
args: [--py38-plus, --add-import, 'from __future__ import annotations']
33-
- repo: https://github.com/asottile/setup-cfg-fmt
34-
rev: v2.5.0
35-
hooks:
36-
- id: setup-cfg-fmt
37-
- repo: https://github.com/psf/black
38-
rev: 23.9.1
39-
hooks:
40-
- id: black
4133
- repo: https://github.com/astral-sh/ruff-pre-commit
42-
rev: v0.0.292
34+
rev: v0.1.6
4335
hooks:
4436
- id: ruff
37+
- id: ruff-format
4538
- repo: https://github.com/dosisod/refurb
46-
rev: v1.21.0
39+
rev: v1.24.0
4740
hooks:
4841
- id: refurb
49-
args: [--ignore, FURB126]
50-
- repo: https://github.com/econchick/interrogate
51-
rev: 1.5.0
52-
hooks:
53-
- id: interrogate
54-
args: [-v, --fail-under=40, src, tests]
5542
- repo: https://github.com/executablebooks/mdformat
5643
rev: 0.7.17
5744
hooks:
@@ -67,7 +54,7 @@ repos:
6754
- id: codespell
6855
args: [-L als, -L falsy]
6956
- repo: https://github.com/pre-commit/mirrors-mypy
70-
rev: 'v1.5.1'
57+
rev: 'v1.7.0'
7158
hooks:
7259
- id: mypy
7360
additional_dependencies: [
@@ -83,7 +70,7 @@ repos:
8370
hooks:
8471
- id: check-manifest
8572
args: [--no-build-isolation]
86-
additional_dependencies: [setuptools-scm, toml]
73+
additional_dependencies: [setuptools-scm, toml, wheel]
8774
- repo: meta
8875
hooks:
8976
- id: check-hooks-apply

pyproject.toml

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,50 @@ requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]
33
build-backend = "setuptools.build_meta"
44

55

6+
[project]
7+
name = "pytask_latex"
8+
description = "Compile LaTeX documents with pytask."
9+
classifiers = [
10+
"Development Status :: 4 - Beta",
11+
"License :: OSI Approved :: MIT License",
12+
"Operating System :: OS Independent",
13+
"Programming Language :: Python :: 3",
14+
"Programming Language :: Python :: 3 :: Only"
15+
]
16+
requires-python = ">=3.8"
17+
dependencies = [ "latex-dependency-scanner>=0.1.1", "pluggy>=1.0.0", "pytask>=0.4.0"]
18+
dynamic = [ "version" ]
19+
authors = [ { name = "Tobias Raabe", email = "[email protected]"}]
20+
readme = { file = "README.md", content-type = "text/markdown"}
21+
license = { text = "MIT" }
22+
23+
[project.urls]
24+
Homepage = "https://github.com/pytask-dev/pytask-latex"
25+
Changelog = "https://github.com/pytask-dev/pytask-latex/blob/main/CHANGES.md"
26+
Documentation = "https://github.com/pytask-dev/pytask-latex"
27+
Github = "https://github.com/pytask-dev/pytask-latex"
28+
Tracker = "https://github.com/pytask-dev/pytask-latex/issues"
29+
30+
[tool.setuptools]
31+
include-package-data = true
32+
zip-safe = false
33+
platforms = [ "any",]
34+
license-files = [ "LICENSE" ]
35+
36+
[tool.check-manifest]
37+
ignore = ["src/pytask_latex/_version.py"]
38+
39+
[project.entry-points.pytask]
40+
pytask_latex = "pytask_latex.plugin"
41+
42+
[tool.setuptools.package-dir]
43+
"" = "src"
44+
45+
[tool.setuptools.packages.find]
46+
where = [ "src" ]
47+
namespaces = false
48+
49+
650
[tool.setuptools_scm]
751
write_to = "src/pytask_latex/_version.py"
852

@@ -28,9 +72,8 @@ ignore_errors = true
2872
target-version = "py38"
2973
select = ["ALL"]
3074
fix = true
75+
unsafe-fixes = true
3176
extend-ignore = [
32-
"TCH",
33-
"TRY",
3477
# Numpy docstyle
3578
"D107",
3679
"D203",
@@ -42,23 +85,17 @@ extend-ignore = [
4285
"D416",
4386
"D417",
4487
# Others.
45-
"D404", # Do not start module docstring with "This".
46-
"RET504", # unnecessary variable assignment before return.
47-
"S101", # raise errors for asserts.
48-
"B905", # strict parameter for zip that was implemented in py310.
4988
"I", # ignore isort
5089
"ANN101", # type annotating self
5190
"ANN102", # type annotating cls
52-
"FBT", # flake8-boolean-trap
53-
"EM", # flake8-errmsg
54-
"ANN401", # flake8-annotate typing.Any
55-
"PD", # pandas-vet
56-
"COM812", # trailing comma missing, but black takes care of that
91+
"ANN401", # Allow typing.Any.
92+
"COM812", # Comply with ruff-format
93+
"ISC001", # Comply with ruff-format
5794
]
5895

5996

6097
[tool.ruff.per-file-ignores]
61-
"tests/*" = ["D", "ANN", "PLR2004"]
98+
"tests/*" = ["D", "ANN", "PLR2004", "S101"]
6299

63100

64101
[tool.ruff.pydocstyle]
@@ -67,7 +104,7 @@ convention = "numpy"
67104

68105
[tool.pytest.ini_options]
69106
# Do not add src since it messes with the loading of pytask-parallel as a plugin.
70-
testpaths = ["tests"]
107+
testpaths = ["src", "tests"]
71108
markers = [
72109
"wip: Tests that are work-in-progress.",
73110
"unit: Flag for unit tests which target mainly a single function.",

setup.cfg

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/pytask_latex/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This module contains the main namespace."""
1+
"""Contains the main namespace."""
22
from __future__ import annotations
33

44
try:

src/pytask_latex/collect.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def compile_latex_document(
7575
for step in _compilation_steps:
7676
step(path_to_tex=_path_to_tex, path_to_document=_path_to_document)
7777
except CalledProcessError as e:
78-
raise RuntimeError(f"Compilation step {step.__name__} failed.") from e
78+
msg = f"Compilation step {step.__name__} failed."
79+
raise RuntimeError(msg) from e
7980

8081

8182
@hookimpl
@@ -93,10 +94,11 @@ def pytask_collect_task(
9394
# Parse the @pytask.mark.latex decorator.
9495
obj, marks = remove_marks(obj, "latex")
9596
if len(marks) > 1:
96-
raise ValueError(
97+
msg = (
9798
f"Task {name!r} has multiple @pytask.mark.latex marks, but only one is "
9899
"allowed."
99100
)
101+
raise ValueError(msg)
100102
latex_mark = marks[0]
101103
script, document, compilation_steps = latex(**latex_mark.kwargs)
102104
parsed_compilation_steps = _parse_compilation_steps(compilation_steps)
@@ -145,19 +147,21 @@ def pytask_collect_task(
145147
if not (
146148
isinstance(script_node, PathNode) and script_node.path.suffix == ".tex"
147149
):
148-
raise ValueError(
150+
msg = (
149151
"The 'script' keyword of the @pytask.mark.latex decorator must point "
150152
f"to LaTeX file with the .tex suffix, but it is {script_node}."
151153
)
154+
raise ValueError(msg)
152155

153156
if not (
154157
isinstance(document_node, PathNode)
155158
and document_node.path.suffix in (".pdf", ".ps", ".dvi")
156159
):
157-
raise ValueError(
160+
msg = (
158161
"The 'document' keyword of the @pytask.mark.latex decorator must point "
159162
"to a .pdf, .ps or .dvi file."
160163
)
164+
raise ValueError(msg)
161165

162166
compilation_steps_node = session.hook.pytask_collect_node(
163167
session=session,
@@ -283,9 +287,7 @@ def _add_latex_dependencies_retroactively(
283287
),
284288
new_deps,
285289
)
286-
task.depends_on[
287-
"_scanned_dependencies"
288-
] = collected_dependencies # type: ignore[assignment]
290+
task.depends_on["_scanned_dependencies"] = collected_dependencies
289291

290292
# Mark the task as being delayed to avoid conflicts with unmatched dependencies.
291293
task.markers.append(Mark("try_last", (), {}))
@@ -306,10 +308,11 @@ def _collect_node(
306308
session=session, path=path, node_info=node_info
307309
)
308310
if collected_node is None:
309-
raise NodeNotCollectedError(
311+
msg = (
310312
f"{node_info.arg_name!r} cannot be parsed as a dependency or product for "
311313
f"task {node_info.task_name!r} in {node_info.task_path!r}."
312314
)
315+
raise NodeNotCollectedError(msg)
313316

314317
return collected_node
315318

@@ -318,7 +321,7 @@ def _parse_compilation_steps(
318321
compilation_steps: str
319322
| Callable[..., Any]
320323
| Sequence[str | Callable[..., Any]]
321-
| None
324+
| None,
322325
) -> list[Callable[..., Any]]:
323326
"""Parse compilation steps."""
324327
__tracebackhide__ = True
@@ -331,11 +334,13 @@ def _parse_compilation_steps(
331334
try:
332335
parsed_step = getattr(cs, step)
333336
except AttributeError:
334-
raise ValueError(f"Compilation step {step!r} is unknown.") from None
337+
msg = f"Compilation step {step!r} is unknown."
338+
raise ValueError(msg) from None
335339
parsed_compilation_steps.append(parsed_step())
336340
elif callable(step):
337341
parsed_compilation_steps.append(step)
338342
else:
339-
raise ValueError(f"Compilation step {step!r} is not a valid step.")
343+
msg = f"Compilation step {step!r} is not a valid step."
344+
raise TypeError(msg)
340345

341346
return parsed_compilation_steps

src/pytask_latex/compilation_steps.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This module contains compilation steps for compiling a LaTeX document.
1+
"""Contains compilation steps for compiling a LaTeX document.
22
33
Each compilation step must have the following signature:
44
@@ -13,18 +13,24 @@ def compilation_step(path_to_tex: Path, path_to_document: Path):
1313
from __future__ import annotations
1414

1515
import subprocess
16-
from pathlib import Path
1716
from typing import Any
1817
from typing import Callable
18+
from typing import TYPE_CHECKING
1919

2020
from pytask_latex.path import relative_to
2121
from pytask_latex.utils import to_list
2222

23+
if TYPE_CHECKING:
24+
from pathlib import Path
25+
2326

2427
def latexmk(
25-
options: str
26-
| list[str]
27-
| tuple[str, ...] = ("--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd")
28+
options: str | list[str] | tuple[str, ...] = (
29+
"--pdf",
30+
"--interaction=nonstopmode",
31+
"--synctex=1",
32+
"--cd",
33+
),
2834
) -> Callable[..., Any]:
2935
"""Compilation step that calls latexmk."""
3036
options = [str(i) for i in to_list(options)]

src/pytask_latex/execute.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
def pytask_execute_task_setup(task: PTask) -> None:
1313
"""Check that latexmk is found on the PATH if a LaTeX task should be executed."""
1414
if has_mark(task, "latex") and shutil.which("latexmk") is None:
15-
raise RuntimeError(
15+
msg = (
1616
"latexmk is needed to compile LaTeX documents, but it is not found on "
1717
"your PATH."
1818
)
19+
raise RuntimeError(msg)

src/pytask_latex/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This module contains functions related to handling paths."""
1+
"""Contains functions related to handling paths."""
22
from __future__ import annotations
33

44
import os

src/pytask_latex/plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
"""Entry-point for the plugin."""
22
from __future__ import annotations
33

4-
from pluggy import PluginManager
4+
from typing import TYPE_CHECKING
5+
56
from pytask import hookimpl
67
from pytask_latex import collect
78
from pytask_latex import config
89
from pytask_latex import execute
910

11+
if TYPE_CHECKING:
12+
from pluggy import PluginManager
13+
1014

1115
@hookimpl
1216
def pytask_add_hooks(pm: PluginManager) -> None:

src/pytask_latex/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This module contains shared functions."""
1+
"""Contains shared functions."""
22
from __future__ import annotations
33

44
from typing import Any

tests/test_execute.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def test_pytask_execute_task_setup(monkeypatch):
2121
"""Make sure that the task setup raises errors."""
2222
# Act like latexmk is installed since we do not test this.
2323
monkeypatch.setattr(
24-
"pytask_latex.execute.shutil.which", lambda x: None # noqa: ARG005
24+
"pytask_latex.execute.shutil.which",
25+
lambda x: None, # noqa: ARG005
2526
)
2627
task = Task(
2728
base_name="example", path=Path(), function=None, markers=[Mark("latex", (), {})]
@@ -180,7 +181,8 @@ def task_compile_document():
180181

181182
# Hide latexmk if available.
182183
monkeypatch.setattr(
183-
"pytask_latex.execute.shutil.which", lambda x: None # noqa: ARG005
184+
"pytask_latex.execute.shutil.which",
185+
lambda x: None, # noqa: ARG005
184186
)
185187

186188
session = build(paths=tmp_path)

0 commit comments

Comments
 (0)