Skip to content

Commit f9c4fb6

Browse files
authored
Allow more ruff rules. (#414)
1 parent 5c9c59a commit f9c4fb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+296
-260
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
python-version: ['3.8', '3.9', '3.10', '3.11']
3131

3232
steps:
33-
- uses: actions/checkout@v3
33+
- uses: actions/checkout@v4
3434
- uses: mamba-org/setup-micromamba@v1
3535
with:
3636
environment-name: gha-testing

.github/workflows/publish-to-pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
name: Build and publish Python 🐍 distributions 📦 to PyPI
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v4
1111

1212
- name: Set up Python 3.8
1313
uses: actions/setup-python@v4

.github/workflows/update-plugin-list.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
steps:
2121
- name: Checkout
22-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
2323
with:
2424
fetch-depth: 0
2525

docs/source/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
3030
- {pull}`410` allows to pass functions to `PythonNode(hash=...)`.
3131
- {pull}`412` adds protocols for tasks.
3232
- {pull}`413` removes scripts to generate `.svg`s.
33+
- {pull}`414` allow more ruff rules.
3334

3435
## 0.3.2 - 2023-06-07
3536

docs/source/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
from __future__ import annotations
88

99
from importlib.metadata import version
10+
from typing import TYPE_CHECKING
1011

11-
import sphinx
12+
if TYPE_CHECKING:
13+
import sphinx
1214

1315

1416
# -- Project information ---------------------------------------------------------------

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515
- click
1616
- click-default-group
1717
- networkx >=2.4
18-
- pluggy
18+
- pluggy >=1.0.0
1919
- optree >=0.9
2020
- rich
2121
- sqlalchemy >=1.4.36

pyproject.toml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ target-version = "py38"
3333
select = ["ALL"]
3434
fix = true
3535
extend-ignore = [
36+
"I", # ignore isort
3637
"TRY", # ignore tryceratops.
37-
"TCH", # ignore non-guarded type imports.
3838
# Numpy docstyle
3939
"D107",
4040
"D203",
@@ -46,25 +46,17 @@ extend-ignore = [
4646
"D416",
4747
"D417",
4848
# Others.
49-
"D404", # Do not start module docstring with "This".
50-
"RET504", # unnecessary variable assignment before return.
5149
"S101", # raise errors for asserts.
52-
"B905", # strict parameter for zip that was implemented in py310.
53-
"I", # ignore isort
5450
"ANN101", # type annotating self
5551
"ANN102", # type annotating cls
5652
"FBT", # flake8-boolean-trap
57-
"EM", # flake8-errmsg
5853
"ANN401", # flake8-annotate typing.Any
5954
"PD", # pandas-vet
6055
"COM812", # trailing comma missing, but black takes care of that
6156
"D401", # imperative mood for first line. too many false-positives.
6257
"SLF001", # access private members.
6358
"S603",
6459
"S607",
65-
# Temporary
66-
"TD002",
67-
"TD003",
6860
]
6961

7062

@@ -73,7 +65,7 @@ extend-ignore = [
7365
"src/_pytask/hookspecs.py" = ["ARG001"]
7466
"src/_pytask/outcomes.py" = ["N818"]
7567
"tests/test_capture.py" = ["T201", "PT011"]
76-
"tests/*" = ["D", "ANN", "PLR2004"]
68+
"tests/*" = ["D", "ANN", "PLR2004", "S101"]
7769
"scripts/*" = ["D", "INP001"]
7870
"docs/source/conf.py" = ["D401", "INP001"]
7971

scripts/update_plugin_list.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ def _escape_rst(text: str) -> str:
8181
.replace(">", "\\>")
8282
.replace("`", "\\`")
8383
)
84-
text = re.sub(r"_\b", "", text)
85-
return text
84+
return re.sub(r"_\b", "", text)
8685

8786

8887
def _iter_plugins() -> Generator[dict[str, str], None, None]: # noqa: C901

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ install_requires =
3636
networkx>=2.4
3737
optree>=0.9
3838
packaging
39-
pluggy
39+
pluggy>=1.0.0
4040
rich
4141
sqlalchemy>=1.4.36
4242
tomli>=1.0.0

src/_pytask/_inspect.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,15 @@ def get_annotations( # noqa: C901, PLR0912, PLR0915
9999
obj_locals = None
100100
unwrap = obj
101101
else:
102-
raise TypeError(f"{obj!r} is not a module, class, or callable.")
102+
msg = f"{obj!r} is not a module, class, or callable."
103+
raise TypeError(msg)
103104

104105
if ann is None:
105106
return {}
106107

107108
if not isinstance(ann, dict):
108-
raise ValueError(f"{obj!r}.__annotations__ is neither a dict nor None")
109+
msg = f"{obj!r}.__annotations__ is neither a dict nor None"
110+
raise ValueError(msg)
109111

110112
if not ann:
111113
return {}
@@ -131,10 +133,9 @@ def get_annotations( # noqa: C901, PLR0912, PLR0915
131133
locals = obj_locals # noqa: A001
132134

133135
eval_func = eval
134-
return_value = {
136+
return {
135137
key: value
136138
if not isinstance(value, str)
137139
else eval_func(value, globals, locals)
138140
for key, value in ann.items()
139141
}
140-
return return_value

src/_pytask/capture.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@
3939
from typing import Generic
4040
from typing import Iterator
4141
from typing import TextIO
42+
from typing import TYPE_CHECKING
4243

4344
import click
4445
from _pytask.click import EnumChoice
4546
from _pytask.config import hookimpl
4647
from _pytask.enums import ShowCapture
47-
from _pytask.node_protocols import PTask
48+
49+
if TYPE_CHECKING:
50+
from _pytask.node_protocols import PTask
4851

4952

5053
class _CaptureMethod(enum.Enum):
@@ -148,9 +151,10 @@ class DontReadFromInput:
148151
encoding = None
149152

150153
def read(self, *_args: Any) -> None:
151-
raise OSError(
154+
msg = (
152155
"pytask: reading from stdin while output is captured! Consider using `-s`."
153156
)
157+
raise OSError(msg)
154158

155159
readline = read
156160
readlines = read
@@ -160,10 +164,12 @@ def __iter__(self) -> DontReadFromInput:
160164
return self
161165

162166
def fileno(self) -> int:
163-
raise UnsupportedOperation("redirected stdin is pseudofile, has no fileno()")
167+
msg = "redirected stdin is pseudofile, has no fileno()"
168+
raise UnsupportedOperation(msg)
164169

165170
def flush(self) -> None:
166-
raise UnsupportedOperation("redirected stdin is pseudofile, has no flush()")
171+
msg = "redirected stdin is pseudofile, has no flush()"
172+
raise UnsupportedOperation(msg)
167173

168174
def isatty(self) -> bool:
169175
return False
@@ -175,22 +181,27 @@ def readable(self) -> bool:
175181
return False
176182

177183
def seek(self, offset: int) -> int: # noqa: ARG002
178-
raise UnsupportedOperation("Redirected stdin is pseudofile, has no seek(int).")
184+
msg = "Redirected stdin is pseudofile, has no seek(int)."
185+
raise UnsupportedOperation(msg)
179186

180187
def seekable(self) -> bool:
181188
return False
182189

183190
def tell(self) -> int:
184-
raise UnsupportedOperation("Redirected stdin is pseudofile, has no tell().")
191+
msg = "Redirected stdin is pseudofile, has no tell()."
192+
raise UnsupportedOperation(msg)
185193

186194
def truncate(self, size: int) -> None: # noqa: ARG002
187-
raise UnsupportedOperation("Cannot truncate stdin.")
195+
msg = "Cannot truncate stdin."
196+
raise UnsupportedOperation(msg)
188197

189198
def write(self, *args: Any) -> None: # noqa: ARG002
190-
raise UnsupportedOperation("Cannot write to stdin.")
199+
msg = "Cannot write to stdin."
200+
raise UnsupportedOperation(msg)
191201

192202
def writelines(self, *args: Any) -> None: # noqa: ARG002
193-
raise UnsupportedOperation("Cannot write to stdin.")
203+
msg = "Cannot write to stdin."
204+
raise UnsupportedOperation(msg)
194205

195206
def writable(self) -> bool:
196207
return False
@@ -611,7 +622,8 @@ def resume_capturing(self) -> None:
611622
def stop_capturing(self) -> None:
612623
"""Stop capturing and reset capturing streams."""
613624
if self._state == "stopped":
614-
raise ValueError("was already stopped")
625+
msg = "was already stopped"
626+
raise ValueError(msg)
615627
self._state = "stopped"
616628
if self.out:
617629
self.out.done()
@@ -647,7 +659,8 @@ def _get_multicapture(method: _CaptureMethod) -> MultiCapture[str]:
647659
return MultiCapture(
648660
in_=None, out=SysCapture(1, tee=True), err=SysCapture(2, tee=True)
649661
)
650-
raise ValueError(f"unknown capturing method: {method!r}")
662+
msg = f"unknown capturing method: {method!r}"
663+
raise ValueError(msg)
651664

652665

653666
# Own implementation of the CaptureManager.

src/_pytask/clean.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import shutil
77
import sys
88
from pathlib import Path
9-
from types import TracebackType
109
from typing import Any
1110
from typing import Generator
1211
from typing import Iterable
@@ -36,6 +35,7 @@
3635

3736

3837
if TYPE_CHECKING:
38+
from types import TracebackType
3939
from typing import NoReturn
4040

4141

@@ -242,15 +242,14 @@ def _find_all_unknown_paths(
242242
_RecursivePathNode.from_path(path, known_paths, exclude)
243243
for path in session.config["paths"]
244244
]
245-
unknown_paths = list(
245+
return list(
246246
itertools.chain.from_iterable(
247247
[
248248
_find_all_unkown_paths_per_recursive_node(node, include_directories)
249249
for node in recursive_nodes
250250
]
251251
)
252252
)
253-
return unknown_paths
254253

255254

256255
@define(repr=False)

src/_pytask/cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33

44
import sys
55
from typing import Any
6+
from typing import TYPE_CHECKING
67

78
import click
8-
import pluggy
99
from _pytask.click import ColoredGroup
1010
from _pytask.config import hookimpl
1111
from _pytask.pluginmanager import get_plugin_manager
1212
from packaging.version import parse as parse_version
1313

14+
if TYPE_CHECKING:
15+
import pluggy
16+
1417

1518
_CONTEXT_SETTINGS: dict[str, Any] = {
1619
"help_option_names": ("-h", "--help"),

src/_pytask/click.py

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

44
import enum

src/_pytask/collect.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Any
1111
from typing import Generator
1212
from typing import Iterable
13+
from typing import TYPE_CHECKING
1314

1415
from _pytask.collect_utils import parse_dependencies_from_task_function
1516
from _pytask.collect_utils import parse_products_from_task_function
@@ -20,7 +21,6 @@
2021
from _pytask.console import format_task_name
2122
from _pytask.exceptions import CollectionError
2223
from _pytask.mark_utils import has_mark
23-
from _pytask.models import NodeInfo
2424
from _pytask.node_protocols import Node
2525
from _pytask.node_protocols import PTask
2626
from _pytask.nodes import PathNode
@@ -31,12 +31,15 @@
3131
from _pytask.path import find_case_sensitive_path
3232
from _pytask.path import import_path
3333
from _pytask.report import CollectionReport
34-
from _pytask.session import Session
3534
from _pytask.shared import find_duplicates
3635
from _pytask.shared import reduce_node_name
3736
from _pytask.traceback import render_exc_info
3837
from rich.text import Text
3938

39+
if TYPE_CHECKING:
40+
from _pytask.session import Session
41+
from _pytask.models import NodeInfo
42+
4043

4144
@hookimpl
4245
def pytask_collect(session: Session) -> bool:
@@ -81,8 +84,7 @@ def _collect_from_paths(session: Session) -> None:
8184
@hookimpl
8285
def pytask_ignore_collect(path: Path, config: dict[str, Any]) -> bool:
8386
"""Ignore a path during the collection."""
84-
is_ignored = any(path.match(pattern) for pattern in config["ignore"])
85-
return is_ignored
87+
return any(path.match(pattern) for pattern in config["ignore"])
8688

8789

8890
@hookimpl

src/_pytask/collect_command.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
"""This module contains the implementation of ``pytask collect``."""
1+
"""Contains the implementation of ``pytask collect``."""
22
from __future__ import annotations
33

44
import sys
55
from collections import defaultdict
6-
from pathlib import Path
76
from typing import Any
87
from typing import TYPE_CHECKING
98

@@ -35,6 +34,7 @@
3534

3635

3736
if TYPE_CHECKING:
37+
from pathlib import Path
3838
from typing import NoReturn
3939

4040

@@ -134,9 +134,7 @@ def _find_common_ancestor_of_all_nodes(
134134
x.path for x in tree_leaves(task.produces) if isinstance(x, PPathNode)
135135
)
136136

137-
common_ancestor = find_common_ancestor(*all_paths, *paths)
138-
139-
return common_ancestor
137+
return find_common_ancestor(*all_paths, *paths)
140138

141139

142140
def _organize_tasks(tasks: list[PTaskWithPath]) -> dict[Path, list[PTaskWithPath]]:

0 commit comments

Comments
 (0)