Skip to content

Commit

Permalink
chore(ruff): Run automated fixes (97 errors)
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
tony committed Aug 26, 2023
1 parent 0553cfc commit bc964fe
Show file tree
Hide file tree
Showing 32 changed files with 146 additions and 184 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 :
13 changes: 5 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# flake8: NOQA: E501
import contextlib
import inspect
import pathlib
import sys
import typing as t
from os.path import relpath
import pathlib

import tmuxp

Expand Down Expand Up @@ -172,12 +172,12 @@
}

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

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

if lineno:
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1)
else:
linespec = ""
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1) if lineno else ""

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

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

# unset the hook immediately after executing
hook_cmd.append(
"set-hook -u -t {target_session} {hook_name}".format(
target_session=session.id, hook_name=hook_name
)
f"set-hook -u -t {session.id} {hook_name}"
)
hook_cmd.append(f"selectw -t {attached_window.id}")

Expand Down Expand Up @@ -122,8 +121,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/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def __init__(
self.cmd = cmd
self.output = output
self.message = (
"before_script failed with returncode {returncode}.\n"
"command: {cmd}\n"
f"before_script failed with returncode {self.returncode}.\n"
f"command: {self.cmd}\n"
"Error output:\n"
"{output}"
).format(returncode=self.returncode, cmd=self.cmd, output=self.output)
f"{self.output}"
)

def __str__(self):
return self.message
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
8 changes: 4 additions & 4 deletions src/tmuxp/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def run_before_script(
if e.errno == 2:
raise exc.BeforeLoadScriptNotExists(e, os.path.abspath(script_file))
else:
raise e
raise


def oh_my_zsh_auto_title() -> None:
Expand Down Expand Up @@ -87,7 +87,7 @@ def get_current_pane(server: "Server") -> t.Optional["Pane"]:
"""Return Pane if one found in env"""
if os.getenv("TMUX_PANE") is not None:
try:
return [p for p in server.panes if p.pane_id == os.getenv("TMUX_PANE")][0]
return next(p for p in server.panes if p.pane_id == os.getenv("TMUX_PANE"))
except IndexError:
pass
return None
Expand Down 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
23 changes: 8 additions & 15 deletions src/tmuxp/workspace/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __init__(
self,
session_config: t.Dict[str, t.Any],
server: Server,
plugins: t.List[t.Any] = [],
plugins: t.Optional[t.List[t.Any]] = None,
) -> None:
"""Initialize workspace loading.
Expand All @@ -162,6 +162,8 @@ def __init__(
``self.session``.
"""

if plugins is None:
plugins = []
if not session_config:
raise exc.EmptyWorkspaceException("Session configuration is empty.")

Expand Down Expand Up @@ -276,9 +278,9 @@ def build(self, session: t.Optional[Session] = None, append: bool = False) -> No
if "start_directory" in self.session_config:
cwd = self.session_config["start_directory"]
run_before_script(self.session_config["before_script"], cwd=cwd)
except Exception as e:
except Exception:
self.session.kill_session()
raise e
raise

if "options" in self.session_config:
for option, value in self.session_config["options"].items():
Expand Down Expand Up @@ -349,10 +351,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 +362,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
12 changes: 6 additions & 6 deletions src/tmuxp/workspace/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@

def is_workspace_file(
filename: str,
extensions: t.Union["ValidExtensions", t.List["ValidExtensions"]] = [
".yml",
".yaml",
".json",
],
extensions: t.Union["ValidExtensions", t.List["ValidExtensions"]] = None,
) -> bool:
"""
Return True if file has a valid workspace file type.
Expand All @@ -39,13 +35,15 @@ def is_workspace_file(
-------
bool
"""
if extensions is None:
extensions = [".yml", ".yaml", ".json"]
extensions = [extensions] if isinstance(extensions, str) else extensions
return any(filename.endswith(e) for e in extensions)


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

"""
Expand All @@ -62,6 +60,8 @@ def in_dir(
-------
list
"""
if extensions is None:
extensions = [".yml", ".yaml", ".json"]
workspace_files = []

for filename in os.listdir(workspace_dir):
Expand Down
5 changes: 3 additions & 2 deletions 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 All @@ -23,7 +24,7 @@ def inline(workspace_dict):
):
workspace_dict["shell_command"] = workspace_dict["shell_command"][0]

if len(workspace_dict.keys()) == int(1):
if len(workspace_dict.keys()) == 1:
workspace_dict = workspace_dict["shell_command"]
if (
"shell_command_before" in workspace_dict
Expand Down
Loading

0 comments on commit bc964fe

Please sign in to comment.