Skip to content

Commit 7f0050c

Browse files
committed
FIx.
1 parent 233e1e9 commit 7f0050c

11 files changed

+44
-120
lines changed

.pre-commit-config.yaml

+5-64
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ repos:
33
rev: v4.6.0
44
hooks:
55
- id: check-added-large-files
6-
args:
7-
- --maxkb=25
6+
args: [--maxkb=25]
87
- id: check-case-conflict
98
- id: check-merge-conflict
109
- id: check-vcs-permalinks
@@ -14,9 +13,7 @@ repos:
1413
- id: fix-byte-order-marker
1514
- id: mixed-line-ending
1615
- id: no-commit-to-branch
17-
args:
18-
- --branch
19-
- main
16+
args: [--branch, main]
2017
- id: trailing-whitespace
2118
- repo: https://github.com/pre-commit/pygrep-hooks
2219
rev: v1.10.0
@@ -27,89 +24,33 @@ repos:
2724
- id: python-no-log-warn
2825
- id: python-use-type-annotations
2926
- id: text-unicode-replacement-char
30-
- repo: https://github.com/asottile/reorder-python-imports
31-
rev: v3.12.0
32-
hooks:
33-
- id: reorder-python-imports
34-
args:
35-
- --py38-plus
36-
- --add-import
37-
- from __future__ import annotations
3827
- repo: https://github.com/asottile/setup-cfg-fmt
3928
rev: v2.5.0
4029
hooks:
4130
- id: setup-cfg-fmt
42-
- repo: https://github.com/PyCQA/docformatter
43-
rev: v1.7.5
44-
hooks:
45-
- id: docformatter
46-
args:
47-
- --in-place
48-
- --wrap-summaries
49-
- '88'
50-
- --wrap-descriptions
51-
- '88'
52-
- --blank
53-
- repo: https://github.com/psf/black
54-
rev: 24.4.2
55-
hooks:
56-
- id: black
5731
- repo: https://github.com/astral-sh/ruff-pre-commit
5832
rev: v0.4.4
5933
hooks:
6034
- id: ruff
35+
- id: ruff-format
6136
- repo: https://github.com/dosisod/refurb
6237
rev: v2.0.0
6338
hooks:
6439
- id: refurb
65-
args:
66-
- --ignore
67-
- FURB126
68-
- repo: https://github.com/econchick/interrogate
69-
rev: 1.7.0
70-
hooks:
71-
- id: interrogate
72-
args:
73-
- -v
74-
- --fail-under=40
75-
- src
76-
- tests
7740
- repo: https://github.com/executablebooks/mdformat
7841
rev: 0.7.17
7942
hooks:
8043
- id: mdformat
8144
additional_dependencies:
8245
- mdformat-gfm
8346
- mdformat-black
84-
args:
85-
- --wrap
86-
- '88'
47+
args: [--wrap, "88"]
8748
- repo: https://github.com/codespell-project/codespell
8849
rev: v2.2.6
8950
hooks:
9051
- id: codespell
91-
- repo: https://github.com/pre-commit/mirrors-mypy
92-
rev: v1.10.0
93-
hooks:
94-
- id: mypy
95-
args:
96-
- --no-strict-optional
97-
- --ignore-missing-imports
98-
additional_dependencies:
99-
- attrs
100-
- click
101-
- types-setuptools
102-
pass_filenames: false
103-
- repo: https://github.com/mgedmin/check-manifest
104-
rev: '0.49'
105-
hooks:
106-
- id: check-manifest
107-
args:
108-
- --no-build-isolation
109-
additional_dependencies:
110-
- setuptools-scm
111-
- toml
11252
- repo: meta
11353
hooks:
11454
- id: check-hooks-apply
11555
- id: check-useless-excludes
56+
# - id: identity # Prints all files passed to pre-commits. Debugging.

pyproject.toml

+15-35
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_stata/_version.py"
87

9-
108
[tool.mypy]
119
files = ["src", "tests"]
1210
check_untyped_defs = true
@@ -17,54 +15,36 @@ 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
31-
extend-ignore = [
32-
"I", # ignore isort
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.
47-
"S101", # raise errors for asserts.
48-
"B905", # strict parameter for zip that was implemented in py310.
49-
"ANN101", # type annotating self
50-
"ANN102", # type annotating cls
51-
"FBT", # flake8-boolean-trap
52-
"EM", # flake8-errmsg
53-
"ANN401", # flake8-annotate typing.Any
54-
"PD", # pandas-vet
55-
"COM812", # trailing comma missing, but black takes care of that
56-
]
26+
unsafe-fixes = true
5727

28+
[tool.ruff.lint]
29+
select = ["ALL"]
30+
ignore = [
31+
"ANN101",
32+
"ANN102",
33+
"ANN401", # flake8-annotate typing.Any
34+
"COM812", # Comply with ruff-format.
35+
"ISC001", # Comply with ruff-format.
36+
]
5837

59-
[tool.ruff.per-file-ignores]
60-
"tests/*" = ["D", "ANN"]
38+
[tool.ruff.lint.per-file-ignores]
39+
"tests/*" = ["D", "ANN", "S101"]
6140
"__init__.py" = ["D104"]
6241

42+
[tool.ruff.lint.isort]
43+
force-single-line = true
6344

64-
[tool.ruff.pydocstyle]
45+
[tool.ruff.lint.pydocstyle]
6546
convention = "numpy"
6647

67-
6848
[tool.pytest.ini_options]
6949
# Do not add src since it messes with the loading of pytask-parallel as a plugin.
7050
testpaths = ["tests"]

