Skip to content

Commit

Permalink
linting: Reduce Class min-public-methods and fix spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
torzdf committed Apr 3, 2024
1 parent a9d87ae commit 9839014
Show file tree
Hide file tree
Showing 74 changed files with 155 additions and 158 deletions.
2 changes: 1 addition & 1 deletion lib/align/detected_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ def generate_mask(self, affine_matrix: np.ndarray, interpolator: int) -> None:
self.add(mask, affine_matrix, interpolator)


class BlurMask(): # pylint:disable=too-few-public-methods
class BlurMask():
""" Factory class to return the correct blur object for requested blur type.
Works for square images only. Currently supports Gaussian and Normalized Box Filters.
Expand Down
23 changes: 10 additions & 13 deletions lib/cli/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# << FILE HANDLING >>

class _FullPaths(argparse.Action): # pylint: disable=too-few-public-methods
class _FullPaths(argparse.Action):
""" Parent class for various file type and file path handling classes.
Expands out given paths to their full absolute paths. This class should not be
Expand Down Expand Up @@ -42,8 +42,7 @@ class DirFullPaths(_FullPaths):
>>> opts=("-f", "--folder_location"),
>>> action=DirFullPaths)),
"""
# pylint: disable=too-few-public-methods,unnecessary-pass
pass
pass # pylint:disable=unnecessary-pass


class FileFullPaths(_FullPaths):
Expand All @@ -68,7 +67,6 @@ class FileFullPaths(_FullPaths):
>>> action=FileFullPaths,
>>> filetypes="video))"
"""
# pylint: disable=too-few-public-methods
def __init__(self, *args, filetypes: str | None = None, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.filetypes = filetypes
Expand All @@ -87,7 +85,7 @@ def _get_kwargs(self):
return [(name, getattr(self, name)) for name in names]


class FilesFullPaths(FileFullPaths): # pylint: disable=too-few-public-methods
class FilesFullPaths(FileFullPaths):
""" Adds support for a File browser to select multiple files in the GUI.
This extends the standard :class:`argparse.Action` and adds an additional parameter
Expand Down Expand Up @@ -118,7 +116,7 @@ def __init__(self, *args, filetypes: str | None = None, **kwargs) -> None:
super().__init__(*args, **kwargs)


class DirOrFileFullPaths(FileFullPaths): # pylint: disable=too-few-public-methods
class DirOrFileFullPaths(FileFullPaths):
""" Adds support to the GUI to launch either a file browser or a folder browser.
Some inputs (for example source frames) can come from a folder of images or from a
Expand Down Expand Up @@ -147,7 +145,7 @@ class DirOrFileFullPaths(FileFullPaths): # pylint: disable=too-few-public-metho
"""


class DirOrFilesFullPaths(FileFullPaths): # pylint: disable=too-few-public-methods
class DirOrFilesFullPaths(FileFullPaths):
""" Adds support to the GUI to launch either a file browser for selecting multiple files
or a folder browser.
Expand Down Expand Up @@ -213,8 +211,7 @@ class SaveFileFullPaths(FileFullPaths):
>>> action=SaveFileFullPaths,
>>> filetypes="video"))
"""
# pylint: disable=too-few-public-methods,unnecessary-pass
pass
pass # pylint:disable=unnecessary-pass


class ContextFullPaths(FileFullPaths):
Expand Down Expand Up @@ -247,7 +244,7 @@ class ContextFullPaths(FileFullPaths):
>>> filetypes="video",
>>> action_option="-a"))
"""
# pylint: disable=too-few-public-methods, too-many-arguments
# pylint:disable=too-many-arguments
def __init__(self,
*args,
filetypes: str | None = None,
Expand Down Expand Up @@ -280,7 +277,7 @@ def _get_kwargs(self) -> list[tuple[str, T.Any]]:

# << GUI DISPLAY OBJECTS >>

class Radio(argparse.Action): # pylint: disable=too-few-public-methods
class Radio(argparse.Action):
""" Adds support for a GUI Radio options box.
This is a standard :class:`argparse.Action` (with stock parameters) which indicates to the GUI
Expand Down Expand Up @@ -309,7 +306,7 @@ def __call__(self, parser, namespace, values, option_string=None) -> None:
setattr(namespace, self.dest, values)


class MultiOption(argparse.Action): # pylint: disable=too-few-public-methods
class MultiOption(argparse.Action):
""" Adds support for multiple option checkboxes in the GUI.
This is a standard :class:`argparse.Action` (with stock parameters) which indicates to the GUI
Expand Down Expand Up @@ -337,7 +334,7 @@ def __call__(self, parser, namespace, values, option_string=None) -> None:
setattr(namespace, self.dest, values)


class Slider(argparse.Action): # pylint: disable=too-few-public-methods
class Slider(argparse.Action):
""" Adds support for a slider in the GUI.
The standard :class:`argparse.Action` is extended with the additional parameters listed below.
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _split_lines(self, text: str, width: int) -> list[str]:
txt = f" - {txt[2:]}"
output.extend(textwrap.wrap(txt, width, subsequent_indent=indent))
return output
return argparse.HelpFormatter._split_lines(self, # pylint: disable=protected-access
return argparse.HelpFormatter._split_lines(self, # pylint:disable=protected-access
text,
width)

Expand Down
6 changes: 3 additions & 3 deletions lib/cli/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
logger = logging.getLogger(__name__)


class ScriptExecutor(): # pylint:disable=too-few-public-methods
class ScriptExecutor():
""" Loads the relevant script modules and executes the script.
This class is initialized in each of the argparsers for the relevant
Expand Down Expand Up @@ -227,11 +227,11 @@ def execute_script(self, arguments: argparse.Namespace) -> None:
except FaceswapError as err:
for line in str(err).splitlines():
logger.error(line)
except KeyboardInterrupt: # pylint: disable=try-except-raise
except KeyboardInterrupt: # pylint:disable=try-except-raise
raise
except SystemExit:
pass
except Exception: # pylint: disable=broad-except
except Exception: # pylint:disable=broad-except
crash_file = crash_log()
logger.exception("Got Exception on main handler:")
logger.critical("An unexpected crash has occurred. Crash report written to '%s'. "
Expand Down
2 changes: 1 addition & 1 deletion lib/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def process(self, in_queue: EventQueue, out_queue: EventQueue):
item.inbound.filename)
try:
image = self._patch_image(item)
except Exception as err: # pylint: disable=broad-except
except Exception as err: # pylint:disable=broad-except
# Log error and output original frame
logger.error("Failed to convert image: '%s'. Reason: %s",
item.inbound.filename, str(err))
Expand Down
4 changes: 2 additions & 2 deletions lib/gpu_stats/directml.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class VendorID(Enum):


# STRUCTS
class StructureRepr(Structure): # pylint:disable=too-few-public-methods
class StructureRepr(Structure):
""" Override the standard structure class to add a useful __repr__ for logging """
def __repr__(self) -> str:
""" Output the class name and the structure contents """
Expand Down Expand Up @@ -155,7 +155,7 @@ class DXGIAdapterDesc1(StructureRepr): # pylint:disable=too-few-public-methods
("DedicatedSystemMemory", ctypes.c_size_t),
("SharedSystemMemory", ctypes.c_size_t),
("AdapterLuid", LUID),
("Flags", DXGIAdapterFlag.ctype)] # type:ignore[attr-defined] # pylint: disable=no-member
("Flags", DXGIAdapterFlag.ctype)] # type:ignore[attr-defined] # pylint:disable=no-member


