Skip to content

Commit

Permalink
Bump dev dependencies, including ruff 0.4.2, f-string tweaks (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Apr 27, 2024
2 parents 296276d + 005fe7c commit 83daaaf
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 189 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Expand Up @@ -19,6 +19,12 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force

<!-- Maintainers, insert changes / features for the next release here -->

### Development

- Code quality: Use f-strings in more places (#931)

via [ruff 0.4.2](https://github.com/astral-sh/ruff/blob/v0.4.2/CHANGELOG.md).

## tmuxp 1.47.0 (2024-04-21)

_Maintenance only, no bug fixes or new features_
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Expand Up @@ -93,7 +93,7 @@ def session_params(session_params: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
@pytest.fixture()
def socket_name(request: pytest.FixtureRequest) -> str:
"""Random socket name for tmuxp."""
return "tmuxp_test%s" % next(namer)
return f"tmuxp_test{next(namer)}"


@pytest.fixture(autouse=True)
Expand Down
10 changes: 5 additions & 5 deletions docs/_ext/aafig.py
Expand Up @@ -126,9 +126,9 @@ def render_aafig_images(app: "Sphinx", doctree: nodes.Node) -> None:
options["format"] = format_map[_format]
else:
logger.warning(
'unsupported builder format "%s", please '
f'unsupported builder format "{_format}", please '
"add a custom entry in aafig_format config "
"option for this builder" % _format,
"option for this builder",
)
img.replace_self(nodes.literal_block(text, text))
continue
Expand Down Expand Up @@ -176,14 +176,14 @@ def render_aafigure(
# Non-HTML
if app.builder.format != "latex":
logger.warning(
"aafig: the builder format %s is not officially "
f"aafig: the builder format {app.builder.format} is not officially "
"supported, aafigure images could not work. "
"Please report problems and working builder to "
"avoid this warning in the future" % app.builder.format,
"avoid this warning in the future",
)
relfn = fname
outfn = path.join(app.builder.outdir, fname)
metadata_fname = "%s.aafig" % outfn
metadata_fname = f"{outfn}.aafig"

try:
if path.isfile(outfn):
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Expand Up @@ -60,8 +60,8 @@
project = about["__title__"]
project_copyright = about["__copyright__"]

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

exclude_patterns = ["_build"]

Expand Down
236 changes: 118 additions & 118 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/tmuxp/cli/convert.py
Expand Up @@ -88,7 +88,7 @@ def command_convert(
if (
not answer_yes
and prompt_yes_no(f"Convert to <{workspace_file}> to {to_filetype}?")
and prompt_yes_no("Save workspace to %s?" % newfile)
and prompt_yes_no(f"Save workspace to {newfile}?")
):
answer_yes = True

Expand Down
54 changes: 29 additions & 25 deletions src/tmuxp/cli/debug_info.py
Expand Up @@ -33,7 +33,7 @@ def command_debug_info(

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

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

output = [
output_break(),
"environment:\n%s"
% "\n".join(
prepend_tab(
[
"dist: %s" % platform.platform(),
"arch: %s" % platform.machine(),
"uname: %s" % "; ".join(platform.uname()[:3]),
"version: %s" % platform.version(),
],
),
"environment:\n{}".format(
"\n".join(
prepend_tab(
[
f"dist: {platform.platform()}",
f"arch: {platform.machine()}",
"uname: {}".format("; ".join(platform.uname()[:3])),
f"version: {platform.version()}",
],
),
)
),
output_break(),
"python version: %s" % " ".join(sys.version.split("\n")),
"system PATH: %s" % os.environ["PATH"],
"tmux version: %s" % get_version(),
"libtmux version: %s" % libtmux_version,
"tmuxp version: %s" % __version__,
"tmux path: %s" % shutil.which("tmux"),
"tmuxp path: %s" % tmuxp_path,
"shell: %s" % os.environ["SHELL"],
"python version: {}".format(" ".join(sys.version.split("\n"))),
"system PATH: {}".format(os.environ["PATH"]),
f"tmux version: {get_version()}",
f"libtmux version: {libtmux_version}",
f"tmuxp version: {__version__}",
"tmux path: {}".format(shutil.which("tmux")),
f"tmuxp path: {tmuxp_path}",
"shell: {}".format(os.environ["SHELL"]),
output_break(),
"tmux sessions:\n%s" % format_tmux_resp(tmux_cmd("list-sessions")),
"tmux windows:\n%s" % format_tmux_resp(tmux_cmd("list-windows")),
"tmux panes:\n%s" % format_tmux_resp(tmux_cmd("list-panes")),
"tmux global options:\n%s" % format_tmux_resp(tmux_cmd("show-options", "-g")),
"tmux window options:\n%s"
% format_tmux_resp(tmux_cmd("show-window-options", "-g")),
"tmux sessions:\n{}".format(format_tmux_resp(tmux_cmd("list-sessions"))),
"tmux windows:\n{}".format(format_tmux_resp(tmux_cmd("list-windows"))),
"tmux panes:\n{}".format(format_tmux_resp(tmux_cmd("list-panes"))),
"tmux global options:\n{}".format(
format_tmux_resp(tmux_cmd("show-options", "-g"))
),
"tmux window options:\n{}".format(
format_tmux_resp(tmux_cmd("show-window-options", "-g"))
),
]

tmuxp_echo("\n".join(output))
13 changes: 7 additions & 6 deletions src/tmuxp/cli/freeze.py
Expand Up @@ -154,11 +154,11 @@ def command_freeze(
),
)
dest_prompt = prompt(
"Save to: %s" % save_to,
f"Save to: {save_to}",
default=save_to,
)
if not args.force and os.path.exists(dest_prompt):
print("%s exists. Pick a new filename." % dest_prompt)
print(f"{dest_prompt} exists. Pick a new filename.")
continue

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

if args.answer_yes or prompt_yes_no("Save to %s?" % dest):
if args.answer_yes or prompt_yes_no(f"Save to {dest}?"):
destdir = os.path.dirname(dest)
if not os.path.isdir(destdir):
os.makedirs(destdir)
with open(dest, "w", encoding=locale.getpreferredencoding(False)) as buf:
buf.write(workspace)

if not args.quiet:
print("Saved to %s." % dest)
print(f"Saved to {dest}.")
9 changes: 5 additions & 4 deletions src/tmuxp/cli/import_config.py
Expand Up @@ -52,7 +52,8 @@ def get_teamocil_dir() -> pathlib.Path:
def _resolve_path_no_overwrite(workspace_file: str) -> str:
path = pathlib.Path(workspace_file).resolve()
if path.exists():
raise ValueError("%s exists. Pick a new filename." % path)
msg = f"{path} exists. Pick a new filename."
raise ValueError(msg)
return str(path)


Expand Down Expand Up @@ -165,18 +166,18 @@ def import_config(
dest = None
while not dest:
dest_path = prompt(
"Save to [%s]" % os.getcwd(),
f"Save to [{os.getcwd()}]",
value_proc=_resolve_path_no_overwrite,
)

# dest = dest_prompt
if prompt_yes_no("Save to %s?" % dest_path):
if prompt_yes_no(f"Save to {dest_path}?"):
dest = dest_path

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

tmuxp_echo("Saved to %s." % dest)
tmuxp_echo(f"Saved to {dest}.")
else:
tmuxp_echo(
"tmuxp has examples in JSON and YAML format at "
Expand Down
6 changes: 4 additions & 2 deletions src/tmuxp/cli/load.py
Expand Up @@ -333,7 +333,7 @@ def load_workspace(
server=t,
)
except exc.EmptyWorkspaceException:
tmuxp_echo("%s is empty or parsed no workspace data" % workspace_file)
tmuxp_echo(f"{workspace_file} is empty or parsed no workspace data")
return None

session_name = expanded_workspace["session_name"]
Expand All @@ -343,7 +343,9 @@ def load_workspace(
if not detached and (
answer_yes
or prompt_yes_no(
"%s is already running. Attach?" % style(session_name, fg="green"),
"{} is already running. Attach?".format(
style(session_name, fg="green")
),
default=True,
)
):
Expand Down
6 changes: 3 additions & 3 deletions src/tmuxp/cli/utils.py
Expand Up @@ -56,7 +56,7 @@ def prompt(
`flask-script <https://github.com/techniq/flask-script>`_. See the
`flask-script license <https://github.com/techniq/flask-script/blob/master/LICENSE>`_.
"""
_prompt = name + ((default and " [%s]" % default) or "")
_prompt = name + ((default and f" [{default}]") or "")
_prompt += (name.endswith("?") and " ") or ": "
while True:
rv = input(_prompt) or default
Expand Down Expand Up @@ -106,7 +106,7 @@ def prompt_bool(
else:
prompt_choice = "y/N"

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

while True:
Expand Down Expand Up @@ -160,7 +160,7 @@ def prompt_choices(
_choices.append(choice)

while True:
rv = prompt(name + " - (%s)" % ", ".join(options), default=default)
rv = prompt(name + " - ({})".format(", ".join(options)), default=default)
if not rv or rv == default:
return default
rv = rv.lower()
Expand Down
8 changes: 4 additions & 4 deletions src/tmuxp/workspace/finders.py
Expand Up @@ -191,8 +191,8 @@ def find_workspace_file(
]
if not len(candidates):
file_error = (
"workspace-file not found in workspace dir (yaml/yml/json) %s "
"for name" % (workspace_dir)
"workspace-file not found "
+ f"in workspace dir (yaml/yml/json) {workspace_dir} for name"
)
else:
candidates = [
Expand All @@ -207,8 +207,8 @@ def find_workspace_file(
if len(candidates) > 1:
tmuxp_echo(
Fore.RED
+ "Multiple .tmuxp.{yml,yaml,json} workspace_files in %s"
% dirname(workspace_file)
+ "Multiple .tmuxp.{yml,yaml,json} workspace_files in "
+ dirname(workspace_file)
+ Fore.RESET,
)
tmuxp_echo(
Expand Down
2 changes: 1 addition & 1 deletion src/tmuxp/workspace/importers.py
Expand Up @@ -71,7 +71,7 @@ def import_tmuxinator(workspace_dict: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
if "shell_command_before" not in tmuxp_workspace:
tmuxp_workspace["shell_command_before"] = []
tmuxp_workspace["shell_command_before"].append(
"rbenv shell %s" % workspace_dict["rbenv"],
"rbenv shell {}".format(workspace_dict["rbenv"]),
)

for window_dict in workspace_dict["windows"]:
Expand Down
17 changes: 8 additions & 9 deletions tests/workspace/test_config.py
Expand Up @@ -293,22 +293,21 @@ def test_replaces_env_variables(monkeypatch: pytest.MonkeyPatch) -> None:
panes:
- shell_command:
- htop
""".format(TEST_VAR="${%s}" % env_key)
""".format(TEST_VAR=f"${{{env_key}}}")

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

monkeypatch.setenv(str(env_key), str(env_val))
sconfig = loader.expand(sconfig)
assert "%s/test" % env_val == sconfig["start_directory"]
assert f"{env_val}/test" == sconfig["start_directory"]
assert (
"%s/test2" % env_val
in sconfig["shell_command_before"]["shell_command"][0]["cmd"]
f"{env_val}/test2" in sconfig["shell_command_before"]["shell_command"][0]["cmd"]
)
assert "%s/test3" % env_val == sconfig["before_script"]
assert "hi - %s" % env_val == sconfig["session_name"]
assert "%s/moo" % env_val == sconfig["global_options"]["default-shell"]
assert "%s/lol" % env_val == sconfig["options"]["default-command"]
assert "logging @ %s" % env_val == sconfig["windows"][1]["window_name"]
assert f"{env_val}/test3" == sconfig["before_script"]
assert f"hi - {env_val}" == sconfig["session_name"]
assert f"{env_val}/moo" == sconfig["global_options"]["default-shell"]
assert f"{env_val}/lol" == sconfig["options"]["default-command"]
assert f"logging @ {env_val}" == sconfig["windows"][1]["window_name"]


def test_validate_plugins() -> None:
Expand Down
16 changes: 8 additions & 8 deletions tests/workspace/test_finder.py
Expand Up @@ -156,7 +156,7 @@ def test_resolve_dot(
assert find_workspace_file("../project") == expect
assert find_workspace_file("../project/") == expect
assert find_workspace_file(".tmuxp.yaml") == expect
assert find_workspace_file("../../.tmuxp/%s.yaml" % user_config_name) == str(
assert find_workspace_file(f"../../.tmuxp/{user_config_name}.yaml") == str(
user_config,
)
assert find_workspace_file("myconfig") == str(user_config)
Expand All @@ -178,8 +178,8 @@ def test_resolve_dot(
assert find_workspace_file("work/project/") == expect
assert find_workspace_file("./work/project") == expect
assert find_workspace_file("./work/project/") == expect
assert find_workspace_file(".tmuxp/%s.yaml" % user_config_name) == str(user_config)
assert find_workspace_file("./.tmuxp/%s.yaml" % user_config_name) == str(
assert find_workspace_file(f".tmuxp/{user_config_name}.yaml") == str(user_config)
assert find_workspace_file(f"./.tmuxp/{user_config_name}.yaml") == str(
user_config,
)
assert find_workspace_file("myconfig") == str(user_config)
Expand All @@ -202,8 +202,8 @@ def test_resolve_dot(
assert find_workspace_file("../work/project") == expect
assert find_workspace_file("../../home/work/project") == expect
assert find_workspace_file("../work/project/") == expect
assert find_workspace_file("%s.yaml" % user_config_name) == str(user_config)
assert find_workspace_file("./%s.yaml" % user_config_name) == str(user_config)
assert find_workspace_file(f"{user_config_name}.yaml") == str(user_config)
assert find_workspace_file(f"./{user_config_name}.yaml") == str(user_config)
assert find_workspace_file("myconfig") == str(user_config)
assert find_workspace_file("~/.tmuxp/myconfig.yaml") == str(user_config)

Expand All @@ -223,10 +223,10 @@ def test_resolve_dot(
expect = str(project_config)
assert find_workspace_file("home/work/project") == expect
assert find_workspace_file("./home/work/project/") == expect
assert find_workspace_file("home/.tmuxp/%s.yaml" % user_config_name) == str(
assert find_workspace_file(f"home/.tmuxp/{user_config_name}.yaml") == str(
user_config,
)
assert find_workspace_file("./home/.tmuxp/%s.yaml" % user_config_name) == str(
assert find_workspace_file(f"./home/.tmuxp/{user_config_name}.yaml") == str(
user_config,
)
assert find_workspace_file("myconfig") == str(user_config)
Expand Down Expand Up @@ -280,7 +280,7 @@ def check_cmd(config_arg: str) -> "_pytest.capture.CaptureResult[str]":
assert expect in check_cmd("../project").out
assert expect in check_cmd("../project/").out
assert expect in check_cmd(".tmuxp.yaml").out
assert str(user_config) in check_cmd("../../.tmuxp/%s.yaml" % user_config_name).out
assert str(user_config) in check_cmd(f"../../.tmuxp/{user_config_name}.yaml").out
assert user_config.stem in check_cmd("myconfig").out
assert str(user_config) in check_cmd("~/.tmuxp/myconfig.yaml").out

Expand Down

0 comments on commit 83daaaf

Please sign in to comment.