Skip to content

Commit

Permalink
Fix docstrings as per pydocstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
matuzalemmuller committed Jun 17, 2022
1 parent 6b16288 commit 7e7edd1
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 70 deletions.
3 changes: 1 addition & 2 deletions dummyfilescreator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
"""Author: Matuzalem (Mat) Muller.
Author: Matuzalem (Mat) Muller
License: GPLv3
"""
__version__ = "3.0.0"
Expand Down
8 changes: 4 additions & 4 deletions dummyfilescreator/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#! /usr/bin/env python3
"""
"""Author: Matuzalem (Mat) Muller.
Author: Matuzalem (Mat) Muller
License: GPLv3
"""
import sys


def main():
"""
Main function. If no parameters are provided, start in GUI mode. Otherwise,
"""Entrypoint.
If no parameters are provided, start in GUI mode. Otherwise,
run in CLI mode. The imports are done according to the execution mode: if
CLI mode is used it is not necessary to import all the PyQt libraries.
"""
Expand Down
22 changes: 6 additions & 16 deletions dummyfilescreator/dfc_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
"""Author: Matuzalem (Mat) Muller.
Author: Matuzalem (Mat) Muller
License: GPLv3
"""
import argparse
Expand All @@ -10,7 +9,6 @@


class DFCCli: # pylint: disable=too-many-instance-attributes

"""Class that provides CLI support."""

__slots__ = (
Expand All @@ -30,7 +28,7 @@ class DFCCli: # pylint: disable=too-many-instance-attributes
)

