From e7f423557ea3f1a5c99a238c5ada6cb2dfa7139b Mon Sep 17 00:00:00 2001 From: Kaminyou Date: Fri, 19 Jan 2024 23:56:29 +0800 Subject: [PATCH] linting and cicd --- .github/workflows/main.yml | 17 +++++++++++++++++ backend/routers/manager.py | 26 ++++++++++++++++++++------ backend/setup.cfg | 5 ++++- backend/wsgi.py | 1 + setup.cfg | 5 +++++ 5 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 setup.cfg diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..5a78f71 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,17 @@ +name: flake8 Lint + +on: [push, pull_request] + +jobs: + flake8-lint: + runs-on: ubuntu-latest + name: Lint + steps: + - name: Check out source repository + uses: actions/checkout@v3 + - name: Set up Python environment + uses: actions/setup-python@v4 + with: + python-version: "3.11" + - name: flake8 Lint + uses: py-actions/flake8@v2 diff --git a/backend/routers/manager.py b/backend/routers/manager.py index deeca47..6ec1bf3 100644 --- a/backend/routers/manager.py +++ b/backend/routers/manager.py @@ -118,7 +118,10 @@ def change_subordinate_password(): user_account = request.form["account"] new_password = request.form["password"] - if SubordinateModel.find_by_account_and_subordinate(account=account, subordinate=user_account) is None: + if SubordinateModel.find_by_account_and_subordinate( + account=account, + subordinate=user_account, + ) is None: return {'msg': 'User does not exist'}, HTTPStatus.FORBIDDEN if UserModel.find_by_account(account=user_account) is None: @@ -152,7 +155,10 @@ def manager_upload_gait_csv(): request_form = request.form.to_dict() target_account = request_form['account'] # should be subordinate request_form.pop('account', None) - if SubordinateModel.find_by_account_and_subordinate(account=account, subordinate=target_account) is None: + if SubordinateModel.find_by_account_and_subordinate( + account=account, + subordinate=target_account, + ) is None: return {'msg': 'User does not exist'}, HTTPStatus.FORBIDDEN form_data = request_schema.load(request_form) @@ -213,7 +219,10 @@ def manager_request_results(): return {'msg': 'User does not exist'}, HTTPStatus.FORBIDDEN target_account = request.form['account'] - if SubordinateModel.find_by_account_and_subordinate(account=account, subordinate=target_account) is None: + if SubordinateModel.find_by_account_and_subordinate( + account=account, + subordinate=target_account, + ) is None: return {'msg': 'User does not exist'}, HTTPStatus.FORBIDDEN request_objects = RequestModel.find_by_account_and_sort_by_exp_date(account=target_account) @@ -326,7 +335,7 @@ def manager_request_report_download(): stage = profile_object.__dict__['stage'] dominantSide = profile_object.__dict__['dominantSide'] lded = profile_object.__dict__['lded'] - ss = f'{target_account},{name},{gender},{birthday},{diagnose},{stage},{dominantSide},{lded},' + ss = f'{target_account},{name},{gender},{birthday},{diagnose},{stage},{dominantSide},{lded},' # noqa orders = [ 'stride length', @@ -340,7 +349,9 @@ def manager_request_report_download(): request_objects = RequestModel.find_by_account(account=target_account) for request_object in request_objects: sss = ss + f'{request_object.__dict__["date"].strftime("%Y-%m-%d")}' - result_objects = ResultModel.find_by_requestUUID(requestUUID=request_object.__dict__["submitUUID"]) + result_objects = ResultModel.find_by_requestUUID( + requestUUID=request_object.__dict__["submitUUID"], + ) collections = { 'stride length': 0, 'stride width': 0, @@ -400,7 +411,10 @@ def manager_get_user_profile(): return {'msg': 'User does not exist'}, HTTPStatus.FORBIDDEN target_account = request.form['account'] - if SubordinateModel.find_by_account_and_subordinate(account=account, subordinate=target_account) is None: + if SubordinateModel.find_by_account_and_subordinate( + account=account, + subordinate=target_account, + ) is None: return {'msg': 'User does not exist'}, HTTPStatus.FORBIDDEN profile_object = ProfileModel.find_latest_by_account(account=target_account) diff --git a/backend/setup.cfg b/backend/setup.cfg index ccece61..59969e7 100644 --- a/backend/setup.cfg +++ b/backend/setup.cfg @@ -26,7 +26,8 @@ omit = *tests/*, **/_saferepr.py branch = True [flake8] -max-line-length = 119 +max-line-length = 100 +max-complexity = 10 ignore = # Do not assign a lambda expression, use a def (https://www.flake8rules.com/rules/E731.html) E731, @@ -38,6 +39,7 @@ ignore = D,DAR,RST # Found commented out code, not ready... E800 + C901 exclude = .git, @@ -49,6 +51,7 @@ exclude = build/ # sphinx docs docs/ + algorithms/gait_basic per-file-ignores = # allow non-optimized or insecure code in tests diff --git a/backend/wsgi.py b/backend/wsgi.py index d099b92..58d2795 100644 --- a/backend/wsgi.py +++ b/backend/wsgi.py @@ -1 +1,2 @@ +# flake8: noqa from app import app diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..507eefe --- /dev/null +++ b/setup.cfg @@ -0,0 +1,5 @@ +[flake8] +max-line-length = 100 +extend-ignore = C901 +exclude = backend/algorithms/gait_basic +max-complexity = 10 \ No newline at end of file