Skip to content

Commit f4212c2

Browse files
committed
ci(ruff): Automated fixes
1 parent 8df3833 commit f4212c2

31 files changed

+119
-172
lines changed

conftest.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
import typing as t
1111

1212
import pytest
13-
1413
from _pytest.doctest import DoctestItem
15-
1614
from libtmux.test import namer
15+
1716
from tests.fixtures import utils as test_utils
1817
from tmuxp.workspace.finders import get_workspace_dir
1918

docs/_ext/aafig.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
logger = logging.getLogger(__name__)
3030

31-
DEFAULT_FORMATS = dict(html="svg", latex="pdf", text=None)
31+
DEFAULT_FORMATS = {"html": "svg", "latex": "pdf", "text": None}
3232

3333

3434
def merge_dict(dst, src):
@@ -58,21 +58,21 @@ class AafigDirective(images.Image):
5858

5959
has_content = True
6060
required_arguments = 0
61-
own_option_spec = dict(
62-
line_width=float,
63-
background=str,
64-
foreground=str,
65-
fill=str,
66-
aspect=nonnegative_int,
67-
textual=flag,
68-
proportional=flag,
69-
)
61+
own_option_spec = {
62+
"line_width": float,
63+
"background": str,
64+
"foreground": str,
65+
"fill": str,
66+
"aspect": nonnegative_int,
67+
"textual": flag,
68+
"proportional": flag,
69+
}
7070
option_spec = images.Image.option_spec.copy()
7171
option_spec.update(own_option_spec)
7272

7373
def run(self):
74-
aafig_options = dict()
75-
own_options_keys = [self.own_option_spec.keys()] + ["scale"]
74+
aafig_options = {}
75+
own_options_keys = [self.own_option_spec.keys(), "scale"]
7676
for (k, v) in self.options.items():
7777
if k in own_options_keys:
7878
# convert flags to booleans
@@ -88,7 +88,7 @@ def run(self):
8888
if isinstance(image_node, nodes.system_message):
8989
return [image_node]
9090
text = "\n".join(self.content)
91-
image_node.aafig = dict(options=aafig_options, text=text)
91+
image_node.aafig = {"options": aafig_options, "text": text}
9292
return [image_node]
9393

9494

@@ -206,7 +206,7 @@ def setup(app):
206206
app.add_directive("aafig", AafigDirective)
207207
app.connect("doctree-read", render_aafig_images)
208208
app.add_config_value("aafig_format", DEFAULT_FORMATS, "html")
209-
app.add_config_value("aafig_default_options", dict(), "html")
209+
app.add_config_value("aafig_default_options", {}, "html")
210210

211211

212212
# vim: set expandtab shiftwidth=4 softtabstop=4 :

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
aafig_default_options = dict(scale=0.75, aspect=0.5, proportional=True)
178178

179179

180-
def linkcode_resolve(domain, info): # NOQA: C901
180+
def linkcode_resolve(domain, info):
181181
"""
182182
Determine the URL corresponding to Python object
183183

src/tmuxp/cli/debug_info.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import typing as t
88

99
from colorama import Fore
10-
1110
from libtmux.__about__ import __version__ as libtmux_version
1211
from libtmux.common import get_version, tmux_cmd
1312

@@ -34,7 +33,7 @@ def prepend_tab(strings):
3433
"""
3534
Prepend tab to strings in list.
3635
"""
37-
return list(map(lambda x: "\t%s" % x, strings))
36+
return ["\t%s" % x for x in strings]
3837

3938
def output_break():
4039
"""

src/tmuxp/cli/freeze.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import typing as t
66

77
from libtmux.server import Server
8+
89
from tmuxp.config_reader import ConfigReader
910
from tmuxp.exc import TmuxpException
1011
from tmuxp.workspace.finders import get_workspace_dir

src/tmuxp/cli/import_config.py

-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ def import_config(
149149
"Save to [%s]" % os.getcwd(), value_proc=_resolve_path_no_overwrite
150150
)
151151

152-
# dest = dest_prompt
153152
if prompt_yes_no("Save to %s?" % dest_path):
154153
dest = dest_path
155154

src/tmuxp/cli/load.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from libtmux.common import has_gte_version
1717
from libtmux.server import Server
1818
from libtmux.session import Session
19+
1920
from tmuxp.types import StrPath
2021

