浏览代码

improved pylint score

Dimitri Korsch 3 年之前
父节点
当前提交
f43cc12a13

+ 1 - 0
.pylintrc

@@ -318,6 +318,7 @@ good-names=i,
            k,
            k,
            ex,
            ex,
            id,
            id,
+           x, y, w, h, x0, y0, x1, y1,
            Run,
            Run,
            _
            _
 
 

+ 11 - 13
pycs/frontend/WebServer.py

@@ -1,16 +1,12 @@
-import eventlet
 import os
 import os
-import socketio
 
 
 from glob import glob
 from glob import glob
-from os import getcwd
-from os import path
-from os.path import exists
 
 
-from flask import Flask
+import eventlet
+import socketio
+
 from flask import send_from_directory
 from flask import send_from_directory
 
 
-from pycs import app
 from pycs.database.Model import Model
 from pycs.database.Model import Model
 from pycs.database.LabelProvider import LabelProvider
 from pycs.database.LabelProvider import LabelProvider
 from pycs.frontend.endpoints.ListJobs import ListJobs
 from pycs.frontend.endpoints.ListJobs import ListJobs
@@ -64,10 +60,10 @@ class WebServer:
 
 
     def __init__(self, app, settings: dict, discovery: bool = True):
     def __init__(self, app, settings: dict, discovery: bool = True):
 
 
-        PRODUCTION = os.path.exists('webui/index.html')
+        is_production = os.path.exists('webui/index.html')
 
 
         # initialize web server
         # initialize web server
-        if PRODUCTION:
+        if is_production:
             print('production build')
             print('production build')
 
 
             # find static files and folders
             # find static files and folders
@@ -89,13 +85,13 @@ class WebServer:
             else:
             else:
                 self.__sio = socketio.Server(async_mode='eventlet')
                 self.__sio = socketio.Server(async_mode='eventlet')
 
 
-            self.__app = socketio.WSGIApp(self.__sio, app, static_files=static_files)
+            self.wsgi_app = socketio.WSGIApp(self.__sio, app, static_files=static_files)
 
 
             # overwrite root path to serve index.html
             # overwrite root path to serve index.html
             @app.route('/', methods=['GET'])
             @app.route('/', methods=['GET'])
             def index():
             def index():
                 # pylint: disable=unused-variable
                 # pylint: disable=unused-variable
-                return send_from_directory(path.join(getcwd(), 'webui'), 'index.html')
+                return send_from_directory(os.path.join(os.getcwd(), 'webui'), 'index.html')
 
 
         else:
         else:
             print('development build')
             print('development build')
@@ -137,6 +133,7 @@ class WebServer:
 
 
 
 
     def define_routes(self, jobs, notifications, pipelines):
     def define_routes(self, jobs, notifications, pipelines):
+        """ defines app routes """
 
 
         # additional
         # additional
         self.app.add_url_rule(
         self.app.add_url_rule(
@@ -295,7 +292,8 @@ class WebServer:
         )
         )
         self.app.add_url_rule(
         self.app.add_url_rule(
             '/projects/<int:project_id>/external_storage',
             '/projects/<int:project_id>/external_storage',
-            view_func=ExecuteExternalStorage.as_view('execute_external_storage', notifications, jobs)
+            view_func=ExecuteExternalStorage.as_view('execute_external_storage',
+                                                     notifications, jobs)
         )
         )
         self.app.add_url_rule(
         self.app.add_url_rule(
             '/projects/<int:project_id>/remove',
             '/projects/<int:project_id>/remove',
@@ -326,5 +324,5 @@ class WebServer:
         )
         )
 
 
     def run(self):
     def run(self):
-        # finally start web server
+        """ start web server """
         eventlet.wsgi.server(eventlet.listen((self.host, self.port)), self.wsgi_app)
         eventlet.wsgi.server(eventlet.listen((self.host, self.port)), self.wsgi_app)

+ 0 - 1
pycs/frontend/endpoints/data/GetPreviousAndNextFile.py

@@ -1,4 +1,3 @@
-from flask import abort
 from flask import jsonify
 from flask import jsonify
 from flask.views import View
 from flask.views import View
 
 

+ 0 - 2
pycs/frontend/endpoints/data/GetResizedFile.py

@@ -22,8 +22,6 @@ class GetResizedFile(View):
         # get file from database
         # get file from database
         file = File.get_or_404(file_id)
         file = File.get_or_404(file_id)
 
 
-        project = file.project
-
         if not os.path.exists(file.absolute_path):
         if not os.path.exists(file.absolute_path):
             abort(404, "File not found!")
             abort(404, "File not found!")
 
 

+ 0 - 2
pycs/frontend/endpoints/data/RemoveFile.py