class DXGIQueryVideoMemoryInfo(StructureRepr): # pylint:disable=too-few-public-methods
Expand Down
2 changes: 1 addition & 1 deletion lib/gpu_stats/nvidia.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _initialize(self) -> None:
"remove and reinstall your Nvidia drivers before reporting. Original "
f"Error: {str(err)}")
raise FaceswapError(msg) from err
except Exception as err: # pylint: disable=broad-except
except Exception as err: # pylint:disable=broad-except
msg = ("An unhandled exception occured reading from the Nvidia Machine Learning "
f"Library. Original error: {str(err)}")
raise FaceswapError(msg) from err
Expand Down
2 changes: 1 addition & 1 deletion lib/gui/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class Config(FaceswapConfig):
""" Config File for GUI """
# pylint: disable=too-many-statements
# pylint:disable=too-many-statements
def set_defaults(self):
""" Set the default values for config """
logger.debug("Setting defaults")
Expand Down
2 changes: 1 addition & 1 deletion lib/gui/analysis/event_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def get_timestamps(self, session_id: int | None = None) -> dict[int, np.ndarray]
return retval


class _EventParser(): # pylint:disable=too-few-public-methods
class _EventParser():
""" Parses Tensorflow event and populates data to :class:`_Cache`.
Parameters
Expand Down
4 changes: 2 additions & 2 deletions lib/gui/analysis/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def get_loss_keys(self, session_id: int | None) -> list[str]:
_SESSION = GlobalSession()


class SessionsSummary(): # pylint:disable=too-few-public-methods
class SessionsSummary():
""" Performs top level summary calculations for each session ID within the loaded or currently
training Session for display in the Analysis tree view.
Expand Down Expand Up @@ -853,7 +853,7 @@ def _calc_trend(cls, data: np.ndarray) -> np.ndarray:
return trend


