Skip to content

Commit 6ddc335

Browse files
committed
chore: Update Ruff linters
1 parent 3143e0d commit 6ddc335

File tree

7 files changed

+75
-24
lines changed

7 files changed

+75
-24
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

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/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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ def stats_collectors(**kwargs) -> list[StatsCollector]:
4343
if "measure" in kwargs:
4444
interval = kwargs.get("interval", 1.0)
4545
manager = Manager()
46-
for collector in StatsCollector.subclasses:
47-
if collector.stat_name in kwargs["measure"]:
48-
collectors.append(collector(interval, manager))
46+
collectors.extend(
47+
collector(interval, manager)
48+
for collector in StatsCollector.subclasses
49+
if collector.stat_name in kwargs["measure"]
50+
)
4951
return collectors
5052

5153

@@ -307,7 +309,6 @@ def __init__(self, interval: float, manager: SyncManager) -> None:
307309

308310
def collect(self) -> None:
309311
"""Don't collect any disk statistics."""
310-
pass
311312

312313
def unproxied_stats(self) -> None:
313314
"""
@@ -342,7 +343,6 @@ def __init__(self, interval: float, manager: SyncManager) -> None:
342343

343344
def collect(self) -> None:
344345
"""Don't collect any CPU statistics."""
345-
pass
346346

347347
def unproxied_stats(self) -> None:
348348
"""
@@ -377,7 +377,6 @@ def __init__(self, interval: float, manager: SyncManager) -> None:
377377

378378
def collect(self) -> None:
379379
"""Don't collect any memory statistics."""
380-
pass
381380

382381
def unproxied_stats(self) -> None:
383382
"""

test/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Create the ``test`` package.
3+
4+
This ``__init__.py`` file creates the ``test`` package, such that tests
5+
can relative-import from modules in the sibling ``shell_logger``
6+
directory.
7+
"""
8+
9+
# © 2023 National Technology & Engineering Solutions of Sandia, LLC
10+
# (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the
11+
# U.S. Government retains certain rights in this software.
12+
13+
# SPDX-License-Identifier: BSD-3-Clause

0 commit comments

Comments
 (0)