Skip to content

Commit

Permalink
ci(ruff): Automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Aug 20, 2023
1 parent 3b43103 commit 248dda5
Show file tree
Hide file tree
Showing 31 changed files with 119 additions and 172 deletions.
3 changes: 1 addition & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import typing as t

import pytest

from _pytest.doctest import DoctestItem

from libtmux.test import namer

from tests.fixtures import utils as test_utils
from tmuxp.workspace.finders import get_workspace_dir

Expand Down
28 changes: 14 additions & 14 deletions docs/_ext/aafig.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

logger = logging.getLogger(__name__)

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


def merge_dict(dst, src):
Expand Down Expand Up @@ -58,21 +58,21 @@ class AafigDirective(images.Image):

has_content = True
required_arguments = 0
own_option_spec = dict(
line_width=float,
background=str,
foreground=str,
fill=str,
aspect=nonnegative_int,
textual=flag,
proportional=flag,
)
own_option_spec = {
"line_width": float,
"background": str,
"foreground": str,
"fill": str,
"aspect": nonnegative_int,
"textual": flag,
"proportional": flag,
}
option_spec = images.Image.option_spec.copy()
option_spec.update(own_option_spec)

def run(self):
aafig_options = dict()
own_options_keys = [self.own_option_spec.keys()] + ["scale"]
aafig_options = {}
own_options_keys = [self.own_option_spec.keys(), "scale"]
for (k, v) in self.options.items():
if k in own_options_keys:
# convert flags to booleans
Expand All @@ -88,7 +88,7 @@ def run(self):
if isinstance(image_node, nodes.system_message):
return [image_node]
text = "\n".join(self.content)
image_node.aafig = dict(options=aafig_options, text=text)
image_node.aafig = {"options": aafig_options, "text": text}
return [image_node]


Expand Down Expand Up @@ -206,7 +206,7 @@ def setup(app):
app.add_directive("aafig", AafigDirective)
app.connect("doctree-read", render_aafig_images)
app.add_config_value("aafig_format", DEFAULT_FORMATS, "html")
app.add_config_value("aafig_default_options", dict(), "html")
app.add_config_value("aafig_default_options", {}, "html")


# vim: set expandtab shiftwidth=4 softtabstop=4 :
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
aafig_default_options = dict(scale=0.75, aspect=0.5, proportional=True)


def linkcode_resolve(domain, info): # NOQA: C901
def linkcode_resolve(domain, info):
"""
Determine the URL corresponding to Python object
Expand Down
3 changes: 1 addition & 2 deletions src/tmuxp/cli/debug_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import typing as t

from colorama import Fore

from libtmux.__about__ import __version__ as libtmux_version
from libtmux.common import get_version, tmux_cmd

Expand All @@ -34,7 +33,7 @@ def prepend_tab(strings):
"""
Prepend tab to strings in list.
"""
return list(map(lambda x: "\t%s" % x, strings))
return ["\t%s" % x for x in strings]

def output_break():
"""
Expand Down
1 change: 1 addition & 0 deletions src/tmuxp/cli/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import typing as t

from libtmux.server import Server

from tmuxp.config_reader import ConfigReader
from tmuxp.exc import TmuxpException
from tmuxp.workspace.finders import get_workspace_dir
Expand Down
1 change: 0 additions & 1 deletion src/tmuxp/cli/import_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def import_config(
"Save to [%s]" % os.getcwd(), value_proc=_resolve_path_no_overwrite
)

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

Expand Down
4 changes: 2 additions & 2 deletions src/tmuxp/cli/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from libtmux.common import has_gte_version
from libtmux.server import Server
from libtmux.session import Session

from tmuxp.types import StrPath