@@ -1,5 +1,3 @@
-from os import remove
-
 from flask import make_response, request, abort
 from flask import make_response, request, abort
 from flask.views import View
 from flask.views import View
 
 

+ 1 - 0
pycs/frontend/endpoints/data/UploadFile.py

@@ -96,4 +96,5 @@ class UploadFile(View):
 
 
         # open file handler
         # open file handler
         file_path = os.path.join(self.data_folder, f'{self.file_uuid}{self.file_extension}')
         file_path = os.path.join(self.data_folder, f'{self.file_uuid}{self.file_extension}')
+        #pylint: disable=consider-using-with
         return open(file_path, 'wb')
         return open(file_path, 'wb')

+ 14 - 18
pycs/frontend/endpoints/pipelines/FitModel.py

@@ -1,4 +1,6 @@
-from flask import make_response, request, abort
+from flask import abort
+from flask import make_response
+from flask import request
 from flask.views import View
 from flask.views import View
 
 
 from pycs.database.Project import Project
 from pycs.database.Project import Project
@@ -51,25 +53,19 @@ class FitModel(View):
         :param pipelines: pipeline cache
         :param pipelines: pipeline cache
         :param project_id: project id
         :param project_id: project id
         """
         """
-        database_copy = None
         pipeline = None
         pipeline = None
 
 
         # create new database instance
         # create new database instance
-        try:
-            database_copy = database.copy()
-            project = Project.query.get(project_id)
-            model = project.model
-            storage = MediaStorage(database_copy, project_id)
+        project = Project.query.get(project_id)
+        model = project.model
+        storage = MediaStorage(project_id)
 
 
-            # load pipeline
-            try:
-                pipeline = pipelines.load_from_root_folder(project, model.root_folder)
-                yield from pipeline.fit(storage)
-            except TypeError:
-                pass
-            finally:
-                if pipeline is not None:
-                    pipelines.free_instance(model.root_folder)
+        # load pipeline
+        try:
+            pipeline = pipelines.load_from_root_folder(project, model.root_folder)
+            yield from pipeline.fit(storage)
+        except TypeError:
+            pass
         finally:
         finally:
-            if database_copy is not None:
-                database_copy.close()
+            if pipeline is not None:
+                pipelines.free_instance(model.root_folder)

+ 4 - 1
pycs/frontend/endpoints/pipelines/PredictFile.py

@@ -1,6 +1,9 @@
-from flask import make_response, request, abort
+from flask import abort
+from flask import make_response
+from flask import request
 from flask.views import View
 from flask.views import View
 
 
+from pycs.database.File import File
 from pycs.frontend.endpoints.pipelines.PredictModel import PredictModel as Predict
 from pycs.frontend.endpoints.pipelines.PredictModel import PredictModel as Predict
 from pycs.frontend.notifications.NotificationList import NotificationList
 from pycs.frontend.notifications.NotificationList import NotificationList
 from pycs.frontend.notifications.NotificationManager import NotificationManager
 from pycs.frontend.notifications.NotificationManager import NotificationManager

+ 0 - 1
pycs/frontend/endpoints/pipelines/PredictModel.py

@@ -7,7 +7,6 @@ from flask import request
 from flask.views import View
 from flask.views import View
 
 
 from pycs import db
 from pycs import db
-from pycs.database.File import File
 from pycs.database.Project import Project
 from pycs.database.Project import Project
 from pycs.frontend.notifications.NotificationList import NotificationList
 from pycs.frontend.notifications.NotificationList import NotificationList
 from pycs.frontend.notifications.NotificationManager import NotificationManager
 from pycs.frontend.notifications.NotificationManager import NotificationManager

+ 0 - 1
pycs/frontend/endpoints/projects/CreateProject.py

@@ -1,4 +1,3 @@
-import os
 import shutil
 import shutil
 import uuid
 import uuid
 
 

+ 2 - 2
pycs/frontend/endpoints/projects/ListProjectCollections.py

@@ -1,8 +1,8 @@
-from flask import abort, jsonify
+from flask import jsonify
 from flask.views import View
 from flask.views import View
 
 
-from pycs.database.Project import Project
 from pycs.database.Collection import Collection
 from pycs.database.Collection import Collection
+from pycs.database.Project import Project
 
 
 
 
 class ListProjectCollections(View):
 class ListProjectCollections(View):

+ 7 - 2
pycs/frontend/endpoints/results/CreateResult.py

@@ -1,6 +1,9 @@
-from flask import request, abort, jsonify
+from flask import abort
+from flask import jsonify
+from flask import request
 from flask.views import View
 from flask.views import View
 
 
