Skip to content

Commit a72c4e7

Browse files
committed
chore(ruff): Run automated fixes (97 errors)
- conftest.py: 1 × I001 (unsorted-imports) - docs/_ext/aafig.py: 5 × C408 (unnecessary-collection-call) 1 × RUF005 (collection-literal-concatenation) - docs/conf.py: 2 × C408 (unnecessary-collection-call) 1 × I001 (unsorted-imports) 1 × SIM108 (if-else-block-instead-of-if-exp) 1 × RUF100 (unused-noqa) - src/tmuxp/cli/debug_info.py: 1 × I001 (unsorted-imports) 1 × C417 (unnecessary-map) - src/tmuxp/cli/freeze.py: 1 × I001 (unsorted-imports) - src/tmuxp/cli/load.py: 1 × I001 (unsorted-imports) 1 × UP031 (printf-string-formatting) 1 × UP032 (f-string) - src/tmuxp/cli/shell.py: 1 × RUF100 (unused-noqa) - src/tmuxp/cli/utils.py: 1 × UP031 (printf-string-formatting) 1 × UP032 (f-string) - src/tmuxp/exc.py: 1 × UP032 (f-string) - src/tmuxp/shell.py: 4 × RUF100 (unused-noqa) - src/tmuxp/types.py: 1 × RUF100 (unused-noqa) - src/tmuxp/util.py: 2 × RUF100 (unused-noqa) 1 × RUF015 (unnecessary-iterable-allocation-for-first-element) 1 × TRY201 (verbose-raise) - src/tmuxp/workspace/builder.py: 3 × SIM401 (if-else-block-instead-of-dict-get) 1 × F841 (unused-variable) 1 × B006 (mutable-argument-default) 1 × RUF013 (implicit-optional) 1 × TRY201 (verbose-raise) - src/tmuxp/workspace/finders.py: 2 × B006 (mutable-argument-default) 1 × RUF013 (implicit-optional) - src/tmuxp/workspace/freezer.py: 1 × I001 (unsorted-imports) 1 × UP018 (native-literals) - src/tmuxp/workspace/importers.py: 2 × B007 (unused-loop-control-variable) 1 × SIM401 (if-else-block-instead-of-dict-get) - src/tmuxp/workspace/loader.py: 2 × SIM401 (if-else-block-instead-of-dict-get) 1 × UP018 (native-literals) 1 × SIM102 (collapsible-if) - src/tmuxp/workspace/validation.py: 1 × SIM102 (collapsible-if) - tests/cli/test_cli.py: 2 × I001 (unsorted-imports) 2 × SIM105 (suppressible-exception) 1 × PTH201 (path-constructor-current-directory) - tests/cli/test_convert.py: 2 × SIM105 (suppressible-exception) 1 × I001 (unsorted-imports) - tests/cli/test_freeze.py: 2 × I001 (unsorted-imports) 2 × SIM105 (suppressible-exception) 2 × RUF005 (collection-literal-concatenation) - tests/cli/test_import.py: 2 × SIM105 (suppressible-exception) 1 × I001 (unsorted-imports) - tests/cli/test_load.py: 5 × SIM105 (suppressible-exception) 2 × I001 (unsorted-imports) 1 × RUF005 (collection-literal-concatenation) 1 × UP032 (f-string) - tests/cli/test_ls.py: 1 × SIM105 (suppressible-exception) 1 × I001 (unsorted-imports) - tests/cli/test_shell.py: 3 × C408 (unnecessary-collection-call) 2 × I001 (unsorted-imports) 1 × SIM105 (suppressible-exception) - tests/fixtures/__init__.py: 1 × RUF100 (unused-noqa) - tests/fixtures/import_teamocil/__init__.py: 1 × RUF100 (unused-noqa) - tests/fixtures/import_tmuxinator/__init__.py: 1 × RUF100 (unused-noqa) - tests/fixtures/workspace/__init__.py: 1 × RUF100 (unused-noqa) - tests/tests/test_helpers.py: 1 × I001 (unsorted-imports) - tests/workspace/test_builder.py: 1 × I001 (unsorted-imports) 1 × SIM300 (yoda-conditions) 1 × SIM108 (if-else-block-instead-of-if-exp) 1 × UP030 (format-literals) 1 × UP032 (f-string) - tests/workspace/test_config.py: 2 × B007 (unused-loop-control-variable)
1 parent c8f4fa4 commit a72c4e7

