Skip to content

Commit 7b2ea42

Browse files
committed
chore(ruff): f-string formatting fixes from ruff 0.4.2
ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes --ignore T201 --ignore F401 --ignore PT014 --ignore RUF100 --ignore PGH004; ruff format . Fixed 102 errors: - conftest.py: 1 × UP031 (printf-string-formatting) 1 × UP032 (f-string) - docs/_ext/aafig.py: 3 × UP031 (printf-string-formatting) 3 × UP032 (f-string) - docs/conf.py: 2 × UP031 (printf-string-formatting) - src/tmuxp/cli/convert.py: 1 × UP031 (printf-string-formatting) 1 × UP032 (f-string) - src/tmuxp/cli/debug_info.py: 19 × UP031 (printf-string-formatting) 8 × UP032 (f-string) - src/tmuxp/cli/freeze.py: 5 × UP031 (printf-string-formatting) 4 × UP032 (f-string) - src/tmuxp/cli/import_config.py: 4 × UP031 (printf-string-formatting) 4 × UP032 (f-string) 1 × EM103 (dot-format-in-exception) - src/tmuxp/cli/load.py: 2 × UP031 (printf-string-formatting) 1 × UP032 (f-string) - src/tmuxp/cli/utils.py: 3 × UP031 (printf-string-formatting) 2 × UP032 (f-string) - src/tmuxp/workspace/finders.py: 2 × UP031 (printf-string-formatting) 2 × UP032 (f-string) - src/tmuxp/workspace/importers.py: 1 × UP031 (printf-string-formatting) - tests/workspace/test_config.py: 8 × UP031 (printf-string-formatting) 8 × UP032 (f-string) - tests/workspace/test_finder.py: 8 × UP031 (printf-string-formatting) 8 × UP032 (f-string)
1 parent 88ee067 commit 7b2ea42

File tree

13 files changed

+77
-71
lines changed

13 files changed

