Skip to content

Commit 7222274

Browse files
[pre-commit.ci] pre-commit autoupdate (#43)
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 143aa77 commit 7222274

15 files changed

+82
-90
lines changed

.pre-commit-config.yaml

+6-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.4.0
3+
rev: v4.6.0
44
hooks:
55
- id: check-added-large-files
66
args: ['--maxkb=100']
@@ -17,33 +17,19 @@ repos:
1717
- id: python-no-log-warn
1818
- id: python-use-type-annotations
1919
- id: text-unicode-replacement-char
20-
- repo: https://github.com/asottile/reorder-python-imports
21-
rev: v3.12.0
22-
hooks:
23-
- id: reorder-python-imports
24-
args: [--py37-plus, --add-import, 'from __future__ import annotations']
2520
- repo: https://github.com/asottile/setup-cfg-fmt
2621
rev: v2.5.0
2722
hooks:
2823
- id: setup-cfg-fmt
29-
- repo: https://github.com/psf/black
30-
rev: 23.9.1
31-
hooks:
32-
- id: black
3324
- repo: https://github.com/astral-sh/ruff-pre-commit
34-
rev: v0.0.292
25+
rev: v0.3.7
3526
hooks:
3627
- id: ruff
28+
- id: ruff-format
3729
- repo: https://github.com/dosisod/refurb
38-
rev: v1.21.0
30+
rev: v2.0.0
3931
hooks:
4032
- id: refurb
41-
args: [--ignore, FURB126]
42-
- repo: https://github.com/econchick/interrogate
43-
rev: 1.5.0
44-
hooks:
45-
- id: interrogate
46-
args: [-v, --fail-under=40, src, tests]
4733
- repo: https://github.com/executablebooks/mdformat
4834
rev: 0.7.17
4935
hooks:
@@ -58,7 +44,7 @@ repos:
5844
hooks:
5945
- id: codespell
6046
- repo: https://github.com/pre-commit/mirrors-mypy
61-
rev: 'v1.5.1'
47+
rev: 'v1.9.0'
6248
hooks:
6349
- id: mypy
6450
additional_dependencies: [
@@ -74,7 +60,7 @@ repos:
7460
hooks:
7561
- id: check-manifest
7662
args: [--no-build-isolation]
77-
additional_dependencies: [setuptools-scm, toml]
63+
additional_dependencies: [setuptools-scm, wheel, toml]
7864
- repo: meta
7965
hooks:
8066
- id: check-hooks-apply

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ Use the `serializer` keyword arguments of the `@pytask.mark.r` decorator with
190190

191191
```python
192192
@pytask.mark.r(script="script.r", serializer="yaml")
193-
def task_example():
194-
...
193+
def task_example(): ...
195194
```
196195

197196
And in your R script use
@@ -214,8 +213,7 @@ import json
214213

215214

216215
@pytask.mark.r(script="script.r", serializer=json.dumps, suffix=".json")
217-
def task_example():
218-
...
216+
def task_example(): ...
219217
```
220218

221219
### Configuration

pyproject.toml

+10-27
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]
33
build-backend = "setuptools.build_meta"
44

5-
65
[tool.setuptools_scm]
76
write_to = "src/pytask_r/_version.py"
87

9-
108
[tool.mypy]
119
files = ["src", "tests"]
1210
check_untyped_defs = true
@@ -17,56 +15,41 @@ no_implicit_optional = true
1715
warn_redundant_casts = true
1816
warn_unused_ignores = true
1917

20-
2118
[[tool.mypy.overrides]]
2219
module = "tests.*"
2320
disallow_untyped_defs = false
2421
ignore_errors = true
2522

26-
2723
[tool.ruff]
2824
target-version = "py38"
29-
select = ["ALL"]
3025
fix = true
26+
unsafe-fixes = true
27+
28+
[tool.ruff.lint]
3129
extend-ignore = [
32-
"TCH",
33-
"TRY",
34-
# Numpy docstyle
35-
"D107",
36-
"D203",
37-
"D212",
38-
"D213",
39-
"D402",
40-
"D413",
41-
"D415",
42-
"D416",
43-
"D417",
44-
# Others.
45-
"D404", # Do not start module docstring with "This".
46-
"RET504", # unnecessary variable assignment before return.
4730
"S101", # raise errors for asserts.
4831
"B905", # strict parameter for zip that was implemented in py310.
49-
"I", # ignore isort
5032
"ANN101", # type annotating self
5133
"ANN102", # type annotating cls
5234
"FBT", # flake8-boolean-trap
5335
"EM", # flake8-errmsg
5436
"ANN401", # flake8-annotate typing.Any
5537
"PD", # pandas-vet
56-
"COM812", # trailing comma missing, but black takes care of that
38+
"COM812", # Comply with ruff-format
39+
"ISC001", # Comply with ruff-format
5740
]
41+
select = ["ALL"]
5842

59-
60-
[tool.ruff.per-file-ignores]
43+
[tool.ruff.lint.per-file-ignores]
6144
"tests/*" = ["D", "ANN"]
6245

63-
64-
[tool.ruff.pydocstyle]
46+
[tool.ruff.lint.pydocstyle]
6547
convention = "numpy"
6648

49+
[tool.ruff.lint.isort]
50+
force-single-line = true
6751

6852
[tool.pytest.ini_options]
69-
# Do not add src since it messes with the loading of pytask-parallel as a plugin.
7053
testpaths = ["tests"]
7154
markers = [
7255
"wip: Tests that are work-in-progress.",

src/pytask_r/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"""This module contains the main namespace of pytask-r."""
1+
"""Contains the main namespace of pytask-r."""
2+
23
from __future__ import annotations
34

45
try:

src/pytask_r/collect.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
"""Collect tasks."""
2+
23
from __future__ import annotations
34

45
import subprocess
56
import warnings
67
from pathlib import Path
78
from typing import Any
89

9-
from pytask import has_mark
10-
from pytask import hookimpl
11-
from pytask import is_task_function
1210
from pytask import Mark
1311
from pytask import NodeInfo
14-
from pytask import parse_dependencies_from_task_function
15-
from pytask import parse_products_from_task_function
1612
from pytask import PathNode
1713
from pytask import PTask
1814
from pytask import PythonNode
19-
from pytask import remove_marks
2015
from pytask import Session
2116
from pytask import Task
2217
from pytask import TaskWithoutPath
23-
from pytask_r.serialization import create_path_to_serialized
18+
from pytask import has_mark
19+
from pytask import hookimpl
20+
from pytask import is_task_function
21+
from pytask import parse_dependencies_from_task_function
22+
from pytask import parse_products_from_task_function
23+
from pytask import remove_marks
24+
2425
from pytask_r.serialization import SERIALIZERS
26+
from pytask_r.serialization import create_path_to_serialized
2527
from pytask_r.shared import r
2628

2729

2830
def run_r_script(
29-
_script: Path, _options: list[str], _serialized: Path, **kwargs: Any # noqa: ARG001
31+
_script: Path,
32+
_options: list[str],
33+
_serialized: Path,
34+
**kwargs: Any, # noqa: ARG001
3035
) -> None:
3136
"""Run an R script."""
3237
cmd = ["Rscript", _script.as_posix(), *_options, str(_serialized)]
@@ -49,10 +54,11 @@ def pytask_collect_task(
4954
# Parse @pytask.mark.r decorator.
5055
obj, marks = remove_marks(obj, "r")
5156
if len(marks) > 1:
52-
raise ValueError(
57+
msg = (
5358
f"Task {name!r} has multiple @pytask.mark.r marks, but only one is "
5459
"allowed."
5560
)
61+
raise ValueError(msg)
5662

5763
mark = _parse_r_mark(
5864
mark=marks[0],
@@ -88,10 +94,11 @@ def pytask_collect_task(
8894
)
8995

9096
if not (isinstance(script_node, PathNode) and script_node.path.suffix == ".r"):
91-
raise ValueError(
97+
msg = (
9298
"The 'script' keyword of the @pytask.mark.r decorator must point "
9399
f"to Julia file with the .r suffix, but it is {script_node}."
94100
)
101+
raise ValueError(msg)
95102

96103
options_node = session.hook.pytask_collect_node(
97104
session=session,
@@ -181,5 +188,4 @@ def _parse_r_mark(
181188
)
182189
parsed_kwargs["suffix"] = suffix or proposed_suffix # type: ignore[assignment]
183190

184-
mark = Mark("r", (), parsed_kwargs)
185-
return mark
191+
return Mark("r", (), parsed_kwargs)

src/pytask_r/config.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""Configure pytask."""
2+
23
from __future__ import annotations
34

45
from typing import Any
56

67
from pytask import hookimpl
8+
79
from pytask_r.serialization import SERIALIZERS
810

911

@@ -13,10 +15,11 @@ def pytask_parse_config(config: dict[str, Any]) -> None:
1315
config["markers"]["r"] = "Tasks which are executed with Rscript."
1416
config["r_serializer"] = config.get("r_serializer", "json")
1517
if config["r_serializer"] not in SERIALIZERS:
16-
raise ValueError(
18+
msg = (
1719
f"'r_serializer' is {config['r_serializer']} and not one of "
1820
f"{list(SERIALIZERS)}."
1921
)
22+
raise ValueError(msg)
2023
config["r_suffix"] = config.get("r_suffix", "")
2124
config["r_options"] = _parse_value_or_whitespace_option(config.get("r_options"))
2225

@@ -27,4 +30,5 @@ def _parse_value_or_whitespace_option(value: Any) -> list[str] | None:
2730
return None
2831
if isinstance(value, list):
2932
return list(map(str, value))
30-
raise ValueError(f"'r_options' is {value} and not a list.")
33+
msg = f"'r_options' is {value} and not a list."
34+
raise ValueError(msg)

src/pytask_r/execute.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
"""Execute tasks."""
2+
23
from __future__ import annotations
34

45
import shutil
56
from typing import Any
67

7-
from pytask import get_marks
8-
from pytask import hookimpl
98
from pytask import PPathNode
109
from pytask import PTask
1110
from pytask import PythonNode
11+
from pytask import get_marks
12+
from pytask import hookimpl
1213
from pytask.tree_util import tree_map
14+
1315
from pytask_r.serialization import serialize_keyword_arguments
1416
from pytask_r.shared import r
1517

@@ -20,9 +22,10 @@ def pytask_execute_task_setup(task: PTask) -> None:
2022
marks = get_marks(task, "r")
2123
if marks:
2224
if shutil.which("Rscript") is None:
23-
raise RuntimeError(
25+
msg = (
2426
"Rscript is needed to run R scripts, but it is not found on your PATH."
2527
)
28+
raise RuntimeError(msg)
2629

2730
assert len(marks) == 1
2831

@@ -31,9 +34,9 @@ def pytask_execute_task_setup(task: PTask) -> None:
3134
assert suffix
3235

3336
serialized_node: PythonNode = task.depends_on["_serialized"] # type: ignore[assignment]
34-
serialized_node.value.parent.mkdir(parents=True, exist_ok=True)
37+
serialized_node.value.parent.mkdir(parents=True, exist_ok=True) # type: ignore[union-attr]
3538
kwargs = collect_keyword_arguments(task)
36-
serialize_keyword_arguments(serializer, serialized_node.value, kwargs)
39+
serialize_keyword_arguments(serializer, serialized_node.value, kwargs) # type: ignore[arg-type]
3740

3841

3942
def collect_keyword_arguments(task: PTask) -> dict[str, Any]:

src/pytask_r/plugin.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
"""Register hook specifications and implementations."""
2+
23
from __future__ import annotations
34

4-
from pluggy import PluginManager
5+
from typing import TYPE_CHECKING
6+
57
from pytask import hookimpl
8+
69
from pytask_r import collect
710
from pytask_r import config
811
from pytask_r import execute
912

13+
if TYPE_CHECKING:
14+
from pluggy import PluginManager
15+
1016

1117
@hookimpl
1218
def pytask_add_hooks(pm: PluginManager) -> None:

src/pytask_r/serialization.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"""This module contains the code to serialize keyword arguments to the task."""
1+
"""Contains the code to serialize keyword arguments to the task."""
2+
23
from __future__ import annotations
34

45
import json
@@ -9,7 +10,6 @@
910
from pytask import PTask
1011
from pytask import PTaskWithPath
1112

12-
1313
_HIDDEN_FOLDER = ".pytask/pytask-r"
1414

1515

@@ -29,8 +29,7 @@ def create_path_to_serialized(task: PTask, suffix: str) -> Path:
2929
"""Create path to serialized."""
3030
parent = task.path.parent if isinstance(task, PTaskWithPath) else Path.cwd()
3131
file_name = create_file_name(task, suffix)
32-
path = parent.joinpath(_HIDDEN_FOLDER, file_name).with_suffix(suffix)
33-
return path
32+
return parent.joinpath(_HIDDEN_FOLDER, file_name).with_suffix(suffix)
3433

3534

3635
def create_file_name(task: PTask, suffix: str) -> str:
@@ -59,11 +58,10 @@ def serialize_keyword_arguments(
5958
if callable(serializer):
6059
serializer_func = serializer
6160
elif isinstance(serializer, str) and serializer in SERIALIZERS:
62-
serializer_func = SERIALIZERS[serializer][
63-
"serializer"
64-
] # type: ignore[assignment]
61+
serializer_func = SERIALIZERS[serializer]["serializer"] # type: ignore[assignment]
6562
else:
66-
raise ValueError(f"Serializer {serializer!r} is not known.")
63+
msg = f"Serializer {serializer!r} is not known."
64+
raise ValueError(msg)
6765

6866
serialized = serializer_func(kwargs)
6967
path_to_serialized.write_text(serialized)

0 commit comments

Comments
 (0)