Skip to content

Commit 68c103d

Browse files
authored
Merge pull request #213 from sandialabs/update-ruff-linters
Update ruff linters
2 parents 1acd254 + 76ba7c7 commit 68c103d

File tree

11 files changed

+76
-78
lines changed

11 files changed

+76
-78
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
- repo: https://github.com/astral-sh/ruff-pre-commit
1010
rev: v0.12.2
1111
hooks:
12-
- id: ruff
12+
- id: ruff-check
1313
- id: ruff-format
1414

1515
- repo: https://github.com/gitleaks/gitleaks

doc/source/abstract_method.rst

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

doc/source/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ shell-logger
88

99
shell_logger
1010
shell
11-
abstract_method
1211
stats_collector
1312
trace_collector
1413
html_utilities

pyproject.toml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,62 @@ line-length = 79
6767
[tool.ruff.lint]
6868
extend-select = [
6969
"A",
70+
"AIR",
71+
# "ANN",
72+
"ARG",
73+
"ASYNC",
7074
"B",
7175
"BLE",
7276
"C4",
7377
"C90",
7478
"D",
79+
"DJ",
7580
# "DTZ",
7681
"E",
7782
"EM",
7883
"ERA",
7984
"EXE",
85+
"F",
86+
"FA",
8087
"FBT",
88+
"FIX",
89+
"FLY",
90+
"FURB",
91+
"G",
92+
"I",
93+
"ICN",
94+
"INP",
95+
"INT",
96+
"ISC",
97+
"LOG",
98+
"N",
8199
"NPY",
100+
"PD",
101+
"PERF",
82102
"PGH",
103+
"PIE",
83104
"PL",
84105
"PT",
85106
"PTH",
107+
"PYI",
108+
"Q",
86109
"RET",
87110
"RSE",
88111
"RUF",
89112
# "S",
90113
"SIM",
114+
"SLF",
115+
"SLOT",
116+
"T10",
117+
"T20",
118+
"TC",
119+
"TD",
91120
"TID",
92121
"TCH",
93122
"TRY",
94-
# "UP",
123+
"UP",
95124
"W",
125+
"YTT",
96126
]
97127
ignore = [
98128
"D212",
@@ -106,14 +136,24 @@ extend-allowed-calls = [
106136

107137

108138
[tool.ruff.lint.per-file-ignores]
109-
"**/test_*.py" = ["S101"]
139+
"**/test_*.py" = [
140+
"S101",
141+
"SLF001",
142+
"T201",
143+
]
144+
"doc/source/conf.py" = ["INP001"]
145+
"example/*.py" = ["T201"]
110146
"html_utilities.py" = ["PLR2004"]
111147

112148

113149
[tool.ruff.lint.pydocstyle]
114150
convention = "google"
115151

116152

153+
[tool.ruff.lint.pyupgrade]
154+
keep-runtime-typing = true
155+
156+
117157

118158
[tool.semantic_release]
119159
build_command = "python3 -m pip install poetry && poetry build"

shell_logger/abstract_method.py

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

shell_logger/html_utilities.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import pkgutil
1010
import re
1111
import textwrap
12-
from collections.abc import Iterable, Mapping
12+
from collections.abc import Iterable, Iterator, Mapping
1313
from datetime import datetime
1414
from pathlib import Path
1515
from types import SimpleNamespace
16-
from typing import Iterator, TextIO, Union
16+
from typing import TextIO, Union
1717

1818

1919
def nested_simplenamespace_to_dict(
@@ -851,7 +851,7 @@ def sgr_4bit_color_and_style_to_html(sgr: str) -> str:
851851
"39": "color: inherit;",
852852
"49": "background-color: inherit;",
853853
}
854-
return f'<span style="{sgr_to_css.get(sgr) or str()}">'
854+
return f'<span style="{sgr_to_css.get(sgr) or ""}">'
855855

856856

857857
def sgr_8bit_color_to_html(sgr_params: list[str]) -> str: # noqa: PLR0911

shell_logger/shell.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from types import SimpleNamespace
2121
from typing import IO, Optional, TextIO
2222

23-
2423
END_OF_READ = 4
2524

2625

@@ -118,7 +117,7 @@ def __del__(self) -> None:
118117
]:
119118
try:
120119
os.close(fd)
121-
except OSError as e:
120+
except OSError as e: # noqa: PERF203
122121
if "Bad file descriptor" not in e.strerror:
123122
raise
124123

@@ -185,12 +184,12 @@ def run(self, command: str, **kwargs) -> SimpleNamespace:
185184

186185
# Set the `RET_CODE` environment variable, such that we can
187186
# access it later.
188-
os.write(self.aux_stdin_wfd, "RET_CODE=$?\n".encode())
187+
os.write(self.aux_stdin_wfd, b"RET_CODE=$?\n")
189188

190189
# Because these writes are non-blocking, tell the shell that the
191190
# writes are complete.
192-
os.write(self.aux_stdin_wfd, "printf '\\4'\n".encode())
193-
os.write(self.aux_stdin_wfd, "printf '\\4' 1>&2\n".encode())
191+
os.write(self.aux_stdin_wfd, b"printf '\\4'\n")
192+
os.write(self.aux_stdin_wfd, b"printf '\\4' 1>&2\n")
194193

195194
# Tee the output to multiple sinks (files, strings,
196195
# `stdout`/`stderr`).

shell_logger/shell_logger.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
import shutil
1515
import string
1616
import tempfile
17-
from collections.abc import Iterable, Mapping
17+
from collections.abc import Iterable, Iterator, Mapping
1818
from datetime import datetime, timedelta
1919
from distutils import dir_util
2020
from pathlib import Path
2121
from tempfile import NamedTemporaryFile
2222
from types import SimpleNamespace
23-
from typing import Iterator, Optional, Union
23+
from typing import Optional, Union
2424

2525
from .html_utilities import (
2626
append_html,
@@ -248,7 +248,7 @@ def update_done_time(self) -> None:
248248
"""
249249
self.done_time = datetime.now()
250250

251-
def __update_duration(self) -> None:
251+
def update_duration(self) -> None:
252252
"""
253253
Update the :attr:`duration` attribute.
254254
@@ -385,7 +385,7 @@ def print(self, msg: str, end: str = "\n") -> None:
385385
msg: The message to print and save to the log.
386386
end: The string appended after the message:
387387
"""
388-
print(msg, end=end)
388+
print(msg, end=end) # noqa: T201
389389
log = {"msg": msg, "timestamp": str(datetime.now()), "cmd": None}
390390
self.log_book.append(log)
391391

@@ -427,7 +427,7 @@ def to_html(self) -> Union[Iterator[str], list[Iterator[str]]]:
427427
if isinstance(log, ShellLogger):
428428
# Update the duration of this ShellLogger's commands.
429429
if log.duration is None:
430-
log.__update_duration()
430+
log.update_duration()
431431
html.append(child_logger_card(log))
432432

433433
# Otherwise, if this is a message being logged...
@@ -559,7 +559,7 @@ def log( # noqa: PLR0913
559559
# Print the command to be executed.
560560
with stdout_path.open("a"), stderr_path.open("a"):
561561
if verbose:
562-
print(cmd)
562+
print(cmd) # noqa: T201
563563

564564
# Initialize the log information.
565565
log = {
@@ -737,7 +737,7 @@ def default(self, obj: object) -> object: # noqa: PLR0911
737737
"""
738738
if isinstance(obj, ShellLogger):
739739
return {
740-
**{"__type__": "ShellLogger"},
740+
"__type__": "ShellLogger",
741741
**{k: self.default(v) for k, v in obj.__dict__.items()},
742742
}
743743
if isinstance(obj, (int, float, str, bytes)):

shell_logger/stats_collector.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
from time import sleep, time
1616
from typing import TYPE_CHECKING
1717

18-
from .abstract_method import AbstractMethod
19-
2018
if TYPE_CHECKING:
2119
from multiprocessing.managers import SyncManager
2220

@@ -41,14 +39,15 @@ def stats_collectors(**kwargs) -> list[StatsCollector]:
4139
Returns:
4240
A collection of instances of :class:`StatsCollector` subclasses.
4341
"""
44-
collectors = []
4542
if "measure" in kwargs:
4643
interval = kwargs.get("interval", 1.0)
4744
manager = Manager()
48-
for collector in StatsCollector.subclasses:
49-
if collector.stat_name in kwargs["measure"]:
50-
collectors.append(collector(interval, manager))
51-
return collectors
45+
return [
46+
collector(interval, manager)
47+
for collector in StatsCollector.subclasses
48+
if collector.stat_name in kwargs["measure"]
49+
]
50+
return []
5251

5352

5453
class StatsCollector:
@@ -117,11 +116,7 @@ def collect(self):
117116
Instantaneously collect a statistic.
118117
119118
This is meant to be called repeatedly after some time interval.
120-
121-
Raises:
122-
AbstractMethod: This must be overridden by subclasses.
123119
"""
124-
raise AbstractMethod
125120

126121
@abstractmethod
127122
def unproxied_stats(self):
@@ -130,11 +125,7 @@ def unproxied_stats(self):
130125
131126
Convert from Python's Manager's data structures to base Python
132127
data structures.
133-
134-
Raises:
135-
AbstractMethod: This must be overridden by subclasses.
136128
"""
137-
raise AbstractMethod
138129

139130
def finish(self):
140131
"""
@@ -317,7 +308,6 @@ def __init__(self, interval: float, manager: SyncManager) -> None:
317308

318309
def collect(self) -> None:
319310
"""Don't collect any disk statistics."""
320-
pass
321311

322312
def unproxied_stats(self) -> None:
323313
"""
@@ -352,7 +342,6 @@ def __init__(self, interval: float, manager: SyncManager) -> None:
352342

353343
def collect(self) -> None:
354344
"""Don't collect any CPU statistics."""
355-
pass
356345

357346
def unproxied_stats(self) -> None:
358347
"""
@@ -387,7 +376,6 @@ def __init__(self, interval: float, manager: SyncManager) -> None:
387376

388377
def collect(self) -> None:
389378
"""Don't collect any memory statistics."""
390-
pass
391379

392380
def unproxied_stats(self) -> None:
393381
"""

shell_logger/trace_collector.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
from abc import abstractmethod
1212
from pathlib import Path
1313

14-
from .abstract_method import AbstractMethod
15-
1614

1715
def trace_collector(**kwargs) -> TraceCollector:
1816
"""
@@ -87,11 +85,7 @@ def trace_args(self) -> str:
8785
8886
The trace command and the arguments you pass to it, but not the
8987
command you're tracing. E.g., return `strace -f -c -e "open"`.
90-
91-
Raises:
92-
AbstractMethod: This needs to be overridden by subclasses.
9388
"""
94-
raise AbstractMethod
9589

9690
def command(self, command: str):
9791
"""

0 commit comments

Comments
 (0)