from .. import config_reader, exc, log, util
Expand Down Expand Up @@ -122,8 +123,7 @@ def load_plugins(session_config: t.Dict[str, t.Any]) -> t.List[t.Any]:
plugins.append(plugin())
except exc.TmuxpPluginException as error:
if not prompt_yes_no(
"%sSkip loading %s?"
% (style(str(error), fg="yellow"), plugin_name),
"{}Skip loading {}?".format(style(str(error), fg="yellow"), plugin_name),
default=True,
):
tmuxp_echo(
Expand Down
2 changes: 1 addition & 1 deletion src/tmuxp/cli/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def command_shell(
session=session, window_name=args.window_name, current_pane=current_pane
)

pane = util.get_pane(window=window, current_pane=current_pane) # NOQA: F841
pane = util.get_pane(window=window, current_pane=current_pane)

if args.command is not None:
exec(args.command)
Expand Down
2 changes: 1 addition & 1 deletion src/tmuxp/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def prompt_choices(
if isinstance(choice, str):
options.append(choice)
elif isinstance(choice, tuple):
options.append("%s [%s]" % (choice, choice[0]))
options.append(f"{choice} [{choice[0]}]")
choice = choice[0]
_choices.append(choice)

Expand Down
8 changes: 4 additions & 4 deletions src/tmuxp/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def has_ipython() -> bool:

def has_ptpython() -> bool:
try:
from ptpython.repl import embed, run_config # NOQA F841
from ptpython.repl import embed, run_config # F841
except ImportError:
try:
from prompt_toolkit.contrib.repl import embed, run_config # NOQA F841
Expand All @@ -44,8 +44,8 @@ def has_ptpython() -> bool:

def has_ptipython() -> bool:
try:
from ptpython.ipython import embed # NOQA F841
from ptpython.repl import run_config # NOQA F841
from ptpython.ipython import embed # F841
from ptpython.repl import run_config # F841
except ImportError:
try:
from prompt_toolkit.contrib.ipython import embed # NOQA F841
Expand Down Expand Up @@ -80,7 +80,7 @@ def get_bpython(options, extra_args=None):
if extra_args is None:
extra_args = {}

from bpython import embed # NOQA F841
from bpython import embed # F841

def launch_bpython():
imported_objects = get_launch_args(**options)
Expand Down
2 changes: 1 addition & 1 deletion src/tmuxp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:class:`StrPath` and :class:`StrOrBytesPath` is based on `typeshed's`_.
.. _typeshed's: https://github.com/python/typeshed/blob/9687d5/stdlib/_typeshed/__init__.pyi#L98
""" # NOQA E501
""" # E501
from os import PathLike
from typing import Union

Expand Down
4 changes: 2 additions & 2 deletions src/tmuxp/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def get_pane(window: "Window", current_pane: t.Optional["Pane"] = None) -> "Pane
pane = None
try:
if current_pane is not None:
pane = window.panes.get(pane_id=current_pane.pane_id) # NOQA: F841
pane = window.panes.get(pane_id=current_pane.pane_id)
else:
pane = window.attached_pane # NOQA: F841
pane = window.attached_pane
except exc.TmuxpException as e:
print(e)

Expand Down
16 changes: 3 additions & 13 deletions src/tmuxp/workspace/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ def __init__(
if not session_config:
raise exc.EmptyWorkspaceException("Session configuration is empty.")

# validation.validate_schema(session_config)

assert isinstance(server, Server)
self.server = server
Expand Down Expand Up @@ -349,10 +348,7 @@ def iter_create_windows(
for window_iterator, window_config in enumerate(
self.session_config["windows"], start=1
):
if "window_name" not in window_config:
window_name = None
else:
window_name = window_config["window_name"]
window_name = window_config.get("window_name", None)

is_first_window_pass = self.first_window_pass(
window_iterator, session, append
Expand All @@ -363,20 +359,14 @@ def iter_create_windows(
w1 = session.attached_window
w1.move_window("99")

if "start_directory" in window_config:
start_directory = window_config["start_directory"]
else:
start_directory = None
start_directory = window_config.get("start_directory", None)

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

if "window_shell" in window_config:
window_shell = window_config["window_shell"]
else:
window_shell = None
window_shell = window_config.get("window_shell", None)

# If the first pane specifies a shell, use that instead.
try:
Expand Down
3 changes: 2 additions & 1 deletion src/tmuxp/workspace/freezer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typing as t

from libtmux.pane import Pane
from libtmux.session import Session
import typing as t


def inline(workspace_dict):
Expand Down
9 changes: 3 additions & 6 deletions src/tmuxp/workspace/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ def import_teamocil(workspace_dict: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
if "session" in workspace_dict:
workspace_dict = workspace_dict["session"]

if "name" in workspace_dict:
tmuxp_workspace["session_name"] = workspace_dict["name"]
else:
tmuxp_workspace["session_name"] = None
tmuxp_workspace["session_name"] = workspace_dict.get("name", None)

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

if "filters" in w:
if "before" in w["filters"]:
for b in w["filters"]["before"]:
for _b in w["filters"]["before"]:
window_dict["shell_command_before"] = w["filters"]["before"]
if "after" in w["filters"]:
for b in w["filters"]["after"]:
for _b in w["filters"]["after"]:
window_dict["shell_command_after"] = w["filters"]["after"]

if "root" in w:
Expand Down
16 changes: 4 additions & 12 deletions src/tmuxp/workspace/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,9 @@ def trickle(workspace_dict):
# prepends a pane's ``shell_command`` list with the window and sessions'
# ``shell_command_before``.

if "start_directory" in workspace_dict:
session_start_directory = workspace_dict["start_directory"]
else:
session_start_directory = None
session_start_directory = workspace_dict.get("start_directory", None)

if "suppress_history" in workspace_dict:
suppress_history = workspace_dict["suppress_history"]
else:
suppress_history = None
suppress_history = workspace_dict.get("suppress_history", None)

for window_dict in workspace_dict["windows"]:

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

# We only need to trickle to the window, workspace builder checks wconf
if suppress_history is not None:
if "suppress_history" not in window_dict:
window_dict["suppress_history"] = suppress_history
if suppress_history is not None and "suppress_history" not in window_dict:
window_dict["suppress_history"] = suppress_history

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

window_dict["panes"][pane_idx]["shell_command"] = commands_before
# pane_dict['shell_command'] = commands_before

return workspace_dict
5 changes: 2 additions & 3 deletions src/tmuxp/workspace/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def validate_schema(workspace_dict: t.Any) -> bool:
if "window_name" not in window:
raise exc.WorkspaceError('workspace window is missing "window_name"')

if "plugins" in workspace_dict:
if not isinstance(workspace_dict["plugins"], list):
raise exc.WorkspaceError('"plugins" only supports list type')
if "plugins" in workspace_dict and not isinstance(workspace_dict["plugins"], list):
raise exc.WorkspaceError('"plugins" only supports list type')

return True
15 changes: 7 additions & 8 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import argparse
import contextlib
import os
import pathlib
import typing as t

import pytest

import libtmux
import pytest
from libtmux.server import Server

from tmuxp import cli
from tmuxp.cli.import_config import get_teamocil_dir, get_tmuxinator_dir
from tmuxp.cli.load import _reattach, load_plugins
Expand Down Expand Up @@ -42,10 +43,9 @@ def test_help(
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture,
) -> None:
try:
with contextlib.suppress(SystemExit):
cli.cli(cli_args)
except SystemExit:
pass

result = capsys.readouterr()

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

try:
with contextlib.suppress(libtmux.exc.LibTmuxException):
_reattach(builder)
except libtmux.exc.LibTmuxException:
pass


assert builder.session is not None
proc = builder.session.cmd("display-message", "-p", "'#S'")
Expand Down
11 changes: 5 additions & 6 deletions tests/cli/test_convert.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import io
import json
import pathlib
Expand Down Expand Up @@ -41,10 +42,9 @@ def test_convert(
input_args = "y\ny\n" if "-y" not in cli_args else ""

monkeypatch.setattr("sys.stdin", io.StringIO(input_args))
try:
with contextlib.suppress(SystemExit):
cli.cli(cli_args)
except SystemExit:
pass

tmuxp_json = tmp_path / ".tmuxp.json"
assert tmuxp_json.exists()
assert tmuxp_json.open().read() == json.dumps({"session_name": "hello"}, indent=2)
Expand Down Expand Up @@ -76,10 +76,9 @@ def test_convert_json(
input_args = "y\ny\n" if "-y" not in cli_args else ""

monkeypatch.setattr("sys.stdin", io.StringIO(input_args))
try:
with contextlib.suppress(SystemExit):
cli.cli(cli_args)
except SystemExit:
pass


tmuxp_yaml = tmp_path / ".tmuxp.yaml"
assert tmuxp_yaml.exists()
Expand Down
Loading

0 comments on commit 248dda5

Please sign in to comment.