32 files changed

+146
-184
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

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# flake8: NOQA: E501
22
import contextlib
33
import inspect
4+
import pathlib
45
import sys
56
import typing as t
67
from os.path import relpath
7-
import pathlib
88

99
import tmuxp
1010

@@ -172,12 +172,12 @@
172172
}
173173

174174
# aafig format, try to get working with pdf
175-
aafig_format = dict(latex="pdf", html="gif")
175+
aafig_format = {"latex": "pdf", "html": "gif"}
176176

177-
aafig_default_options = dict(scale=0.75, aspect=0.5, proportional=True)
177+
aafig_default_options = {"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
@@ -224,10 +224,7 @@ def linkcode_resolve(domain, info): # NOQA: C901
224224
except Exception:
225225
lineno = None
226226

227-
if lineno:
228-
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1)
229-
else:
230-
linespec = ""
227+
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1) if lineno else ""
231228

232229
fn = relpath(fn, start=pathlib.Path(tmuxp.__file__).parent)
233230

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/load.py

+3-5
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
@@ -91,9 +92,7 @@ def set_layout_hook(session: Session, hook_name: str) -> None:
9192

9293
# unset the hook immediately after executing
9394
hook_cmd.append(
94-
"set-hook -u -t {target_session} {hook_name}".format(
95-
target_session=session.id, hook_name=hook_name
96-
)
95+
f"set-hook -u -t {session.id} {hook_name}"
9796
)
9897
hook_cmd.append(f"selectw -t {attached_window.id}")
9998

@@ -122,8 +121,7 @@ def load_plugins(session_config: t.Dict[str, t.Any]) -> t.List[t.Any]:
122121
plugins.append(plugin())
123122
except exc.TmuxpPluginException as error:
124123
if not prompt_yes_no(
125-
"%sSkip loading %s?"
126-
% (style(str(error), fg="yellow"), plugin_name),
124+
"{}Skip loading {}?".format(style(str(error), fg="yellow"), plugin_name),
127125
default=True,
128126
):
129127
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/exc.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def __init__(
5050
self.cmd = cmd
5151
self.output = output
5252
self.message = (
53-
"before_script failed with returncode {returncode}.\n"
54-
"command: {cmd}\n"
53+
f"before_script failed with returncode {self.returncode}.\n"
54+
f"command: {self.cmd}\n"
5555
"Error output:\n"
56-
"{output}"
57-
).format(returncode=self.returncode, cmd=self.cmd, output=self.output)
56+
f"{self.output}"
57+
)
5858

