Skip to content

Commit

Permalink
style(ruff): enable FURB
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Jun 21, 2024
1 parent f4688c0 commit ec12ee6
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 50 deletions.
5 changes: 4 additions & 1 deletion oomox_gui/color.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import operator
from collections.abc import Sequence
from typing import TYPE_CHECKING, Annotated

Expand Down Expand Up @@ -29,7 +30,9 @@ def int_to_hex(num: int | float) -> "HexColor":


def color_list_from_hex(color_text: "HexColor") -> "tuple[str, str, str]":
return (color_text[:2], color_text[2:4], color_text[4:])
result: tuple[str, str, str]
result = operator.itemgetter(slice(2), slice(2, 4), slice(4, 6))(color_text)
return result


def int_list_from_hex(color_text: "HexColor") -> "IntColor":
Expand Down
6 changes: 3 additions & 3 deletions oomox_gui/colors_list.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
from typing import TYPE_CHECKING

from gi.repository import GLib, Gtk
Expand Down Expand Up @@ -519,9 +520,8 @@ class ImagePathListBoxRow(OomoxListBoxRow):
value_widget: ScaledImage

def set_value(self, value: str) -> None: # type: ignore[override]
with open(value, "rb") as image_file:
img_bytes = image_file.read()
self.value_widget.set_from_bytes(img_bytes)
img_bytes = Path(value).read_bytes()
self.value_widget.set_from_bytes(img_bytes)