+77
-71
lines changed

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def session_params(session_params: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
9393
@pytest.fixture()
9494
def socket_name(request: pytest.FixtureRequest) -> str:
9595
"""Random socket name for tmuxp."""
96-
return "tmuxp_test%s" % next(namer)
96+
return f"tmuxp_test{next(namer)}"
9797

9898

9999
@pytest.fixture(autouse=True)

docs/_ext/aafig.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ def render_aafig_images(app: "Sphinx", doctree: nodes.Node) -> None:
126126
options["format"] = format_map[_format]
127127
else:
128128
logger.warning(
129-
'unsupported builder format "%s", please '
129+
f'unsupported builder format "{_format}", please '
130130
"add a custom entry in aafig_format config "
131-
"option for this builder" % _format,
131+
"option for this builder",
132132
)
133133
img.replace_self(nodes.literal_block(text, text))
134134
continue
@@ -176,14 +176,14 @@ def render_aafigure(
176176
# Non-HTML
177177
if app.builder.format != "latex":
178178
logger.warning(
179-
"aafig: the builder format %s is not officially "
179+
f"aafig: the builder format {app.builder.format} is not officially "
180180
"supported, aafigure images could not work. "
181181
"Please report problems and working builder to "
182-
"avoid this warning in the future" % app.builder.format,
182+
"avoid this warning in the future",
183183
)
184184
relfn = fname
185185
outfn = path.join(app.builder.outdir, fname)
186-
metadata_fname = "%s.aafig" % outfn
186+
metadata_fname = f"{outfn}.aafig"
187187

188188
try:
189189
if path.isfile(outfn):

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
project = about["__title__"]
6161
project_copyright = about["__copyright__"]
6262

63-
version = "%s" % (".".join(about["__version__"].split("."))[:2])
64-
release = "%s" % (about["__version__"])
63+
version = "{}".format(".".join(about["__version__"].split("."))[:2])
64+
release = "{}".format(about["__version__"])
6565

6666
exclude_patterns = ["_build"]
6767

src/tmuxp/cli/convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def command_convert(
8888
if (
8989
not answer_yes
9090
and prompt_yes_no(f"Convert to <{workspace_file}> to {to_filetype}?")
91-
and prompt_yes_no("Save workspace to %s?" % newfile)
91+
and prompt_yes_no(f"Save workspace to {newfile}?")
9292
):
9393
answer_yes = True
9494

src/tmuxp/cli/debug_info.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def command_debug_info(
3333

3434
def prepend_tab(strings: t.List[str]) -> t.List[str]:
3535
"""Prepend tab to strings in list."""
36-
return ["\t%s" % x for x in strings]
36+
return [f"\t{x}" for x in strings]
3737

3838
def output_break() -> str:
3939
"""Generate output break."""
@@ -52,33 +52,37 @@ def format_tmux_resp(std_resp: tmux_cmd) -> str:
5252

5353
output = [
5454
output_break(),
55-
"environment:\n%s"
56-
% "\n".join(
57-
prepend_tab(
58-
[
59-
"dist: %s" % platform.platform(),
60-
"arch: %s" % platform.machine(),
61-
"uname: %s" % "; ".join(platform.uname()[:3]),
62-
"version: %s" % platform.version(),
63-
],
64-
),
55+
"environment:\n{}".format(
56+
"\n".join(
57+
prepend_tab(
58+
[
59+
f"dist: {platform.platform()}",
60+
f"arch: {platform.machine()}",
61+
"uname: {}".format("; ".join(platform.uname()[:3])),
62+
f"version: {platform.version()}",
63+
],
64+
),
65+
)
6566
),
6667
output_break(),
67-
"python version: %s" % " ".join(sys.version.split("\n")),
68-
"system PATH: %s" % os.environ["PATH"],
69-
"tmux version: %s" % get_version(),
70-
"libtmux version: %s" % libtmux_version,
71-
"tmuxp version: %s" % __version__,
72-
"tmux path: %s" % shutil.which("tmux"),
73-
"tmuxp path: %s" % tmuxp_path,
74-
"shell: %s" % os.environ["SHELL"],
68+
"python version: {}".format(" ".join(sys.version.split("\n"))),
69+
"system PATH: {}".format(os.environ["PATH"]),
70+
f"tmux version: {get_version()}",
71+
f"libtmux version: {libtmux_version}",
72+
f"tmuxp version: {__version__}",
73+
"tmux path: {}".format(shutil.which("tmux")),
74+
f"tmuxp path: {tmuxp_path}",
75+
"shell: {}".format(os.environ["SHELL"]),
7576
output_break(),
76-
"tmux sessions:\n%s" % format_tmux_resp(tmux_cmd("list-sessions")),
77-
"tmux windows:\n%s" % format_tmux_resp(tmux_cmd("list-windows")),
78-
"tmux panes:\n%s" % format_tmux_resp(tmux_cmd("list-panes")),
79-
"tmux global options:\n%s" % format_tmux_resp(tmux_cmd("show-options", "-g")),
80-
"tmux window options:\n%s"
81-
% format_tmux_resp(tmux_cmd("show-window-options", "-g")),
77+
"tmux sessions:\n{}".format(format_tmux_resp(tmux_cmd("list-sessions"))),
78+
"tmux windows:\n{}".format(format_tmux_resp(tmux_cmd("list-windows"))),
79+
"tmux panes:\n{}".format(format_tmux_resp(tmux_cmd("list-panes"))),
80+
"tmux global options:\n{}".format(
81+
format_tmux_resp(tmux_cmd("show-options", "-g"))
82+
),
83+
"tmux window options:\n{}".format(
84+
format_tmux_resp(tmux_cmd("show-window-options", "-g"))
85+
),
8286
]
8387

8488
tmuxp_echo("\n".join(output))

src/tmuxp/cli/freeze.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ def command_freeze(
154154
),
155155
)
156156
dest_prompt = prompt(
157-
"Save to: %s" % save_to,
157+
f"Save to: {save_to}",
158158
default=save_to,
159159
)
160160
if not args.force and os.path.exists(dest_prompt):
161-
print("%s exists. Pick a new filename." % dest_prompt)
161+
print(f"{dest_prompt} exists. Pick a new filename.")
162162
continue
163163

164164
dest = dest_prompt
@@ -185,8 +185,9 @@ def extract_workspace_format(
185185
workspace_format = extract_workspace_format(dest)
186186
if not is_valid_ext(workspace_format):
187187
_workspace_format = prompt_choices(
188-
"Couldn't ascertain one of [%s] from file name. Convert to"
189-
% ", ".join(valid_workspace_formats),
188+
"Couldn't ascertain one of [{}] from file name. Convert to".format(
189+
", ".join(valid_workspace_formats)
190+
),
190191
choices=t.cast(t.List[str], valid_workspace_formats),
191192
default="yaml",
192193
)
@@ -203,12 +204,12 @@ def extract_workspace_format(
203204
elif workspace_format == "json":
204205
workspace = configparser.dump(fmt="json", indent=2)
205206

206-
if args.answer_yes or prompt_yes_no("Save to %s?" % dest):
207+
if args.answer_yes or prompt_yes_no(f"Save to {dest}?"):
207208
destdir = os.path.dirname(dest)
208209
if not os.path.isdir(destdir):
209210
os.makedirs(destdir)
210211
with open(dest, "w", encoding=locale.getpreferredencoding(False)) as buf:
211212
buf.write(workspace)
212213

213214
if not args.quiet:
214-
print("Saved to %s." % dest)
215+
print(f"Saved to {dest}.")

src/tmuxp/cli/import_config.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def get_teamocil_dir() -> pathlib.Path:
5252
def _resolve_path_no_overwrite(workspace_file: str) -> str:
5353
path = pathlib.Path(workspace_file).resolve()
5454
if path.exists():
55-
raise ValueError("%s exists. Pick a new filename." % path)
55+
msg = f"{path} exists. Pick a new filename."
56+
raise ValueError(msg)
5657
return str(path)
5758

5859

@@ -165,18 +166,18 @@ def import_config(
165166
dest = None
166167
while not dest:
167168
dest_path = prompt(
168-
"Save to [%s]" % os.getcwd(),
169+
f"Save to [{os.getcwd()}]",
169170
value_proc=_resolve_path_no_overwrite,
170171
)
171172

172173
# dest = dest_prompt
173-
if prompt_yes_no("Save to %s?" % dest_path):
174+
if prompt_yes_no(f"Save to {dest_path}?"):
174175
dest = dest_path
175176

176177
with open(dest, "w", encoding=locale.getpreferredencoding(False)) as buf:
177178
buf.write(new_config)
178179

179-
tmuxp_echo("Saved to %s." % dest)
180+
tmuxp_echo(f"Saved to {dest}.")
180181
else:
181182
tmuxp_echo(
182183
"tmuxp has examples in JSON and YAML format at "

src/tmuxp/cli/load.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def load_workspace(
333333
server=t,
334334
)
335335
except exc.EmptyWorkspaceException:
336-
tmuxp_echo("%s is empty or parsed no workspace data" % workspace_file)
336+
tmuxp_echo(f"{workspace_file} is empty or parsed no workspace data")
337337
return None
338338

339339
session_name = expanded_workspace["session_name"]
@@ -343,7 +343,9 @@ def load_workspace(
343343
if not detached and (
344344
answer_yes
345345
or prompt_yes_no(
346-
"%s is already running. Attach?" % style(session_name, fg="green"),
346+
"{} is already running. Attach?".format(
347+
style(session_name, fg="green")
348+
),
347349
default=True,
348350
)
349351
):

src/tmuxp/cli/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def prompt(
5656
`flask-script <https://github.com/techniq/flask-script>`_. See the
5757
`flask-script license <https://github.com/techniq/flask-script/blob/master/LICENSE>`_.
5858
"""
59-
_prompt = name + ((default and " [%s]" % default) or "")
59+
_prompt = name + ((default and f" [{default}]") or "")
6060
_prompt += (name.endswith("?") and " ") or ": "
6161
while True:
6262
rv = input(_prompt) or default
@@ -106,7 +106,7 @@ def prompt_bool(
106106
else:
107107
prompt_choice = "y/N"
108108

109-
_prompt = name + " [%s]" % prompt_choice
109+
_prompt = name + f" [{prompt_choice}]"
110110
_prompt += (name.endswith("?") and " ") or ": "
111111

112112
while True:
@@ -160,7 +160,7 @@ def prompt_choices(
160160
_choices.append(choice)
161161

162162
while True:
163-
rv = prompt(name + " - (%s)" % ", ".join(options), default=default)
163+
rv = prompt(name + " - ({})".format(", ".join(options)), default=default)
164164
if not rv or rv == default:
165165
return default
166166
rv = rv.lower()

src/tmuxp/workspace/finders.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ def find_workspace_file(
191191
]
192192
if not len(candidates):
193193
file_error = (
194-
"workspace-file not found in workspace dir (yaml/yml/json) %s "
195-
"for name" % (workspace_dir)
194+
f"workspace-file not found in workspace dir (yaml/yml/json) {workspace_dir} "
195+
"for name"
196196
)
197197
else:
198198
candidates = [
@@ -207,8 +207,7 @@ def find_workspace_file(
207207
if len(candidates) > 1:
208208
tmuxp_echo(
209209
Fore.RED
210-
+ "Multiple .tmuxp.{yml,yaml,json} workspace_files in %s"
211-
% dirname(workspace_file)
210+
+ f"Multiple .tmuxp.{{yml,yaml,json}} workspace_files in {dirname(workspace_file)}"
212211
+ Fore.RESET,
213212
)
214213
tmuxp_echo(

src/tmuxp/workspace/importers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def import_tmuxinator(workspace_dict: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
7171
if "shell_command_before" not in tmuxp_workspace:
7272
tmuxp_workspace["shell_command_before"] = []
7373
tmuxp_workspace["shell_command_before"].append(
74-
"rbenv shell %s" % workspace_dict["rbenv"],
74+
"rbenv shell {}".format(workspace_dict["rbenv"]),
7575
)
7676

7777
for window_dict in workspace_dict["windows"]:

tests/workspace/test_config.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,22 +293,21 @@ def test_replaces_env_variables(monkeypatch: pytest.MonkeyPatch) -> None:
293293
panes:
294294
- shell_command:
295295
- htop
296-
""".format(TEST_VAR="${%s}" % env_key)
296+
""".format(TEST_VAR=f"${{{env_key}}}")
297297

298298
sconfig = ConfigReader._load(fmt="yaml", content=yaml_workspace)
299299

300300
monkeypatch.setenv(str(env_key), str(env_val))
301301
sconfig = loader.expand(sconfig)
302-
assert "%s/test" % env_val == sconfig["start_directory"]
302+
assert f"{env_val}/test" == sconfig["start_directory"]
303303
assert (
304-
"%s/test2" % env_val
305-
in sconfig["shell_command_before"]["shell_command"][0]["cmd"]
304+
f"{env_val}/test2" in sconfig["shell_command_before"]["shell_command"][0]["cmd"]
306305
)
307-
assert "%s/test3" % env_val == sconfig["before_script"]
308-
assert "hi - %s" % env_val == sconfig["session_name"]
309-
assert "%s/moo" % env_val == sconfig["global_options"]["default-shell"]
310-
assert "%s/lol" % env_val == sconfig["options"]["default-command"]
311-
assert "logging @ %s" % env_val == sconfig["windows"][1]["window_name"]
306+
assert f"{env_val}/test3" == sconfig["before_script"]
307+
assert f"hi - {env_val}" == sconfig["session_name"]
308+
assert f"{env_val}/moo" == sconfig["global_options"]["default-shell"]
309+
assert f"{env_val}/lol" == sconfig["options"]["default-command"]
310+
assert f"logging @ {env_val}" == sconfig["windows"][1]["window_name"]
312311

313312

314313
def test_validate_plugins() -> None:

tests/workspace/test_finder.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def test_resolve_dot(
156156
assert find_workspace_file("../project") == expect
157157
assert find_workspace_file("../project/") == expect
158158
assert find_workspace_file(".tmuxp.yaml") == expect
159-
assert find_workspace_file("../../.tmuxp/%s.yaml" % user_config_name) == str(
159+
assert find_workspace_file(f"../../.tmuxp/{user_config_name}.yaml") == str(
160160
user_config,
161161
)
162162
assert find_workspace_file("myconfig") == str(user_config)
@@ -178,8 +178,8 @@ def test_resolve_dot(
178178
assert find_workspace_file("work/project/") == expect
179179
assert find_workspace_file("./work/project") == expect
180180
assert find_workspace_file("./work/project/") == expect
181-
assert find_workspace_file(".tmuxp/%s.yaml" % user_config_name) == str(user_config)
182-
assert find_workspace_file("./.tmuxp/%s.yaml" % user_config_name) == str(
181+
assert find_workspace_file(f".tmuxp/{user_config_name}.yaml") == str(user_config)
182+
assert find_workspace_file(f"./.tmuxp/{user_config_name}.yaml") == str(
183183
user_config,
184184
)
185185
assert find_workspace_file("myconfig") == str(user_config)
@@ -202,8 +202,8 @@ def test_resolve_dot(
202202
assert find_workspace_file("../work/project") == expect
203203
assert find_workspace_file("../../home/work/project") == expect
204204
assert find_workspace_file("../work/project/") == expect
205-
assert find_workspace_file("%s.yaml" % user_config_name) == str(user_config)
206-
assert find_workspace_file("./%s.yaml" % user_config_name) == str(user_config)
205+
assert find_workspace_file(f"{user_config_name}.yaml") == str(user_config)
206+
assert find_workspace_file(f"./{user_config_name}.yaml") == str(user_config)
207207
assert find_workspace_file("myconfig") == str(user_config)
208208
assert find_workspace_file("~/.tmuxp/myconfig.yaml") == str(user_config)
209209

@@ -223,10 +223,10 @@ def test_resolve_dot(
223223
expect = str(project_config)
224224
assert find_workspace_file("home/work/project") == expect
225225
assert find_workspace_file("./home/work/project/") == expect
226-
assert find_workspace_file("home/.tmuxp/%s.yaml" % user_config_name) == str(
226+
assert find_workspace_file(f"home/.tmuxp/{user_config_name}.yaml") == str(
227227
user_config,
228228
)
229-
assert find_workspace_file("./home/.tmuxp/%s.yaml" % user_config_name) == str(
229+
assert find_workspace_file(f"./home/.tmuxp/{user_config_name}.yaml") == str(
230230
user_config,
231231
)
232232
assert find_workspace_file("myconfig") == str(user_config)
@@ -280,7 +280,7 @@ def check_cmd(config_arg: str) -> "_pytest.capture.CaptureResult[str]":
280280
assert expect in check_cmd("../project").out
281281
assert expect in check_cmd("../project/").out
282282
assert expect in check_cmd(".tmuxp.yaml").out
283-
assert str(user_config) in check_cmd("../../.tmuxp/%s.yaml" % user_config_name).out
283+
assert str(user_config) in check_cmd(f"../../.tmuxp/{user_config_name}.yaml").out
284284
assert user_config.stem in check_cmd("myconfig").out
285285
assert str(user_config) in check_cmd("~/.tmuxp/myconfig.yaml").out
286286

0 commit comments

Comments
 (0)