5959
def __str__(self):
6060
return self.message

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def run_before_script(
5858
if e.errno == 2:
5959
raise exc.BeforeLoadScriptNotExists(e, os.path.abspath(script_file))
6060
else:
61-
raise e
61+
raise
6262

6363

6464
def oh_my_zsh_auto_title() -> None:
@@ -87,7 +87,7 @@ def get_current_pane(server: "Server") -> t.Optional["Pane"]:
8787
"""Return Pane if one found in env"""
8888
if os.getenv("TMUX_PANE") is not None:
8989
try:
90-
return [p for p in server.panes if p.pane_id == os.getenv("TMUX_PANE")][0]
90+
return next(p for p in server.panes if p.pane_id == os.getenv("TMUX_PANE"))
9191
except IndexError:
9292
pass
9393
return None
@@ -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

+8-15
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def __init__(
141141
self,
142142
session_config: t.Dict[str, t.Any],
143143
server: Server,
144-
plugins: t.List[t.Any] = [],
144+
plugins: t.Optional[t.List[t.Any]] = None,
145145
) -> None:
146146
"""Initialize workspace loading.
147147
@@ -162,6 +162,8 @@ def __init__(
162162
``self.session``.
163163
"""
164164

165+
if plugins is None:
166+
plugins = []
165167
if not session_config:
166168
raise exc.EmptyWorkspaceException("Session configuration is empty.")
167169

@@ -276,9 +278,9 @@ def build(self, session: t.Optional[Session] = None, append: bool = False) -> No
276278
if "start_directory" in self.session_config:
277279
cwd = self.session_config["start_directory"]
278280
run_before_script(self.session_config["before_script"], cwd=cwd)
279-
except Exception as e:
281+
except Exception:
280282
self.session.kill_session()
281-
raise e
283+
raise
282284

283285
if "options" in self.session_config:
284286
for option, value in self.session_config["options"].items():
@@ -349,10 +351,7 @@ def iter_create_windows(
349351
for window_iterator, window_config in enumerate(
350352
self.session_config["windows"], start=1
351353
):
352-
if "window_name" not in window_config:
353-
window_name = None
354-
else:
355-
window_name = window_config["window_name"]
354+
window_name = window_config.get("window_name", None)
356355

357356
is_first_window_pass = self.first_window_pass(
358357
window_iterator, session, append
@@ -363,20 +362,14 @@ def iter_create_windows(
363362
w1 = session.attached_window
364363
w1.move_window("99")
365364

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

371367
# If the first pane specifies a start_directory, use that instead.
372368
panes = window_config["panes"]
373369
if panes and "start_directory" in panes[0]:
374370
start_directory = panes[0]["start_directory"]
375371

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

381374
# If the first pane specifies a shell, use that instead.
382375
try:

src/tmuxp/workspace/finders.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919

2020
def is_workspace_file(
2121
filename: str,
22-
extensions: t.Union["ValidExtensions", t.List["ValidExtensions"]] = [
23-
".yml",
24-
".yaml",
25-
".json",
26-
],
22+
extensions: t.Union["ValidExtensions", t.List["ValidExtensions"]] = None,
2723
) -> bool:
2824
"""
2925
Return True if file has a valid workspace file type.
@@ -39,13 +35,15 @@ def is_workspace_file(
3935
-------
4036
bool
4137
"""
38+
if extensions is None:
39+
extensions = [".yml", ".yaml", ".json"]
4240
extensions = [extensions] if isinstance(extensions, str) else extensions
4341
return any(filename.endswith(e) for e in extensions)
4442

4543

4644
def in_dir(
4745
workspace_dir: t.Union[pathlib.Path, str] = os.path.expanduser("~/.tmuxp"),
48-
extensions: t.List["ValidExtensions"] = [".yml", ".yaml", ".json"],
46+
extensions: t.Optional[t.List["ValidExtensions"]] = None,
4947
) -> t.List[str]:
5048

5149
"""
@@ -62,6 +60,8 @@ def in_dir(
6260
-------
6361
list
6462
"""
63+
if extensions is None:
64+
extensions = [".yml", ".yaml", ".json"]
6565
workspace_files = []
6666

6767
for filename in os.listdir(workspace_dir):

src/tmuxp/workspace/freezer.py

+3-2
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):
@@ -23,7 +24,7 @@ def inline(workspace_dict):
2324
):
2425
workspace_dict["shell_command"] = workspace_dict["shell_command"][0]
2526

26-
if len(workspace_dict.keys()) == int(1):
27+
if len(workspace_dict.keys()) == 1:
2728
workspace_dict = workspace_dict["shell_command"]
2829
if (
2930
"shell_command_before" in workspace_dict

0 commit comments

Comments
 (0)