class _ExponentialMovingAverage(): # pylint:disable=too-few-public-methods
class _ExponentialMovingAverage():
""" Reshapes data before calculating exponential moving average, then iterates once over the
rows to calculate the offset without precision issues.
Expand Down
4 changes: 2 additions & 2 deletions lib/gui/control_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def add_scrollbar(self):
self.mainframe.bind("<Configure>", self.update_scrollbar)
logger.debug("Added Config Scrollbar")

def update_scrollbar(self, event): # pylint: disable=unused-argument
def update_scrollbar(self, event): # pylint:disable=unused-argument
""" Update the options frame scrollbar """
self._canvas.configure(scrollregion=self._canvas.bbox("all"))

Expand Down Expand Up @@ -908,7 +908,7 @@ class ControlBuilder():
blank_nones: bool
Sets selected values to an empty string rather than None if this is true.
"""
def __init__(self, parent, option, option_columns, # pylint: disable=too-many-arguments
def __init__(self, parent, option, option_columns, # pylint:disable=too-many-arguments
label_width, checkbuttons_frame, style, blank_nones):
logger.debug("Initializing %s: (parent: %s, option: %s, option_columns: %s, "
"label_width: %s, checkbuttons_frame: %s, style: %s, blank_nones: %s)",
Expand Down
18 changes: 9 additions & 9 deletions lib/gui/custom_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
logger = logging.getLogger(__name__)


class ContextMenu(tk.Menu): # pylint: disable=too-many-ancestors
class ContextMenu(tk.Menu): # pylint:disable=too-many-ancestors
""" A Pop up menu to be triggered when right clicking on widgets that this menu has been
applied to.
Expand Down Expand Up @@ -72,7 +72,7 @@ def _select_all(self):
self._widget.select_range(0, tk.END)


class RightClickMenu(tk.Menu): # pylint: disable=too-many-ancestors
class RightClickMenu(tk.Menu): # pylint:disable=too-many-ancestors
""" A Pop up menu that can be bound to a right click mouse event to bring up a context menu
Parameters
Expand Down Expand Up @@ -118,7 +118,7 @@ def popup(self, event):
self.tk_popup(event.x_root, event.y_root)


class ConsoleOut(ttk.Frame): # pylint: disable=too-many-ancestors
class ConsoleOut(ttk.Frame): # pylint:disable=too-many-ancestors
""" The Console out section of the GUI.
A Read only text box for displaying the output from stdout/stderr.
Expand Down Expand Up @@ -195,7 +195,7 @@ def _redirect_console(self):
sys.stderr = _SysOutRouter(self._console, "stderr")
logger.debug("Redirected console")

def _clear(self, *args): # pylint: disable=unused-argument
def _clear(self, *args): # pylint:disable=unused-argument
""" Clear the console output screen """
logger.debug("Clear console")
if not self._console_clear.get():
Expand All @@ -206,7 +206,7 @@ def _clear(self, *args): # pylint: disable=unused-argument
logger.debug("Cleared console")


class _ReadOnlyText(tk.Text): # pylint: disable=too-many-ancestors
class _ReadOnlyText(tk.Text): # pylint:disable=too-many-ancestors
""" A read only text widget.
Standard tkinter Text widgets are read/write by default. As we want to make the console
Expand Down Expand Up @@ -417,7 +417,7 @@ def __call__(self, *args):
return self.tk_call(self.orig_and_operation + args)


class StatusBar(ttk.Frame): # pylint: disable=too-many-ancestors
class StatusBar(ttk.Frame): # pylint:disable=too-many-ancestors
""" Status Bar for displaying the Status Message and Progress Bar at the bottom of the GUI.
Parameters
Expand Down Expand Up @@ -725,7 +725,7 @@ def _hide(self):
self._topwidget = None


class MultiOption(ttk.Checkbutton): # pylint: disable=too-many-ancestors
class MultiOption(ttk.Checkbutton): # pylint:disable=too-many-ancestors
""" Similar to the standard :class:`ttk.Radio` widget, but with the ability to select
multiple pre-defined options. Selected options are generated as `nargs` for the argument
parser to consume.
Expand Down Expand Up @@ -767,7 +767,7 @@ def _master_needs_update(self):
logger.trace(retval)
return retval

def _on_update(self, *args): # pylint: disable=unused-argument
def _on_update(self, *args): # pylint:disable=unused-argument
""" Update the master variable on a check button change.
The value for this checked option is added or removed from the :attr:`_master_variable`
Expand All @@ -788,7 +788,7 @@ def _on_update(self, *args): # pylint: disable=unused-argument
logger.trace("Setting master variable to: %s", val)
self._master_variable.set(val)

def _on_master_update(self, *args): # pylint: disable=unused-argument
def _on_master_update(self, *args): # pylint:disable=unused-argument
""" Update the check button on a master variable change (e.g. load .fsw file in the GUI).
The value for this option is set to ``True`` or ``False`` depending on it's existence in
Expand Down
4 changes: 2 additions & 2 deletions lib/gui/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
_ = _LANG.gettext


class DisplayNotebook(ttk.Notebook): # pylint: disable=too-many-ancestors
class DisplayNotebook(ttk.Notebook): # pylint:disable=too-many-ancestors
""" The tkinter Notebook that holds the display items.
Parameters
Expand Down Expand Up @@ -152,7 +152,7 @@ def _remove_tabs(self):
child_object.close() # Call the OptionalDisplayPage close() method
self.forget(child)

def _update_displaybook(self, *args): # pylint: disable=unused-argument
def _update_displaybook(self, *args): # pylint:disable=unused-argument
""" Callback to be executed when the global tkinter variable `display`
(:attr:`wrapper_var`) is updated when a Faceswap task is executed.
Expand Down
4 changes: 2 additions & 2 deletions lib/gui/display_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
_ = _LANG.gettext


class Analysis(DisplayPage): # pylint: disable=too-many-ancestors
class Analysis(DisplayPage): # pylint:disable=too-many-ancestors
""" Session Analysis Tab.
The area of the GUI that holds the session summary stats for model training sessions.
Expand Down Expand Up @@ -366,7 +366,7 @@ def _set_buttons_state(self, *args): # pylint:disable=unused-argument
button.state([state])


class StatsData(ttk.Frame): # pylint: disable=too-many-ancestors
class StatsData(ttk.Frame): # pylint:disable=too-many-ancestors
""" Stats frame of analysis tab.
Holds the tree-view containing the summarized session statistics in the Analysis tab.
Expand Down
6 changes: 3 additions & 3 deletions lib/gui/display_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
_ = _LANG.gettext


class PreviewExtract(DisplayOptionalPage): # pylint: disable=too-many-ancestors
class PreviewExtract(DisplayOptionalPage): # pylint:disable=too-many-ancestors
""" Tab to display output preview images for extract and convert """
def __init__(self, *args, **kwargs) -> None:
logger.debug(parse_class_init(locals()))
Expand Down Expand Up @@ -80,7 +80,7 @@ def save_items(self) -> None:
print(f"Saved preview to {filename}")


class PreviewTrain(DisplayOptionalPage): # pylint: disable=too-many-ancestors
class PreviewTrain(DisplayOptionalPage): # pylint:disable=too-many-ancestors
""" Training preview image(s) """
def __init__(self, *args, **kwargs) -> None:
logger.debug(parse_class_init(locals()))
Expand Down Expand Up @@ -163,7 +163,7 @@ def save_items(self) -> None:
self._display.save(location)


class GraphDisplay(DisplayOptionalPage): # pylint: disable=too-many-ancestors
class GraphDisplay(DisplayOptionalPage): # pylint:disable=too-many-ancestors
""" The Graph Tab of the Display section """
def __init__(self,
parent: ttk.Notebook,
Expand Down

0 comments on commit 9839014

Please sign in to comment.