+from pycs import db
 from pycs.database.File import File
 from pycs.database.File import File
 from pycs.frontend.notifications.NotificationManager import NotificationManager
 from pycs.frontend.notifications.NotificationManager import NotificationManager
 
 
@@ -16,7 +19,9 @@ class CreateResult(View):
         # pylint: disable=invalid-name
         # pylint: disable=invalid-name
         self.nm = nm
         self.nm = nm
 
 
-    def extract_request_data(self):
+    @staticmethod
+    def extract_request_data():
+        """ get the data from the request and validate it """
         request_data = request.get_json(force=True)
         request_data = request.get_json(force=True)
 
 
         if 'type' not in request_data:
         if 'type' not in request_data:

+ 0 - 1
pycs/frontend/endpoints/results/GetProjectResults.py

@@ -1,4 +1,3 @@
-from flask import abort
 from flask import jsonify
 from flask import jsonify
 from flask.views import View
 from flask.views import View
 
 

+ 1 - 1
pycs/frontend/endpoints/results/GetResults.py

@@ -1,4 +1,4 @@
-from flask import abort, jsonify
+from flask import jsonify
 from flask.views import View
 from flask.views import View
 
 
 from pycs.database.File import File
 from pycs.database.File import File

+ 2 - 1
pycs/frontend/util/JSONEncoder.py

@@ -1,8 +1,9 @@
 import datetime
 import datetime
 
 
-from flask.json import JSONEncoder as Base
 from typing import Any
 from typing import Any
 
 
+from flask.json import JSONEncoder as Base
+
 from pycs.database.util.JSONEncoder import JSONEncoder as DatabaseEncoder
 from pycs.database.util.JSONEncoder import JSONEncoder as DatabaseEncoder
 from pycs.jobs.util.JSONEncoder import JSONEncoder as JobsEncoder
 from pycs.jobs.util.JSONEncoder import JSONEncoder as JobsEncoder
 
 

+ 1 - 0
pycs/interfaces/MediaBoundingBox.py

@@ -1,6 +1,7 @@
 from pycs.database.Result import Result
 from pycs.database.Result import Result
 
 
 
 
+#pylint: disable=too-few-public-methods
 class MediaBoundingBox:
 class MediaBoundingBox:
     """
     """
     A bounding box defined by it's upper left corner coordinates plus width and height. All those
     A bounding box defined by it's upper left corner coordinates plus width and height. All those

+ 1 - 0
pycs/interfaces/MediaImageLabel.py

@@ -1,6 +1,7 @@
 from pycs.database.Result import Result
 from pycs.database.Result import Result
 
 
 
 
+#pylint: disable=too-few-public-methods
 class MediaImageLabel:
 class MediaImageLabel:
     """
     """
     An image label with an optional frame index for videos.
     An image label with an optional frame index for videos.

+ 1 - 0
pycs/interfaces/MediaLabel.py

@@ -1,6 +1,7 @@
 from pycs.database.Label import Label
 from pycs.database.Label import Label
 
 
 
 
+#pylint: disable=too-few-public-methods
 class MediaLabel:
 class MediaLabel:
     """
     """
     a label
     a label

+ 3 - 0
pycs/interfaces/Pipeline.py

@@ -9,6 +9,7 @@ class Pipeline:
     pipeline interface that should be implemented by model developers
     pipeline interface that should be implemented by model developers
     """
     """
 
 
+    #pylint: disable=unnecessary-pass
     def __init__(self, root_folder: str, distribution: dict):
     def __init__(self, root_folder: str, distribution: dict):
         """
         """
         prepare everything needed to run jobs later
         prepare everything needed to run jobs later
@@ -18,6 +19,7 @@ class Pipeline:
         """
         """
         pass
         pass
 
 
+    #pylint: disable=unnecessary-pass
     def close(self):
     def close(self):
         """
         """
         is called everytime a pipeline is not needed anymore and should be used
         is called everytime a pipeline is not needed anymore and should be used
@@ -27,6 +29,7 @@ class Pipeline:
         """
         """
         pass
         pass
 
 
+    #pylint: disable=no-self-use
     def collections(self) -> List[dict]:
     def collections(self) -> List[dict]:
         """
         """
         is called while initializing a pipeline to receive available
         is called while initializing a pipeline to receive available

+ 1 - 1
pycs/util/file_ops.py

@@ -7,7 +7,7 @@ from PIL import Image
 
 
 from pycs.database.File import File
 from pycs.database.File import File
 
 
-# pylint: disable=too-many-arguments, invalid-name, too-many-locals
+# pylint: disable=too-many-arguments, too-many-locals
 def crop_file(file: File, project_root: str, x: float, y: float, w: float, h: float) -> str:
 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
     gets a file for the given file_id, crops the according image to the