2122
from .. import config_reader, exc, log, util
@@ -122,8 +123,7 @@ def load_plugins(session_config: t.Dict[str, t.Any]) -> t.List[t.Any]:
122123
plugins.append(plugin())
123124
except exc.TmuxpPluginException as error:
124125
if not prompt_yes_no(
125-
"%sSkip loading %s?"
126-
% (style(str(error), fg="yellow"), plugin_name),
126+
"{}Skip loading {}?".format(style(str(error), fg="yellow"), plugin_name),
127127
default=True,
128128
):
129129
tmuxp_echo(

src/tmuxp/cli/shell.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def command_shell(
166166
session=session, window_name=args.window_name, current_pane=current_pane
167167
)
168168

169-
pane = util.get_pane(window=window, current_pane=current_pane) # NOQA: F841
169+
pane = util.get_pane(window=window, current_pane=current_pane)
170170

171171
if args.command is not None:
172172
exec(args.command)

src/tmuxp/cli/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def prompt_choices(
126126
if isinstance(choice, str):
127127
options.append(choice)
128128
elif isinstance(choice, tuple):
129-
options.append("%s [%s]" % (choice, choice[0]))
129+
options.append(f"{choice} [{choice[0]}]")
130130
choice = choice[0]
131131
_choices.append(choice)
132132

src/tmuxp/shell.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def has_ipython() -> bool:
3232

3333
def has_ptpython() -> bool:
3434
try:
35-
from ptpython.repl import embed, run_config # NOQA F841
35+
from ptpython.repl import embed, run_config # F841
3636
except ImportError:
3737
try:
3838
from prompt_toolkit.contrib.repl import embed, run_config # NOQA F841
@@ -44,8 +44,8 @@ def has_ptpython() -> bool:
4444

4545
def has_ptipython() -> bool:
4646
try:
47-
from ptpython.ipython import embed # NOQA F841
48-
from ptpython.repl import run_config # NOQA F841
47+
from ptpython.ipython import embed # F841
48+
from ptpython.repl import run_config # F841
4949
except ImportError:
5050
try:
5151
from prompt_toolkit.contrib.ipython import embed # NOQA F841
@@ -80,7 +80,7 @@ def get_bpython(options, extra_args=None):
8080
if extra_args is None:
8181
extra_args = {}
8282

83-
from bpython import embed # NOQA F841
83+
from bpython import embed # F841
8484

8585
def launch_bpython():
8686
imported_objects = get_launch_args(**options)

src/tmuxp/types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
:class:`StrPath` and :class:`StrOrBytesPath` is based on `typeshed's`_.
77
88
.. _typeshed's: https://github.com/python/typeshed/blob/9687d5/stdlib/_typeshed/__init__.pyi#L98
9-
""" # NOQA E501
9+
""" # E501
1010
from os import PathLike
1111
from typing import Union
1212

src/tmuxp/util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ def get_pane(window: "Window", current_pane: t.Optional["Pane"] = None) -> "Pane
151151
pane = None
152152
try:
153153
if current_pane is not None:
154-
pane = window.panes.get(pane_id=current_pane.pane_id) # NOQA: F841
154+
pane = window.panes.get(pane_id=current_pane.pane_id)
155155
else:
156-
pane = window.attached_pane # NOQA: F841
156+
pane = window.attached_pane
157157
except exc.TmuxpException as e:
158158
print(e)
159159

src/tmuxp/workspace/builder.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ def __init__(
165165
if not session_config:
166166
raise exc.EmptyWorkspaceException("Session configuration is empty.")
167167

168-
# validation.validate_schema(session_config)
169168

170169
assert isinstance(server, Server)
171170
self.server = server
@@ -349,10 +348,7 @@ def iter_create_windows(
349348
for window_iterator, window_config in enumerate(
350349
self.session_config["windows"], start=1
351350
):
352-
if "window_name" not in window_config:
353-
window_name = None
354-
else:
355-
window_name = window_config["window_name"]
351+
window_name = window_config.get("window_name", None)
356352

357353
is_first_window_pass = self.first_window_pass(
358354
window_iterator, session, append
@@ -363,20 +359,14 @@ def iter_create_windows(
363359
w1 = session.attached_window
364360
w1.move_window("99")
365361

366-
if "start_directory" in window_config:
367-
start_directory = window_config["start_directory"]
368-
else:
369-
start_directory = None
362+
start_directory = window_config.get("start_directory", None)
370363

371364
# If the first pane specifies a start_directory, use that instead.
372365
panes = window_config["panes"]
373366
if panes and "start_directory" in panes[0]:
374367
start_directory = panes[0]["start_directory"]
375368

376-
if "window_shell" in window_config:
377-
window_shell = window_config["window_shell"]
378-
else:
379-
window_shell = None
369+
window_shell = window_config.get("window_shell", None)
380370

381371
# If the first pane specifies a shell, use that instead.
382372
try:

src/tmuxp/workspace/freezer.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import typing as t
2+
13
from libtmux.pane import Pane
24
from libtmux.session import Session
3-
import typing as t
45

56

67
def inline(workspace_dict):

src/tmuxp/workspace/importers.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ def import_teamocil(workspace_dict: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
126126
if "session" in workspace_dict:
127127
workspace_dict = workspace_dict["session"]
128128

129-
if "name" in workspace_dict:
130-
tmuxp_workspace["session_name"] = workspace_dict["name"]
131-
else:
132-
tmuxp_workspace["session_name"] = None
129+
tmuxp_workspace["session_name"] = workspace_dict.get("name", None)
133130

134131
if "root" in workspace_dict:
135132
tmuxp_workspace["start_directory"] = workspace_dict.pop("root")
@@ -144,10 +141,10 @@ def import_teamocil(workspace_dict: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
144141

145142
if "filters" in w:
146143
if "before" in w["filters"]:
147-
for b in w["filters"]["before"]:
144+
for _b in w["filters"]["before"]:
148145
window_dict["shell_command_before"] = w["filters"]["before"]
149146
if "after" in w["filters"]:
150-
for b in w["filters"]["after"]:
147+
for _b in w["filters"]["after"]:
151148
window_dict["shell_command_after"] = w["filters"]["after"]
152149

153150
if "root" in w:

src/tmuxp/workspace/loader.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,9 @@ def trickle(workspace_dict):
206206
# prepends a pane's ``shell_command`` list with the window and sessions'
207207
# ``shell_command_before``.
208208

209-
if "start_directory" in workspace_dict:
210-
session_start_directory = workspace_dict["start_directory"]
211-
else:
212-
session_start_directory = None
209+
session_start_directory = workspace_dict.get("start_directory", None)
213210

214-
if "suppress_history" in workspace_dict:
215-
suppress_history = workspace_dict["suppress_history"]
216-
else:
217-
suppress_history = None
211+
suppress_history = workspace_dict.get("suppress_history", None)
218212

219213
for window_dict in workspace_dict["windows"]:
220214

@@ -232,9 +226,8 @@ def trickle(workspace_dict):
232226
window_dict["start_directory"] = window_start_path
233227

234228
# We only need to trickle to the window, workspace builder checks wconf
235-
if suppress_history is not None:
236-
if "suppress_history" not in window_dict:
237-
window_dict["suppress_history"] = suppress_history
229+
if suppress_history is not None and "suppress_history" not in window_dict:
230+
window_dict["suppress_history"] = suppress_history
238231

239232
# If panes were NOT specified for a window, assume that a single pane
240233
# with no shell commands is desired
@@ -262,6 +255,5 @@ def trickle(workspace_dict):
262255
commands_before.extend(pane_dict["shell_command"])
263256

264257
window_dict["panes"][pane_idx]["shell_command"] = commands_before
265-
# pane_dict['shell_command'] = commands_before
266258

267259
return workspace_dict

src/tmuxp/workspace/validation.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def validate_schema(workspace_dict: t.Any) -> bool:
2727
if "window_name" not in window:
2828
raise exc.WorkspaceError('workspace window is missing "window_name"')
2929

30-
if "plugins" in workspace_dict:
31-
if not isinstance(workspace_dict["plugins"], list):
32-
raise exc.WorkspaceError('"plugins" only supports list type')
30+
if "plugins" in workspace_dict and not isinstance(workspace_dict["plugins"], list):
31+
raise exc.WorkspaceError('"plugins" only supports list type')
3332

3433
return True

tests/cli/test_cli.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import argparse
2+
import contextlib
23
import os
34
import pathlib
45
import typing as t
56

6-
import pytest
7-
87
import libtmux
8+
import pytest
99
from libtmux.server import Server
10+
1011
from tmuxp import cli
1112
from tmuxp.cli.import_config import get_teamocil_dir, get_tmuxinator_dir
1213
from tmuxp.cli.load import _reattach, load_plugins
@@ -42,10 +43,9 @@ def test_help(
4243
monkeypatch: pytest.MonkeyPatch,
4344
capsys: pytest.CaptureFixture,
4445
) -> None:
45-
try:
46+
with contextlib.suppress(SystemExit):
4647
cli.cli(cli_args)
47-
except SystemExit:
48-
pass
48+
4949
result = capsys.readouterr()
5050

5151
assert "usage: tmuxp [-h] [--version] [--log-level log-level]" in result.out
@@ -130,10 +130,9 @@ def test_reattach_plugins(
130130
)
131131
builder.build()
132132

133-
try:
133+
with contextlib.suppress(libtmux.exc.LibTmuxException):
134134
_reattach(builder)
135-
except libtmux.exc.LibTmuxException:
136-
pass
135+
137136

138137
assert builder.session is not None
139138
proc = builder.session.cmd("display-message", "-p", "'#S'")

tests/cli/test_convert.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import io
23
import json
34
import pathlib
@@ -41,10 +42,9 @@ def test_convert(
4142
input_args = "y\ny\n" if "-y" not in cli_args else ""
4243

4344
monkeypatch.setattr("sys.stdin", io.StringIO(input_args))
44-
try:
45+
with contextlib.suppress(SystemExit):
4546
cli.cli(cli_args)
46-
except SystemExit:
47-
pass
47+
4848
tmuxp_json = tmp_path / ".tmuxp.json"
4949
assert tmuxp_json.exists()
5050
assert tmuxp_json.open().read() == json.dumps({"session_name": "hello"}, indent=2)
@@ -76,10 +76,9 @@ def test_convert_json(
7676
input_args = "y\ny\n" if "-y" not in cli_args else ""
7777

7878
monkeypatch.setattr("sys.stdin", io.StringIO(input_args))
79-
try:
79+
with contextlib.suppress(SystemExit):
8080
cli.cli(cli_args)
81-
except SystemExit:
82-
pass
81+
8382

8483
tmuxp_yaml = tmp_path / ".tmuxp.yaml"
8584
assert tmuxp_yaml.exists()

0 commit comments

Comments
 (0)