Browse Source

fixed pylint score

Dimitri Korsch 3 years ago
parent
commit
93b7cf4611

+ 2 - 1
.pylintrc

@@ -155,7 +155,8 @@ disable=print-statement,
         comprehension-escape,
         duplicate-code,
         missing-module-docstring,
-        too-many-instance-attributes
+        too-many-instance-attributes,
+        no-member
 
 # Enable the message, report, category or checker with the given id(s). You can
 # either give multiple identifier separated by comma (,) or put this option

+ 1 - 2
pycs/__init__.py

@@ -17,7 +17,7 @@ from sqlalchemy.engine import Engine
 
 
 print('=== Loading settings ===')
-with open('settings.json') as file:
+with open('settings.json', encoding='utf8') as file:
     settings = munchify(json.load(file))
 
 # create projects folder
@@ -48,4 +48,3 @@ db = SQLAlchemy(app, engine_options=dict(
     )
 )
 migrate = Migrate(app, db)
-

+ 2 - 1
pycs/database/File.py

@@ -212,7 +212,8 @@ class File(NamedBaseModel):
         result.data = data
 
         if label is not None:
-            assert isinstance(label, (int, Label, str)), f"Label \"{label}\" has invalid type: {type(label)}"
+            assert isinstance(label, (int, Label, str)), \
+                f"Label \"{label}\" has invalid type: {type(label)}"
 
             if isinstance(label, str):
                 label = Label.query.filter(

+ 2 - 2
pycs/database/LabelProvider.py

@@ -40,7 +40,7 @@ class LabelProvider(NamedBaseModel):
         """
 
         for folder, conf_path in _find_files(root):
-            with open(conf_path) as conf_file:
+            with open(conf_path, encoding='utf8') as conf_file:
                 config = json.load(conf_file)
 
             provider, _ = cls.get_or_create(
@@ -73,7 +73,7 @@ class LabelProvider(NamedBaseModel):
         :return: LabelProvider instance
         """
         # load configuration.json
-        with open(self.configuration_file_path) as configuration_file:
+        with open(self.configuration_file_path, encoding='utf8') as configuration_file:
             configuration = json.load(configuration_file)
 
         # load code

+ 1 - 1
pycs/database/Model.py

@@ -37,7 +37,7 @@ class Model(NamedBaseModel):
             and stores them in the database
         """
         for folder in Path(root).glob("*"):
-            with open(folder / config_name) as config_file:
+            with open(folder / config_name, encoding='utf8') as config_file:
                 config = json.load(config_file)
 
             # extract data

+ 1 - 1
pycs/database/Project.py

@@ -208,7 +208,7 @@ class Project(NamedBaseModel):
     def __check_labels(self, labels):
         """ check labels for unique keys and cycles """
 
-        unique_keys = dict()
+        unique_keys = {}
 
         for label in labels:
             key = (label["project_id"], label["reference"])

+ 2 - 1
pycs/interfaces/Pipeline.py

@@ -70,7 +70,8 @@ class Pipeline:
         """
         raise NotImplementedError
 
-    def pure_inference(self, storage: MediaStorage, file: MediaFile, bounding_boxes: List[MediaBoundingBox]):
+    def pure_inference(self, storage: MediaStorage, file: MediaFile,
+                       bounding_boxes: List[MediaBoundingBox]):
         """
         receive a file and a list of bounding boxes and only create a
         classification for the given bounding boxes.

+ 1 - 1
pycs/jobs/JobRunner.py

@@ -100,7 +100,7 @@ class JobRunner:
         :param identifier: job identifier
         :return:
         """
-        for i in range(len(self.__jobs)):
+        for i, job in enumerate(self.__jobs):
             if self.__jobs[i].identifier == identifier:
                 if self.__jobs[i].finished is not None:
                     job = self.__jobs[i]

+ 7 - 3
pycs/util/FileOperations.py

@@ -11,7 +11,6 @@ from tqdm import tqdm
 
 from pycs import app
 from pycs.database.File import File
-from pycs.database.Project import Project
 
 DEFAULT_JPEG_QUALITY = 80
 
@@ -252,7 +251,7 @@ def find_images(folder,
     """ walk recursively the folder and find images """
 
     suffixes = suffixes if suffixes is not None else [".jpg", ".jpeg", ".png"]
-    images: T.List[Path] = list()
+    images: T.List[Path] = []
     for root, _, files in os.walk(folder):
         for file in files:
             fpath = Path(root, file)
@@ -264,7 +263,12 @@ def find_images(folder,
     return images
 
 
-def generate_thumbnails(project: Project, sizes = [Size(200, 200), Size(2000, 1200)]):
+def generate_thumbnails(project: "Project", sizes = None):
+    """ generates thumbnails for all image files in the given  """
+
+    if sizes is None:
+        sizes = [Size(200, 200), Size(2000, 1200)]
+
     app.logger.info(f"Generating thumbnails for project \"{project.name}\"")
 
     files = list(project.files)

+ 1 - 1
pycs/util/PipelineUtil.py

@@ -13,7 +13,7 @@ def load_from_root_folder(root_folder: str) -> Pipeline:
     """
     # load configuration.json
     configuration_path = path.join(root_folder, 'configuration.json')
-    with open(configuration_path, 'r') as configuration_file:
+    with open(configuration_path, 'r', encoding='utf8') as configuration_file:
         configuration = load(configuration_file)
 
     # load code

+ 2 - 1
pycs/util/ProgressFileWriter.py

@@ -7,7 +7,8 @@ class ProgressFileWriter(BufferedWriter):
     """
 
     def __init__(self, path, mode, callback=None):
-        self.file_handler = open(path, mode)
+        # pylint: disable=consider-using-with
+        self.file_handler = open(path, mode, encoding='utf8')
 
         self.progress = 0
         self.callback = callback