From 8a0951c727c1179c9de1b1c974e79809703864f3 Mon Sep 17 00:00:00 2001 From: GeoffreyCoulaud Date: Wed, 10 May 2023 00:53:36 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Sorted=20imports,=20made=20pylin?= =?UTF-8?q?t=20happy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/importer/importer.py | 22 +++++++++++----------- src/importer/source.py | 25 +++++++++++-------------- src/importer/sources/lutris_source.py | 8 ++++---- src/utils/decorators.py | 16 +++++++--------- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/importer/importer.py b/src/importer/importer.py index 2015a04..b0d94ae 100644 --- a/src/importer/importer.py +++ b/src/importer/importer.py @@ -1,7 +1,7 @@ -from threading import Thread, Lock -from gi.repository import Adw, Gtk, Gio +from threading import Lock, Thread + +from gi.repository import Adw, Gtk -from .game import Game from .steamgriddb import SGDBHelper @@ -18,7 +18,7 @@ class Importer: games_lock = None games = None - def __init__(self, win) -> None: + def __init__(self, win): self.games = set() self.sources = set() self.counts = dict() @@ -77,12 +77,12 @@ class Importer: print(f"{source.full_name}, installed: {source.is_installed}") if not source.is_installed: continue - t = Thread(target=self.__import_source__, args=tuple([source])) # fmt: skip - threads.append(t) - t.start() + thread = Thread(target=self.__import_source__, args=tuple([source])) # fmt: skip + threads.append(thread) + thread.start() - for t in threads: - t.join() + for thread in threads: + thread.join() # Save games for game in self.games: @@ -95,11 +95,11 @@ class Importer: self.close_dialog() - def __import_source__(self, *args, **kwargs): + def __import_source__(self, *args, **_kwargs): """Source import thread entry point""" # TODO error handling in source iteration # TODO add SGDB image (move to a game manager) - source, *rest = args + source, *_rest = args iterator = source.__iter__() with self.progress_lock: self.counts[source.id]["total"] = len(iterator) diff --git a/src/importer/source.py b/src/importer/source.py index c53687d..2576034 100644 --- a/src/importer/source.py +++ b/src/importer/source.py @@ -38,41 +38,38 @@ class Source(Iterable): @property def full_name(self): """The source's full name""" - s = self.name + full_name_ = self.name if self.variant is not None: - s += f" ({self.variant})" - return s + full_name_ += f" ({self.variant})" + return full_name_ @property - def id(self): + def id(self): # pylint: disable=invalid-name """The source's identifier""" - s = self.name.lower() + id_ = self.name.lower() if self.variant is not None: - s += f"_{self.variant.lower()}" - return s + id_ += f"_{self.variant.lower()}" + return id_ @property def game_id_format(self): """The string format used to construct game IDs""" - f = self.name.lower() + format_ = self.name.lower() if self.variant is not None: - f += f"_{self.variant.lower()}" - f += "_{game_id}" - return f + format_ += f"_{self.variant.lower()}" + format_ += "_{game_id}" + return format_ @property @abstractmethod def executable_format(self): """The executable format used to construct game executables""" - pass @property @abstractmethod def is_installed(self): """Whether the source is detected as installed""" - pass @abstractmethod def __iter__(self): """Get the source's iterator, to use in for loops""" - pass diff --git a/src/importer/sources/lutris_source.py b/src/importer/sources/lutris_source.py index 44e6bea..b98c603 100644 --- a/src/importer/sources/lutris_source.py +++ b/src/importer/sources/lutris_source.py @@ -2,10 +2,10 @@ from functools import cache from sqlite3 import connect from time import time +from .decorators import replaced_by_path, replaced_by_schema_key from .game import Game from .save_cover import resize_cover, save_cover from .source import Source, SourceIterator -from .decorators import replaced_by_schema_key, replaced_by_path class LutrisSourceIterator(SourceIterator): @@ -128,7 +128,7 @@ class LutrisNativeSource(LutrisSource): @property @replaced_by_schema_key("lutris-cache-location") - @replaced_by_path("~/.local/share/lutris/covers") + @replaced_by_path("~/.local/share/lutris/covers/") def cache_location(self): raise FileNotFoundError() @@ -140,12 +140,12 @@ class LutrisFlatpakSource(LutrisSource): @property @replaced_by_schema_key("lutris-flatpak-location") - @replaced_by_path("~/.var/app/net.lutris.Lutris/data/lutris") + @replaced_by_path("~/.var/app/net.lutris.Lutris/data/lutris/") def location(self): raise FileNotFoundError() @property @replaced_by_schema_key("lutris-flatpak-cache-location") - @replaced_by_path("~/.var/app/net.lutris.Lutris/data/lutris/covers") + @replaced_by_path("~/.var/app/net.lutris.Lutris/data/lutris/covers/") def cache_location(self): raise FileNotFoundError() diff --git a/src/utils/decorators.py b/src/utils/decorators.py index e38a017..0ec1ea7 100644 --- a/src/utils/decorators.py +++ b/src/utils/decorators.py @@ -18,18 +18,17 @@ from os import PathLike from functools import wraps -def replaced_by_path(path: PathLike): # Decorator builder +def replaced_by_path(override: PathLike): # Decorator builder """Replace the method's returned path with the override if the override exists on disk""" def decorator(original_function): # Built decorator (closure) @wraps(original_function) def wrapper(*args, **kwargs): # func's override - p = Path(path).expanduser() - if p.exists(): - return p - else: - return original_function(*args, **kwargs) + path = Path(override).expanduser() + if path.exists(): + return path + return original_function(*args, **kwargs) return wrapper @@ -46,10 +45,9 @@ def replaced_by_schema_key(key: str): # Decorator builder schema = args[0].win.schema try: override = schema.get_string(key) - except Exception: + except Exception: # pylint: disable=broad-exception-caught return original_function(*args, **kwargs) - else: - return replaced_by_path(override)(original_function)(*args, **kwargs) + return replaced_by_path(override)(original_function)(*args, **kwargs) return wrapper