src/pytask_stata/collect.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
import functools
66
import subprocess
77
from types import FunctionType
8-
from typing import Any
98
from typing import TYPE_CHECKING
9+
from typing import Any
1010

11+
from pytask import Mark
12+
from pytask import Session
13+
from pytask import Task
1114
from pytask import depends_on
1215
from pytask import has_mark
1316
from pytask import hookimpl
14-
from pytask import Mark
1517
from pytask import parse_nodes
1618
from pytask import produces
1719
from pytask import remove_marks
18-
from pytask import Session
19-
from pytask import Task
20+
2021
from pytask_stata.shared import convert_task_id_to_name_of_log_file
2122
from pytask_stata.shared import stata
2223

@@ -48,10 +49,11 @@ def pytask_collect_task(
4849
obj, marks = remove_marks(obj, "stata")
4950

5051
if len(marks) > 1:
51-
raise ValueError(
52+
msg = (
5253
f"Task {name!r} has multiple @pytask.mark.stata marks, but only one is "
5354
"allowed."
5455
)
56+
raise ValueError(msg)
5557

5658
mark = _parse_stata_mark(mark=marks[0])
5759
script, options = stata(**marks[0].kwargs)
@@ -110,8 +112,7 @@ def _parse_stata_mark(mark: Mark) -> Mark:
110112

111113
parsed_kwargs = {"script": script or None, "options": options or []}
112114

113-
mark = Mark("stata", (), parsed_kwargs)
114-
return mark
115+
return Mark("stata", (), parsed_kwargs)
115116

116117

117118
def _copy_func(func: FunctionType) -> FunctionType:

src/pytask_stata/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Any
88

99
from pytask import hookimpl
10+
1011
from pytask_stata.shared import STATA_COMMANDS
1112

1213

src/pytask_stata/execute.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@
44

55
import re
66

7-
from pytask import has_mark
8-
from pytask import hookimpl
97
from pytask import Session
108
from pytask import Task
11-
from pytask_stata.shared import convert_task_id_to_name_of_log_file
9+
from pytask import has_mark
10+
from pytask import hookimpl
11+
1212
from pytask_stata.shared import STATA_COMMANDS
13+
from pytask_stata.shared import convert_task_id_to_name_of_log_file
1314

1415

1516
@hookimpl
1617
def pytask_execute_task_setup(session: Session, task: Task) -> None:
1718
"""Check if Stata is found on the PATH."""
1819
if has_mark(task, "stata") and session.config["stata"] is None:
19-
raise RuntimeError(
20+
msg = (
2021
"Stata is needed to run do-files, but it is not found on your PATH.\n\n"
2122
f"We are looking for one of {STATA_COMMANDS} on your PATH. If you have a"
2223
"different Stata executable, please, file an issue at "
2324
"https://github.com/pytask-dev/pytask-stata."
2425
)
26+
raise RuntimeError(msg)
2527

2628

2729
@hookimpl

src/pytask_stata/plugin.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import TYPE_CHECKING
66

77
from _pytask.config import hookimpl
8+
89
from pytask_stata import cli
910
from pytask_stata import collect
1011
from pytask_stata import config

src/pytask_stata/shared.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from __future__ import annotations
44

55
import sys
6+
from typing import TYPE_CHECKING
67
from typing import Any
78
from typing import Iterable
89
from typing import Sequence
9-
from typing import TYPE_CHECKING
1010

1111
if TYPE_CHECKING:
1212
from pathlib import Path
@@ -79,9 +79,7 @@ def convert_task_id_to_name_of_log_file(id_: str) -> str:
7979
'task_example_py_task_example[arg1]'
8080
8181
"""
82-
id_without_parent_directories = id_.rsplit("/")[-1]
83-
converted_id = id_without_parent_directories.replace(".", "_").replace("::", "_")
84-
return converted_id
82+
return id_.rsplit("/")[-1].replace(".", "_").replace("::", "_")
8583

8684

8785
def _to_list(scalar_or_iter: Any) -> list[Any]:

tests/conftest.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from click.testing import CliRunner
77
from pytask_stata.config import STATA_COMMANDS
88

9-
109
needs_stata = pytest.mark.skipif(
1110
next(
1211
(executable for executable in STATA_COMMANDS if shutil.which(executable)), None

tests/test_execute.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
from pathlib import Path
77

88
import pytest
9-
from pytask import cli
109
from pytask import ExitCode
11-
from pytask import main
1210
from pytask import Mark
1311
from pytask import Session
1412
from pytask import Task
13+
from pytask import cli
14+
from pytask import main
1515
from pytask_stata.config import STATA_COMMANDS
1616
from pytask_stata.execute import pytask_execute_task_setup
1717

@@ -117,7 +117,8 @@ def task_run_do_file():
117117

118118
# Hide Stata if available.
119119
monkeypatch.setattr(
120-
"pytask_stata.config.shutil.which", lambda x: None # noqa: ARG005
120+
"pytask_stata.config.shutil.which",
121+
lambda x: None, # noqa: ARG005
121122
)
122123

123124
session = main({"paths": tmp_path})

tests/test_parallel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import time
77

88
import pytest
9-
from pytask import cli
109
from pytask import ExitCode
10+
from pytask import cli
1111

1212
from tests.conftest import needs_stata
1313

tests/test_parametrize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import textwrap
55

66
import pytest
7-
from pytask import cli
87
from pytask import ExitCode
8+
from pytask import cli
99

1010
from tests.conftest import needs_stata
1111

0 commit comments

Comments
 (0)