def __init__(self): # pylint: disable=too-many-branches
"""Saves arguments to internal atributes."""
"""Save arguments to internal atributes."""
parser = argparse.ArgumentParser(
description="""Application to generate dummy files. Run without arguments to start
in GUI mode or include arguments to use CLI mode."""
Expand Down Expand Up @@ -142,9 +140,7 @@ def print_progress(
file_name: str,
chunk_n: int,
):
"""
Updates progress bars while files are created.
"""
"""Update progress bars while files are created."""
self.pbar_total.n = n_created
self.pbar_total.refresh()
if self.verbose:
Expand All @@ -153,9 +149,7 @@ def print_progress(
self.pbar_file.refresh()

def error_function(self, error_message: str):
"""
Displays message when an error happens during file creation.
"""
"""Display message when an error happens during file creation."""
if self.pbar_total is not None:
self.pbar_total.close()
if self.pbar_file is not None:
Expand All @@ -164,9 +158,7 @@ def error_function(self, error_message: str):
sys.exit(1)

def complete_function(self):
"""
Shows completion message when all files are created.
"""
"""Show completion message when all files are created."""
if self.pbar_total is not None:
self.pbar_total.close()
if self.pbar_file is not None:
Expand All @@ -176,9 +168,7 @@ def complete_function(self):
print(f"Log file saved to {self.log_path}")

def run(self):
"""
Starts the file creation process.
"""
"""Start the file creation process."""
try:
if self.progressbar or self.verbose:
self.files_creator = FilesCreator(
Expand Down
26 changes: 11 additions & 15 deletions dummyfilescreator/dfc_ui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#! /usr/bin/env python3
"""
"""Author: Matuzalem (Mat) Muller.
Author: Matuzalem (Mat) Muller
License: GPLv3
"""
import math
Expand All @@ -27,12 +26,12 @@


class About(QDialog):

"""Displays About window."""

__slots__ = ("about_window")

def __init__(self):
"""Import Qt resource for icon and display the QDialog."""
super().__init__()
self.about_window = UiAbout()
self.about_window.setupUi(self)
Expand All @@ -43,9 +42,7 @@ def __init__(self):


class DFCUi(QMainWindow):
"""
Launches application window.
"""
"""Launch application window."""

__slots__ = ("main_window", "creator_thread")

Expand All @@ -54,6 +51,7 @@ class DFCUi(QMainWindow):
signal_complete = pyqtSignal()

def __init__(self):
"""Import Qt resource for icon and window UI, connect signals and display window."""
super().__init__()
self.main_window = UiMainWindow()
self.main_window.setupUi(self)
Expand Down Expand Up @@ -186,26 +184,26 @@ def emit_progress_bar_update(
file_name: str,
chunk_n: int,
):
"""
Emits signal to update progress bars while files are created.
"""Emit signal to update progress bars while files are created.
The signal invokes the method self.__update_progress_bar
This function is necessary because files_creator does not emit signals
and it cannot draw/modify the QMainWindow from this class.
"""
self.signal_update_progress.emit(n_created, file_name, chunk_n)

def emit_error_window(self, error_message: str):
"""
Emits signal to display message when an error happens during file creation.
"""Emit signal to display message when an error happens during file creation.
The signal invokes the method self.__display_error_message
This function is necessary because files_creator does not emit signals
and it cannot draw/modify the QMainWindow from this class.
"""
self.signal_error.emit(error_message)

def emit_display_success_message(self):
"""
Emits signal shows completion message when all files are created.
"""Emit signal shows completion message when all files are created.
The signal invokes the method self.__display_success_message
This function is necessary because files_creator does not emit signals
and it cannot draw/modify the QMainWindow from this class.
Expand Down Expand Up @@ -386,9 +384,7 @@ def __change_ui(self, state: str): # pylint: disable=too-many-statements


def main():
"""
Main function in case this file is executed directly.
"""
"""Entrypoint in case this file is executed directly."""
app = QApplication(sys.argv)
window = DFCUi()
window.show()
Expand Down
14 changes: 4 additions & 10 deletions dummyfilescreator/files_creator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
"""Author: Matuzalem (Mat) Muller.
Author: Matuzalem (Mat) Muller
License: GPLv3
"""
import hashlib
Expand All @@ -12,7 +11,6 @@


class FilesCreator(threading.Thread): # pylint: disable=too-many-instance-attributes

"""Creates files."""

__slots__ = (
Expand Down Expand Up @@ -47,10 +45,7 @@ def __init__( # pylint: disable=too-many-arguments, too-many-locals, too-many-b
update_function=None,
error_function=None,
):
"""
Saves parameters to internal atributes and computes how many chunks
should be created per file.
"""
"""Save parameters to internal atributes and computes how many chunks should be created per file.""" # pylint: disable=line-too-long
super().__init__()
self.folder_path = folder_path
self.number_files = number_files
Expand Down Expand Up @@ -145,6 +140,7 @@ def __create_file(self, file_path, n_created, file_name):
return True

def run(self):
"""Start file creation."""
for n_created in range(1, self.number_files + 1):
file_name = f"{uuid.uuid4()}.dummy"
file_path = f"{self.folder_path}/{file_name}"
Expand All @@ -164,7 +160,5 @@ def run(self):
return True

def kill(self):
"""
Sets the abort flag to true, which will stop the thread execution loop.
"""
"""Set the abort flag to true, which will stop the thread execution loop."""
self.abort = True
23 changes: 9 additions & 14 deletions dummyfilescreator/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
"""Author: Matuzalem (Mat) Muller.
Author: Matuzalem (Mat) Muller
License: GPLv3
"""
import csv
Expand All @@ -15,16 +14,16 @@


class CsvFormatter(logging.Formatter):
"""
Formats log entry as csv.
"""
"""Formats log entry as csv."""

def __init__(self):
"""Create csv write for log formatting."""
super().__init__()
self.output = io.StringIO()
self.writer = csv.writer(self.output, quoting=csv.QUOTE_ALL)

def format(self, record):
"""Return log record in csv format."""
self.writer.writerow(
[datetime.datetime.now(), record.file_size, record.msg, record.hash]
)
Expand All @@ -35,22 +34,20 @@ def format(self, record):


class CustomFilter(logging.Filter): # pylint: disable=too-few-public-methods
"""
Custom filter to save file size and hash to log file.
"""
"""Custom filter to save file size and hash to log file."""

def filter(self, record):
"""Include file size and hash in the log record."""
record.file_size = FILE_SIZE
record.hash = HASH
return True


class Logger: # pylint: disable=too-few-public-methods
"""
Logger class, to be used by classes that want to save log entries to file.
"""
"""Logger class, to be used by classes that want to save log entries to file."""

def __init__(self, log_path, error_function=None):
"""Create log file and set up logger formatter and filter."""
self.error_function = error_function
self.logger = logging.getLogger(str(uuid.uuid4()))
self.logger.setLevel(logging.DEBUG)
Expand All @@ -69,9 +66,7 @@ def __init__(self, log_path, error_function=None):
raise error

def log(self, f_path, f_size, f_hash=None):
"""
Saves log entry to log file.
"""
"""Save log record to log file."""
global FILE_SIZE # pylint: disable=global-statement
FILE_SIZE = f_size
global HASH # pylint: disable=global-statement
Expand Down
4 changes: 1 addition & 3 deletions dummyfilescreator/qt_about_window.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
"""Author: Matuzalem (Mat) Muller.
Author: Matuzalem (Mat) Muller
License: GPLv3
File autogenerated by pyuic5, based on design/qt/About.ui
"""
from PyQt5 import QtCore, QtWidgets
Expand Down
4 changes: 1 addition & 3 deletions dummyfilescreator/qt_icon.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
"""Author: Matuzalem (Mat) Muller.
Author: Matuzalem (Mat) Muller
License: GPLv3
File autogenerated by pyrcc5, based on the resource file for design/icon/icon.png (not included)
"""
from PyQt5 import QtCore
Expand Down
4 changes: 1 addition & 3 deletions dummyfilescreator/qt_main_window.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
"""Author: Matuzalem (Mat) Muller.
Author: Matuzalem (Mat) Muller
License: GPLv3
File autogenerated by pyuic5, based on design/qt/MainWindow.ui
"""
from PyQt5 import QtCore, QtWidgets
Expand Down

0 comments on commit 7e7edd1

Please sign in to comment.