Skip to content

Commit

Permalink
style: ruff updated to 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Feb 17, 2024
1 parent c26ac01 commit d0bb66f
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 69 deletions.
2 changes: 1 addition & 1 deletion maintenance_scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ else
deactivate
fi
if [[ "$FIX_MODE" -eq 1 ]] ; then
"${APP_DIR}/env/bin/ruff" --fix "${TARGETS[@]}" || true
"${APP_DIR}/env/bin/ruff" --unsafe-fixes --fix "${TARGETS[@]}" || true
else
"${APP_DIR}/env/bin/ruff" "${TARGETS[@]}"
fi
Expand Down
6 changes: 3 additions & 3 deletions maintenance_scripts/makefile_shellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ def get_targets() -> list[str]:

def print_by_lines(text: str) -> None:
for idx, line in enumerate(text.splitlines()):
print(f"{idx+1}: {line}")
print(f"{idx + 1}: {line}")


def print_error_in_target(target: str) -> None:
print(
f"\n{'-'*30}\n"
f"\n{'-' * 30}\n"
f"ERROR in target `{target}`:"
f"\n{'-'*30}",
f"\n{'-' * 30}",
)


Expand Down
8 changes: 4 additions & 4 deletions oomox_gui/colors_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,11 +651,11 @@ def _callback(key: str, value: "ThemeValueT") -> None:
theme_option["fallback_value"] = value
self.theme = self.theme_reload_callback()
callbacks = [_callback]
elif theme_value.get("reload_options") or key in [
elif theme_value.get("reload_options") or key in {
"ICONS_STYLE", "THEME_STYLE",
"TERMINAL_BASE_TEMPLATE", "TERMINAL_THEME_MODE",
"TERMINAL_THEME_AUTO_BGFG", "TERMINAL_FG", "TERMINAL_BG",
]:
}:
def _callback( # pylint:disable=unused-argument
key: str, # noqa: ARG001
value: "ThemeValueT", # noqa: ARG001
Expand Down Expand Up @@ -771,9 +771,9 @@ def open_theme( # pylint: disable=too-many-branches,too-many-locals
):
row.hide()
continue
if theme_value["type"] in (
if theme_value["type"] in {
"color", "options", "bool", "int", "float", "image_path",
):
}:
if not isinstance(row, OomoxListBoxRow):
wrong_row_type = (
f"Row is of type {theme_value['type']}"
Expand Down
2 changes: 1 addition & 1 deletion oomox_gui/export_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def __init__(
override_options: dict[str, "Any"] | None = None,
**kwargs: "Any",
) -> None:
if os.environ.get("XDG_CURRENT_DESKTOP", "").lower() in ("kde", "lxqt"):
if os.environ.get("XDG_CURRENT_DESKTOP", "").lower() in {"kde", "lxqt"}:
self.default_export_dir = os.path.join(
os.environ.get(
"XDG_DATA_HOME",
Expand Down
14 changes: 7 additions & 7 deletions oomox_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(self, transient_for: Gtk.Window) -> None:


def dialog_is_yes(dialog: Gtk.Dialog) -> bool:
return dialog.run() in (Gtk.ResponseType.YES, Gtk.ResponseType.OK)
return dialog.run() in {Gtk.ResponseType.YES, Gtk.ResponseType.OK}


class AppActions(ActionsEnum):
Expand Down Expand Up @@ -174,7 +174,7 @@ def add_simple_action(
return action


class OomoxApplicationWindow(WindowWithActions): # pylint: disable=too-many-instance-attributes,too-many-public-methods # noqa: E501
class OomoxApplicationWindow(WindowWithActions): # pylint: disable=too-many-instance-attributes,too-many-public-methods

colorscheme_name: str
colorscheme_path: str
Expand Down Expand Up @@ -268,9 +268,9 @@ def import_themix_colors(self) -> None:
Gtk.FileChooserAction.OPEN, # type: ignore[arg-type]
)
filechooser_response = filechooser_dialog.run()
if filechooser_response in (
if filechooser_response in {
Gtk.ResponseType.CANCEL, Gtk.ResponseType.DELETE_EVENT,
):
}:
filechooser_dialog.destroy()
return
import_theme_path = filechooser_dialog.get_filename()
Expand All @@ -297,9 +297,9 @@ def import_from_plugin(self, plugin: "OomoxImportPlugin") -> None:
Gtk.FileChooserAction.OPEN, # type: ignore[arg-type]
)
filechooser_response = filechooser_dialog.run()
if filechooser_response in (
if filechooser_response in {
Gtk.ResponseType.CANCEL, Gtk.ResponseType.DELETE_EVENT,
):
}:
filechooser_dialog.destroy()
return
import_theme_path = filechooser_dialog.get_filename()
Expand Down Expand Up @@ -946,7 +946,7 @@ def do_command_line(self, _command_line: None) -> int: # pylint: disable=argume
self.activate()
return 0

def quit(self) -> None: # pylint: disable=arguments-differ # noqa: A003
def quit(self) -> None: # pylint: disable=arguments-differ
if self.window:
self.window.close()
else:
Expand Down
4 changes: 2 additions & 2 deletions oomox_gui/plugin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class PreviewImageboxesNames(Enum):
PreviewImageboxesNames.CHECKBOX.name: 16,
}

def preview_transform_function(
self, # noqa: PLR6301
def preview_transform_function( # noqa: PLR6301
self,
svg_template: str,
colorscheme: "ThemeT",
) -> str:
Expand Down
2 changes: 1 addition & 1 deletion oomox_gui/preset_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def _on_keypress(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> None:
return
if key == Keys.KEY_F5:
self.reload_presets()
elif key in (Keys.LEFT_ARROW, Keys.RIGHT_ARROW):
elif key in {Keys.LEFT_ARROW, Keys.RIGHT_ARROW}:
treepath = self._get_current_treepath()
if not treepath:
return
Expand Down
4 changes: 2 additions & 2 deletions oomox_gui/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ def override_widget_color(

def update_preview_carets(self, colorscheme: "ThemeT") -> None:
self.css_providers.caret.load_from_data((
(Gtk.get_minor_version() >= GTK_320_POSTFIX and """
((Gtk.get_minor_version() >= GTK_320_POSTFIX and """
* {{
caret-color: #{primary_caret_color};
-gtk-secondary-caret-color: #{secondary_caret_color};
-GtkWidget-cursor-aspect-ratio: {caret_aspect_ratio};
}}
""" or """
""") or """
* {{
-GtkWidget-cursor-color: #{primary_caret_color};
-GtkWidget-secondary-cursor-color: #{secondary_caret_color};
Expand Down
8 changes: 4 additions & 4 deletions oomox_gui/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ def show_shortcuts(parent_window: Gtk.Window) -> None:
"import_section",
PluginLoader.get_import_plugins(),
lambda plugin: (
plugin.import_text and
plugin.import_text.replace("_", "").replace("…", "") or
(plugin.import_text and
plugin.import_text.replace("_", "").replace("…", "")) or
translate("Import {plugin_name}").format(plugin_name=plugin.display_name)
),
),
(
"export_section",
PluginLoader.get_export_plugins(),
lambda plugin: (
plugin.export_text and
plugin.export_text.replace("_", "").replace("…", "") or
(plugin.export_text and
plugin.export_text.replace("_", "").replace("…", "")) or
translate("Export {plugin_name}").format(plugin_name=plugin.display_name)
),
),
Expand Down
16 changes: 9 additions & 7 deletions oomox_gui/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ def find_closest_color_key(
highlight_keys = [f"color{i}" for i in range(8, 15 + 1)]
for preset_key, preset_color in colors_hex.items():
if (
(
highlight
) and (
"color" not in preset_key
) and (
"color" not in preset_key
)
) or (
preset_key not in highlight_keys
):
Expand Down Expand Up @@ -213,7 +215,7 @@ def get_lightness(theme_color: str) -> int:
COLOR_SIMILARITY_IMPORTANCE: "Final" = 2.5


def _generate_theme_from_full_palette( # noqa: E501 pylint: disable=too-many-nested-blocks,too-many-locals,too-many-statements,too-many-branches
def _generate_theme_from_full_palette( # pylint: disable=too-many-nested-blocks,too-many-locals,too-many-statements,too-many-branches # noqa: E501,RUF100
result_callback: "Callable[[TerminalThemeT], None]",
reference_colors: dict[str, str],
all_colors: list[str],
Expand Down Expand Up @@ -301,7 +303,7 @@ def _generate_theme_from_full_palette( # noqa: E501 pylint: disable=too-many-n
),
)
if (
(key not in ["color0", "color7", "color8", "color15"])
(key not in {"color0", "color7", "color8", "color15"})
and (not min_lightness <= sum(new_value) <= max_lightness)
):
raise ContinueNext # noqa: TRY301
Expand Down Expand Up @@ -471,7 +473,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"] in {"auto"}:
colorscheme["TERMINAL_ACCENT_COLOR"] = colorscheme["SEL_BG"]
colorscheme["TERMINAL_BACKGROUND"] = colorscheme["TXT_BG"]
colorscheme["TERMINAL_FOREGROUND"] = colorscheme["TXT_FG"]
Expand Down Expand Up @@ -506,7 +508,7 @@ def _callback(term_colorscheme: TerminalThemeT) -> None:
result_callback=_callback,
)
return
if colorscheme["TERMINAL_THEME_MODE"] in ("basic", "auto"):
if colorscheme["TERMINAL_THEME_MODE"] in {"basic", "auto"}:
term_colorscheme = generate_theme_from_hint(
template_path=os.path.join(
TERMINAL_TEMPLATE_DIR, terminal_base_template,
Expand Down Expand Up @@ -587,7 +589,7 @@ def cli() -> None:
theme_fg = args[4]
theme_hint = args[CliArgs.THEME_HINT] if len(args) > CliArgs.THEME_HINT else None
auto_swap_colors = (
(args[CliArgs.AUTO_SWAP_COLORS] not in ["y", "yes", "true", "1"])
(args[CliArgs.AUTO_SWAP_COLORS] not in {"y", "yes", "true", "1"})
if len(args) > CliArgs.AUTO_SWAP_COLORS else
False
)
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 not in {"NOGUI"}
) and (
not key.startswith("_")
) and (
Expand Down
2 changes: 1 addition & 1 deletion plugins/icons_papirus/papirus-icon-theme
2 changes: 1 addition & 1 deletion plugins/import_from_image/oomox_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def _generate_terminal_palette_callback( # pylint: disable=too-many-locals
max_lightness = max_possible_lightness - lightness_delta

for key, value in reference_palette.items():
if key not in ["color0", "color7", "color8", "color15", "foreground", "background"]:
if key not in {"color0", "color7", "color8", "color15", "foreground", "background"}:
closest_color, _diff = find_closest_color(
value, bright_colors_list,
min_lightness=min_lightness, max_lightness=max_lightness,
Expand Down
84 changes: 50 additions & 34 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ ignore = ""
aggressive = 1

[tool.ruff]
preview = true
line-length = 120

[tool.ruff.lint.mccabe]
max-complexity = 19

[tool.ruff.format]
preview = true

[tool.ruff.lint]
preview = true
select = [
"F",
"E", "W",
Expand Down Expand Up @@ -47,59 +55,67 @@ select = [
"EXE",
"TCH",
"TRY",
#"PTH", # @TODO: refactor os.path to pathlib.Path
#"PTH", # @TODO: refactor os.path to pathlib.Path
"RUF",
]
ignore = [
# enable back later:
"C901", # "too complex"
"ERA001", # commented out code
# already managed by pylint, mb replace completely to ruff later:
"PLR0912", # too many branches
"PLR0913", # too many arguments
"PLR0915", # too many statements
# enable back later:
"C901", # "too complex"
"ERA001", # commented out code
# already managed by pylint, mb replace completely to ruff later:
"PLC0415", # `import` should be at the top-level of a file
"PLR0904", # Too many public methods
"PLR0912", # too many branches
"PLR0913", # too many arguments
"PLR0914", # too-many-locals
"PLR0915", # too many statements
"PLR0917", # Too many positional arguments
"PLR1702", # Too many nested blocks
# bandit stuff:
"S404",

"ANN101", # annotate self
"ANN102", # annotate cls
"ANN401", # disable Any
"ANN101", # annotate self
"ANN102", # annotate cls
"ANN401", # disable Any

"BLE001", # disallow catching Exception
"BLE001", # disallow catching Exception

# docstrings
"D100",
"D101",
"D102",
"D103",
#
"D105",
# docstrings
"D100",
"D101",
"D102",
"D103",
#
"D105",
"D106",
"D107",
"D203", # conflicts with D211
"D205",
"D212", # conflicts with D213
"D400",
"D401", # idk, it seems broken? pydocstyle.org is down so i can't check how it's supposed to work
"D415",
"D107",
"D203", # conflicts with D211
"D205",
"D212", # conflicts with D213
"D400",
"D401", # idk, it seems broken? pydocstyle.org is down so i can't check how it's supposed to work
"D415",
"PLR2044" # line with empty comment

#"Q000", # force double-quotes
#"Q000", # force double-quotes
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"oomog_gui/main.py" = [
"E402",
]
"plugins/*/oomox_plugin.py" = [
"INP001",
"INP001",
"RUF012",
"PLR6301",
]
"maintenance_scripts/*.py" = [
"INP001",
"T201",
"INP001",
"T201",
]
"maintenance_scripts/pikaman.py" = [
"ARG002",
"ARG002",
]
"maintenance_scripts/vulture_whitelist.py" = [
"B018",
"B018",
]

0 comments on commit d0bb66f

Please sign in to comment.