6
0
Ver Fonte

improved pylint score

Dimitri Korsch há 4 anos atrás
pai
commit
ab774e0df9
3 ficheiros alterados com 17 adições e 10 exclusões
  1. 1 1
      .pylintrc
  2. 4 4
      pycs/frontend/endpoints/results/ResultAsCrop.py
  3. 12 5
      pycs/util/file_ops.py

+ 1 - 1
.pylintrc

@@ -347,7 +347,7 @@ module-naming-style=snake_case
 
 # Regular expression matching correct module names. Overrides module-naming-
 # style.
-module-rgx=^[A-Za-z0-9]+$
+module-rgx=^[A-Za-z0-9\_]+$
 
 # Colon-delimited sets of names that determine each other's naming style when
 # the name regexes allow several styles.

+ 4 - 4
pycs/frontend/endpoints/results/ResultAsCrop.py

@@ -22,12 +22,13 @@ class ResultAsCrop(View):
         result = Result.get_or_404(result_id)
 
         if result.type != "bounding-box":
-            abort(400, f"The type of the queried result was not \"bounding-box\"! It was {result.type}")
+            msg = f"The type of the queried result was not \"bounding-box\"! It was {result.type}"
+            abort(400, msg)
 
         file = result.file
 
         if file.type != "image":
-            abort(400, f"Currently only supporting images!")
+            abort(400, "Currently only supporting images!")
 
 
         data = result.data
@@ -39,9 +40,8 @@ class ResultAsCrop(View):
         if -1 in xywh:
             abort(400, f"The data of the result is not correct: {data}!")
 
-        x, y, w, h = xywh
 
-        crop_path, crop_fname = file_ops.crop_file(file, file.project.root_folder, x, y, w, h)
+        crop_path, crop_fname = file_ops.crop_file(file, file.project.root_folder, *xywh)
 
         parts = os.path.splitext(crop_fname)
 

+ 12 - 5
pycs/util/file_ops.py

@@ -1,12 +1,13 @@
-import cv2
 import os
+import typing as T
+
+import cv2
 
 from PIL import Image
-from typing import Tuple
-from typing import Optional
 
 from pycs.database.File import File
 
+# pylint: disable=too-many-arguments, invalid-name, too-many-locals
 def crop_file(file: File, project_root: str, x: float, y: float, w: float, h: float) -> str:
     """
     gets a file for the given file_id, crops the according image to the
@@ -46,7 +47,10 @@ def crop_file(file: File, project_root: str, x: float, y: float, w: float, h: fl
     return os.path.split(target_path)
 
 
-def resize_file(file: File, project_root: str, max_width: int, max_height: int) -> Tuple[str, str]:
+def resize_file(file: File,
+                project_root: str,
+                max_width: int,
+                max_height: int) -> T.Tuple[str, str]:
     """
     If file type equals video this function extracts a thumbnail first. It calls resize_image
     to resize and returns the resized files directory and name.
@@ -77,7 +81,10 @@ def resize_file(file: File, project_root: str, max_width: int, max_height: int)
 
     return os.path.split(abs_file_path)
 
-def resize_image(file_path: str, target_path: str, max_width: int, max_height: int) -> Optional[bool]:
+def resize_image(file_path: str,
+                 target_path: str,
+                 max_width: int,
+                 max_height: int) -> T.Optional[bool]:
     """
     resize an image so width < max_width and height < max_height