Skip to content

Commit 8a96d4c

Browse files
Add ruff and refurb. (#24)
1 parent ff32f7c commit 8a96d4c

12 files changed

+135
-103
lines changed

.pre-commit-config.yaml

+62-60
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.2.0
3+
rev: v4.4.0
44
hooks:
55
- id: check-added-large-files
6-
args: ['--maxkb=25']
6+
args:
7+
- --maxkb=25
78
- id: check-case-conflict
89
- id: check-merge-conflict
910
- id: check-vcs-permalinks
@@ -13,101 +14,102 @@ repos:
1314
- id: fix-byte-order-marker
1415
- id: mixed-line-ending
1516
- id: no-commit-to-branch
16-
args: [--branch, main]
17+
args:
18+
- --branch
19+
- main
1720
- id: trailing-whitespace
1821
- repo: https://github.com/pre-commit/pygrep-hooks
19-
rev: v1.9.0
22+
rev: v1.10.0
2023
hooks:
2124
- id: python-check-blanket-noqa
2225
- id: python-check-mock-methods
2326
- id: python-no-eval
2427
- id: python-no-log-warn
2528
- id: python-use-type-annotations
2629
- id: text-unicode-replacement-char
27-
- repo: https://github.com/asottile/pyupgrade
28-
rev: v2.32.0
29-
hooks:
30-
- id: pyupgrade
31-
args: [--py37-plus]
3230
- repo: https://github.com/asottile/reorder_python_imports
33-
rev: v3.0.1
31+
rev: v3.9.0
3432
hooks:
3533
- id: reorder-python-imports
36-
args: [--py37-plus, --add-import, 'from __future__ import annotations']
34+
args:
35+
- --py37-plus
36+
- --add-import
37+
- from __future__ import annotations
3738
- repo: https://github.com/asottile/setup-cfg-fmt
38-
rev: v1.20.1
39+
rev: v2.2.0
3940
hooks:
4041
- id: setup-cfg-fmt
41-
- repo: https://github.com/myint/docformatter
42-
rev: v1.3.1
42+
- repo: https://github.com/PyCQA/docformatter
43+
rev: v1.6.0.rc1
4344
hooks:
4445
- id: docformatter
45-
args: [--in-place, --wrap-summaries, "88", --wrap-descriptions, "88", --blank]
46+
args:
47+
- --in-place
48+
- --wrap-summaries
49+
- '88'
50+
- --wrap-descriptions
51+
- '88'
52+
- --blank
4653
- repo: https://github.com/psf/black
47-
rev: 22.3.0
54+
rev: 22.12.0
4855
hooks:
4956
- id: black
50-
- repo: https://github.com/PyCQA/flake8
51-
rev: 4.0.1
57+
- repo: https://github.com/charliermarsh/ruff-pre-commit
58+
rev: v0.0.228
59+
hooks:
60+
- id: ruff
61+
- repo: https://github.com/dosisod/refurb
62+
rev: v1.10.0
5263
hooks:
53-
- id: flake8
54-
types: [python]
55-
additional_dependencies: [
56-
flake8-alfred,
57-
flake8-bugbear,
58-
flake8-builtins,
59-
flake8-comprehensions,
60-
flake8-docstrings,
61-
flake8-eradicate,
62-
flake8-print,
63-
flake8-pytest-style,
64-
flake8-todo,
65-
flake8-typing-imports,
66-
flake8-unused-arguments,
67-
pep8-naming,
68-
pydocstyle,
69-
Pygments,
70-
]
64+
- id: refurb
65+
args:
66+
- --ignore
67+
- FURB126
7168
- repo: https://github.com/econchick/interrogate
7269
rev: 1.5.0
7370
hooks:
7471
- id: interrogate
75-
args: [-v, --fail-under=40, src, tests]
72+
args:
73+
- -v
74+
- --fail-under=40
75+
- src
76+
- tests
7677
- repo: https://github.com/executablebooks/mdformat
77-
rev: 0.7.14
78+
rev: 0.7.16
7879
hooks:
7980
- id: mdformat
80-
additional_dependencies: [
81-
mdformat-gfm,
82-
mdformat-black,
83-
]
84-
args: [--wrap, "88"]
85-
- repo: https://github.com/codespell-project/codespell
86-
rev: v2.1.0
87-
hooks:
81+
additional_dependencies:
82+
- mdformat-gfm
83+
- mdformat-black
84+
args:
85+
- --wrap
86+
- '88'
87+
- repo: https://github.com/codespell-project/codespell
88+
rev: v2.2.2
89+
hooks:
8890
- id: codespell
8991
- repo: https://github.com/pre-commit/mirrors-mypy
90-
rev: 'v0.931'
92+
rev: v0.991
9193
hooks:
9294
- id: mypy
93-
args: [
94-
--no-strict-optional,
95-
--ignore-missing-imports,
96-
]
97-
additional_dependencies: [
98-
attrs,
99-
click,
100-
types-setuptools
101-
]
95+
args:
96+
- --no-strict-optional
97+
- --ignore-missing-imports
98+
additional_dependencies:
99+
- attrs
100+
- click
101+
- types-setuptools
102102
pass_filenames: false
103103
- repo: https://github.com/mgedmin/check-manifest
104-
rev: "0.48"
104+
rev: '0.49'
105105
hooks:
106106
- id: check-manifest
107-
args: [--no-build-isolation]
108-
additional_dependencies: [setuptools-scm, toml]
107+
args:
108+
- --no-build-isolation
109+
additional_dependencies:
110+
- setuptools-scm
111+
- toml
109112
- repo: meta
110113
hooks:
111114
- id: check-hooks-apply
112115
- id: check-useless-excludes
113-
# - id: identity # Prints all files passed to pre-commits. Debugging.

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask-stata) and
77