def __init__(
self,
Expand Down
4 changes: 2 additions & 2 deletions oomox_gui/gtk_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from abc import ABCMeta, abstractmethod
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, ClassVar

from gi.repository import GdkPixbuf, Gio, GLib, Gtk
Expand Down Expand Up @@ -28,7 +28,7 @@ def get_id(self) -> str:
return f"{self.target}.{self.name}"


class ActionsEnum(metaclass=ABCMeta):
class ActionsEnum(ABC):

@property
@abstractmethod
Expand Down
4 changes: 2 additions & 2 deletions oomox_gui/plugin_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from abc import ABCMeta, abstractmethod
from abc import ABC, abstractmethod
from enum import Enum
from typing import TYPE_CHECKING, ClassVar

Expand All @@ -25,7 +25,7 @@ class AboutLink(TypedDict):
PLUGIN_PATH_PREFIX: "Final" = "__plugin__"


class OomoxPlugin(metaclass=ABCMeta):
class OomoxPlugin(ABC):

@property
@abstractmethod
Expand Down
12 changes: 5 additions & 7 deletions oomox_gui/preview.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path
from typing import TYPE_CHECKING

from gi.repository import GLib, Gtk
Expand Down Expand Up @@ -160,13 +161,10 @@ def create_menu(self, n_items: int, has_submenus: bool = False) -> Gtk.Menu:
def load_imageboxes_templates(self, theme_plugin: "OomoxThemePlugin") -> None:
for icon in theme_plugin.PreviewImageboxesNames:
template_path = f"{icon.value}.svg.template"
with open(
os.path.join(
theme_plugin.gtk_preview_dir, template_path,
), "rb",
) as file_object:
self.preview_imageboxes_templates[icon.name] = \
file_object.read().decode(DEFAULT_ENCODING)
data = Path(
Path(theme_plugin.gtk_preview_dir) / Path(template_path),
).read_bytes()
self.preview_imageboxes_templates[icon.name] = data.decode(DEFAULT_ENCODING)

def update_preview_imageboxes(
self, colorscheme: "ThemeT", theme_plugin: "OomoxThemePlugin",
Expand Down
12 changes: 5 additions & 7 deletions oomox_gui/preview_icons.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from enum import Enum
from pathlib import Path
from typing import TYPE_CHECKING

from gi.repository import Gtk
Expand Down Expand Up @@ -61,9 +61,7 @@ def load_icon_templates(self, theme_plugin: "OomoxIconsPlugin") -> None:
self.icons_plugin_name = theme_plugin.name
for icon in IconsNames:
template_path = f"{icon.value}.svg.template"
with open(
os.path.join(
theme_plugin.preview_svg_dir, template_path,
), "rb",
) as file_object:
self.icons_templates[icon.name] = file_object.read().decode(DEFAULT_ENCODING)
data = Path(
Path(theme_plugin.preview_svg_dir) / Path(template_path),
).read_bytes()
self.icons_templates[icon.name] = data.decode(DEFAULT_ENCODING)
43 changes: 23 additions & 20 deletions oomox_gui/terminal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import operator
import os
import shutil
import sys
from pathlib import Path
from typing import TYPE_CHECKING, ClassVar

from .color import (
Expand Down Expand Up @@ -70,21 +72,23 @@ def find_closest_color_key(

def import_xcolors(path: str) -> dict[str, str]:
hex_colors = {}
with open(os.path.expanduser(path), encoding=DEFAULT_ENCODING) as file_object:
for line in file_object.read().split("\n"):
if line.strip().startswith("!"):
continue
pair = [s.strip() for s in line.split(":")]
if len(pair) < 2: # noqa: PLR2004
continue
key, value = pair
key = key.replace("*", "")
value = value.replace("#", "").lower()
for char in value:
if char not in VALID_COLOR_CHARS:
break
else:
hex_colors[key] = value
text = Path(
os.path.expanduser(path),
).read_text(encoding=DEFAULT_ENCODING)
for line in text.split("\n"):
if line.strip().startswith("!"):
continue
pair = [s.strip() for s in line.split(":")]
if len(pair) < 2: # noqa: PLR2004
continue
key, value = pair
key = key.replace("*", "")
value = value.replace("#", "").lower()
for char in value:
if char not in VALID_COLOR_CHARS:
break
else:
hex_colors[key] = value
return hex_colors


Expand Down Expand Up @@ -250,10 +254,9 @@ def _generate_theme_from_full_palette( # pylint: disable=too-many-nested-blocks
] for key, value in hex_colors.items()
}
if extend_palette:
for color in all_colors[:]:
for color in all_colors.copy():
for i in (20, 40, 60):
all_colors.append(hex_darker(color, i))
all_colors.append(hex_darker(color, -i))
all_colors.extend((hex_darker(color, i), hex_darker(color, -i)))

grayest_colors = get_grayest_colors(all_colors)
bright_colors_set = set(all_colors)
Expand Down Expand Up @@ -414,7 +417,7 @@ def generate_theme_from_full_palette( # pylint: disable=too-many-arguments,too-
all_colors = sorted(get_all_colors_from_oomox_colorscheme(palette))
cache_id = str(
[
kwargs[name] for name in sorted(kwargs, key=lambda x: x[0])
kwargs[name] for name in sorted(kwargs, key=operator.itemgetter(0))
] + all_colors,
) + template_path + theme_bg + str(accuracy) + str(extend_palette)

Expand Down Expand Up @@ -473,7 +476,7 @@ def _generate_themes_from_oomox(
def _callback(term_colorscheme: TerminalThemeT) -> None:
_generate_themes_from_oomox_callback(colorscheme, term_colorscheme, result_callback)

if colorscheme["TERMINAL_THEME_MODE"] in {"auto"}:
if colorscheme["TERMINAL_THEME_MODE"] == "auto":
colorscheme["TERMINAL_ACCENT_COLOR"] = colorscheme["SEL_BG"]
colorscheme["TERMINAL_BACKGROUND"] = colorscheme["TXT_BG"]
colorscheme["TERMINAL_FOREGROUND"] = colorscheme["TXT_FG"]
Expand Down
2 changes: 1 addition & 1 deletion oomox_gui/theme_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def save_colorscheme(preset_name: str, colorscheme: "ThemeT", path: str | None =
with open(path, "w", encoding=DEFAULT_ENCODING) as file_object:
for key, value in sorted(colorscheme_to_write.items()):
if (
key not in {"NOGUI"}
key != "NOGUI"
) and (
not key.startswith("_")
) and (
Expand Down
2 changes: 1 addition & 1 deletion oomox_gui/theme_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _set_fallback_values(
theme_keys.append("NOGUI")

with open(preset_path, encoding=DEFAULT_ENCODING) as file_object:
for line in file_object.readlines():
for line in file_object:
key, _sep, value = line.strip().partition("=")
if key.startswith("#") or key not in theme_keys:
continue
Expand Down
2 changes: 1 addition & 1 deletion plugins/base16
Submodule base16 updated 1 files
+8 −9 oomox_plugin.py
2 changes: 1 addition & 1 deletion plugins/export_oomoxify
3 changes: 2 additions & 1 deletion plugins/export_xresources/oomox_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import re
from pathlib import Path
from typing import TYPE_CHECKING

from oomox_gui.config import DEFAULT_ENCODING
Expand Down Expand Up @@ -70,7 +71,7 @@ def do_export(self) -> None:
parent_dir = os.path.dirname(export_path)
if not os.path.exists(parent_dir):
os.makedirs(parent_dir)
with open(export_path, "w", encoding=DEFAULT_ENCODING) as fobj:
with Path(export_path).open("w", encoding=DEFAULT_ENCODING) as fobj:
fobj.write(self.xresources_theme)
self.remove_preset_name_from_path_config()
self.export_config.save()
Expand Down
2 changes: 1 addition & 1 deletion plugins/import_random/oomox_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def read_colorscheme_from_path(self, preset_path: str) -> "ThemeT":
randomizator = ColorRandomizator()

with open(preset_path, encoding=DEFAULT_ENCODING) as file_object:
for line in file_object.readlines():
for line in file_object:
key, _sep, value = line.strip().partition("=")
if key.startswith("#") or key not in theme_keys:
continue
Expand Down
2 changes: 1 addition & 1 deletion plugins/import_xresources/oomox_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def read_colorscheme_from_path(self, preset_path: str) -> dict[str, str]:
colorscheme = {}

with open(preset_path, encoding=DEFAULT_ENCODING) as file_object:
for line in file_object.readlines():
for line in file_object:
key, _sep, value = line.strip().partition("=")
if key.startswith("#") or key not in theme_keys:
continue
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ select = [
"FA",
"FIX",
"FLY",
#"FURB",
"FURB",
"G",
"INT",
"LOG",
Expand Down

0 comments on commit ec12ee6

Please sign in to comment.