Skip to content

Commit c602869

Browse files
committed
chore(ruff,unsafe): Unsafe autofixes for ruff with Python 3.10+
uv run ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes Fixed 9 errors: - docs/_ext/aafig.py: 1 × FURB103 (write-whole-file) 1 × FURB101 (read-whole-file) 1 × I001 (unsorted-imports) 1 × G004 (logging-f-string) - src/tmuxp/_internal/config_reader.py: 1 × PLW1514 (unspecified-encoding) - src/tmuxp/cli/convert.py: 1 × FURB103 (write-whole-file) - src/tmuxp/cli/freeze.py: 1 × FURB103 (write-whole-file) - src/tmuxp/cli/import_config.py: 1 × FURB103 (write-whole-file) - src/tmuxp/workspace/builder.py: 1 × G004 (logging-f-string) Found 1120 errors (9 fixed, 1111 remaining).
1 parent e4340e5 commit c602869

File tree

6 files changed

+21
-23
lines changed

6 files changed

+21
-23
lines changed

docs/_ext/aafig.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import locale
1818
import logging
19+
import pathlib
1920
import posixpath
2021
import typing as t
2122
from hashlib import sha1 as sha
@@ -130,9 +131,8 @@ def render_aafig_images(app: Sphinx, doctree: nodes.Node) -> None:
130131
options["format"] = format_map[format_]
131132
else:
132133
logger.warning(
133-
f'unsupported builder format "{format_}", please '
134-
"add a custom entry in aafig_format config "
135-
"option for this builder",
134+
'unsupported builder format "%s", please add a custom entry in aafig_format config option for this builder',
135+
format_,
136136
)
137137
img.replace_self(nodes.literal_block(text, text))
138138
continue
@@ -196,11 +196,9 @@ def render_aafigure(
196196
f = None
197197
try:
198198
try:
199-
with open(
200-
metadata_fname,
201-
encoding=locale.getpreferredencoding(False),
202-
) as f:
203-
extra = f.read()
199+
extra = pathlib.Path(metadata_fname).read_text(
200+
encoding=locale.getpreferredencoding(False)
201+
)
204202
except Exception as e:
205203
raise AafigError from e
206204
finally:
@@ -221,12 +219,9 @@ def render_aafigure(
221219
extra = None
222220
if options["format"].lower() == "svg":
223221
extra = visitor.get_size_attrs()
224-
with open(
225-
metadata_fname,
226-
"w",
227-
encoding=locale.getpreferredencoding(False),
228-
) as f:
229-
f.write(extra)
222+
pathlib.Path(metadata_fname).write_text(
223+
extra, encoding=locale.getpreferredencoding(False)
224+
)
230225

231226
return relfn, outfn, None, extra
232227

src/tmuxp/_internal/config_reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def _from_file(cls, path: pathlib.Path) -> dict[str, t.Any]:
106106
{'session_name': 'my session'}
107107
"""
108108
assert isinstance(path, pathlib.Path)
109-
content = path.open().read()
109+
content = path.open(encoding="utf-8").read()
110110

111111
if path.suffix in {".yaml", ".yml"}:
112112
fmt: FormatLiteral = "yaml"

src/tmuxp/cli/convert.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def command_convert(
9696
answer_yes = True
9797

9898
if answer_yes:
99-
with open(newfile, "w", encoding=locale.getpreferredencoding(False)) as buf:
100-
buf.write(new_workspace)
99+
pathlib.Path(newfile).write_text(
100+
new_workspace, encoding=locale.getpreferredencoding(False)
101+
)
101102
print(f"New workspace file saved to <{newfile}>.") # NOQA: T201 RUF100

src/tmuxp/cli/freeze.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ def extract_workspace_format(
210210
destdir = os.path.dirname(dest)
211211
if not os.path.isdir(destdir):
212212
os.makedirs(destdir)
213-
with open(dest, "w", encoding=locale.getpreferredencoding(False)) as buf:
214-
buf.write(workspace)
213+
pathlib.Path(dest).write_text(
214+
workspace, encoding=locale.getpreferredencoding(False)
215+
)
215216

216217
if not args.quiet:
217218
print(f"Saved to {dest}.") # NOQA: T201 RUF100

src/tmuxp/cli/import_config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ def import_config(
178178
if prompt_yes_no(f"Save to {dest_path}?"):
179179
dest = dest_path
180180

181-
with open(dest, "w", encoding=locale.getpreferredencoding(False)) as buf:
182-
buf.write(new_config)
181+
pathlib.Path(dest).write_text(
182+
new_config, encoding=locale.getpreferredencoding(False)
183+
)
183184

184185
tmuxp_echo(f"Saved to {dest}.")
185186
else:

src/tmuxp/workspace/builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ def iter_create_windows(
418418
else:
419419
target = "windows"
420420
logger.warning(
421-
f"Cannot set environment for new {target}. "
422-
"You need tmux 3.0 or newer for this.",
421+
"Cannot set environment for new %s. You need tmux 3.0 or newer for this.",
422+
target,
423423
)
424424
environment = None
425425

0 commit comments

Comments
 (0)