88
## 0.3.0 - 2023-xx-xx
99

10+
- {pull}`24` adds ruff and refurb.
1011
- {pull}`25` adds docformatter.
1112
- {pull}`26` adds Python 3.11 to CI.
1213
- {pull}`28` aligns the package with pytask v0.3.

pyproject.toml

+40
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,43 @@ warn_unused_ignores = true
2222
module = "tests.*"
2323
disallow_untyped_defs = false
2424
ignore_errors = true
25+
26+
27+
[tool.ruff]
28+
target-version = "py37"
29+
select = ["ALL"]
30+
fix = true
31+
extend-ignore = [
32+
# Numpy docstyle
33+
"D107",
34+
"D203",
35+
"D212",
36+
"D213",
37+
"D402",
38+
"D413",
39+
"D415",
40+
"D416",
41+
"D417",
42+
# Others.
43+
"D404", # Do not start module docstring with "This".
44+
"RET504", # unnecessary variable assignment before return.
45+
"S101", # raise errors for asserts.
46+
"B905", # strict parameter for zip that was implemented in py310.
47+
"I", # ignore isort
48+
"ANN101", # type annotating self
49+
"ANN102", # type annotating cls
50+
"FBT", # flake8-boolean-trap
51+
"EM", # flake8-errmsg
52+
"ANN401", # flake8-annotate typing.Any
53+
"PD", # pandas-vet
54+
"COM812", # trailing comma missing, but black takes care of that
55+
]
56+
57+
58+
[tool.ruff.per-file-ignores]
59+
"tests/*" = ["D", "ANN"]
60+
"__init__.py" = ["D104"]
61+
62+
63+
[tool.ruff.pydocstyle]
64+
convention = "numpy"

setup.cfg

-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ classifiers =
1515
Operating System :: OS Independent
1616
Programming Language :: Python :: 3
1717
Programming Language :: Python :: 3 :: Only
18-
Programming Language :: Python :: 3.7
19-
Programming Language :: Python :: 3.8
20-
Programming Language :: Python :: 3.9
21-
Programming Language :: Python :: 3.10
2218
project_urls =
2319
Documentation = https://github.com/pytask-dev/pytask-stata
2420
Github = https://github.com/pytask-dev/pytask-stata

src/pytask_stata/collect.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def pytask_collect_task(
6363
task = Task(
6464
base_name=name,
6565
path=path,
66-
function=_copy_func(run_stata_script), # type: ignore
66+
function=_copy_func(run_stata_script), # type: ignore[arg-type]
6767
depends_on=dependencies,
6868
produces=products,
6969
markers=markers,
@@ -97,20 +97,14 @@ def pytask_collect_task(
9797
task.function = stata_function
9898

9999
return task
100-
else:
101-
return None
100+
return None
102101

103102

104103
def _parse_stata_mark(mark: Mark) -> Mark:
105104
"""Parse a Stata mark."""
106105
script, options = stata(**mark.kwargs)
107106

108-
parsed_kwargs = {}
109-
for arg_name, value, default in [ # type: ignore
110-
("script", script, None),
111-
("options", options, []),
112-
]:
113-
parsed_kwargs[arg_name] = value if value else default
107+
parsed_kwargs = {"script": script or None, "options": options or []}
114108

115109
mark = Mark("stata", (), parsed_kwargs)
116110
return mark

src/pytask_stata/parametrize.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@
1111
@hookimpl
1212
def pytask_parametrize_kwarg_to_marker(obj: Callable[..., Any], kwargs: Any) -> None:
1313
"""Attach parametrized stata arguments to the function with a marker."""
14-
if callable(obj):
15-
if "stata" in kwargs:
16-
pytask.mark.stata(**kwargs.pop("stata"))(obj)
14+
if callable(obj) and "stata" in kwargs:
15+
pytask.mark.stata(**kwargs.pop("stata"))(obj)

tests/test_collect.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from pytask_stata.collect import stata
99

1010

11-
@pytest.mark.unit
11+
@pytest.mark.unit()
1212
@pytest.mark.parametrize(
13-
"args, kwargs, expectation, expected",
13+
("args", "kwargs", "expectation", "expected"),
1414
[
1515
(
1616
(),
@@ -32,9 +32,9 @@ def test_stata(args, kwargs, expectation, expected):
3232
assert options == expected
3333

3434

35-
@pytest.mark.unit
35+
@pytest.mark.unit()
3636
@pytest.mark.parametrize(
37-
"mark, expectation, expected",
37+
("mark", "expectation", "expected"),
3838
[
3939
(
4040
Mark("stata", (), {"script": "script.do"}),

tests/test_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pytask import main
55

66

7-
@pytest.mark.end_to_end
7+
@pytest.mark.end_to_end()
88
def test_marker_is_configured(tmp_path):
99
session = main({"paths": tmp_path})
1010

tests/test_execute.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
from tests.conftest import needs_stata
1919

2020

21-
@pytest.mark.unit
21+
@pytest.mark.unit()
2222
@pytest.mark.parametrize(
23-
"stata, expectation",
23+
("stata", "expectation"),
2424
[(executable, does_not_raise()) for executable in STATA_COMMANDS]
2525
+ [(None, pytest.raises(RuntimeError, match="Stata is needed"))],
2626
)
@@ -42,7 +42,7 @@ def test_pytask_execute_task_setup_raise_error(stata, platform, expectation):
4242

4343

4444
@needs_stata
45-
@pytest.mark.end_to_end
45+
@pytest.mark.end_to_end()
4646
def test_run_do_file(runner, tmp_path):
4747
task_source = """
4848
import pytask
@@ -72,7 +72,7 @@ def task_run_do_file():
7272

7373

7474
@needs_stata
75-
@pytest.mark.end_to_end
75+
@pytest.mark.end_to_end()
7676
def test_run_do_file_w_task_decorator(runner, tmp_path):
7777
task_source = """
7878
import pytask
@@ -102,7 +102,7 @@ def run_do_file():
102102
assert tmp_path.joinpath("script.log").exists()
103103

104104

105-
@pytest.mark.end_to_end
105+
@pytest.mark.end_to_end()
106106
def test_raise_error_if_stata_is_not_found(tmp_path, monkeypatch):
107107
task_source = """
108108
import pytask
@@ -117,7 +117,7 @@ def task_run_do_file():
117117

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

123123
session = main({"paths": tmp_path})
@@ -127,7 +127,7 @@ def task_run_do_file():
127127

128128

129129
@needs_stata
130-
@pytest.mark.end_to_end
130+
@pytest.mark.end_to_end()
131131
def test_run_do_file_w_wrong_cmd_option(runner, tmp_path):
132132
"""Apparently, Stata simply discards wrong cmd options."""
133133
task_source = """
@@ -152,7 +152,7 @@ def task_run_do_file():
152152

153153

154154
@needs_stata
155-
@pytest.mark.end_to_end
155+
@pytest.mark.end_to_end()
156156
def test_run_do_file_by_passing_path(runner, tmp_path):
157157
"""Replicates example under "Command Line Arguments" in Readme."""
158158
task_source = """
@@ -178,7 +178,7 @@ def task_run_do_file():
178178

179179

180180
@needs_stata
181-
@pytest.mark.end_to_end
181+
@pytest.mark.end_to_end()
182182
def test_run_do_file_fails_with_multiple_marks(runner, tmp_path):
183183
task_source = """
184184
import pytask

tests/test_normal_execution_w_plugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pytask import cli
88

99

10-
@pytest.mark.end_to_end
10+
@pytest.mark.end_to_end()
1111
@pytest.mark.parametrize(
1212
"dependencies",
1313
[[], ["in.txt"], ["in_1.txt", "in_2.txt"]],

0 commit comments

Comments
 (0)