Skip to content

Commit

Permalink
moved python files to /backend (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Jan 29, 2022
1 parent 5246fd9 commit ddf27ae
Show file tree
Hide file tree
Showing 25 changed files with 25 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/lint-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
npm install -g pyright
- run: mv configs.template.py configs.py
- name: Analysing the code with ${{ job.name }}
run: pyright --warnings
run: pyright --warnings backend
Pylint:
runs-on: ubuntu-latest
steps:
Expand All @@ -51,7 +51,7 @@ jobs:
pip install -r "scripts/requirements.txt"
- run: mv configs.template.py configs.py
- name: Analysing the code with ${{ job.name }}
run: pylint --reports=y --output-format=colorized $(git ls-files '**/*.py*')
run: pylint --reports=y --output-format=colorized $(git ls-files 'backend/*.py*')
Flake8:
runs-on: ubuntu-latest
steps:
Expand All @@ -68,7 +68,7 @@ jobs:
pip install -r "scripts/requirements.txt"
- run: mv configs.template.py configs.py
- name: Analysing the code with ${{ job.name }}
run: flake8
run: flake8 backend
Bandit:
runs-on: ubuntu-latest
steps:
Expand All @@ -85,4 +85,4 @@ jobs:
pip install -r "scripts/requirements.txt"
- run: mv configs.template.py configs.py
- name: Analysing the code with ${{ job.name }}
run: bandit -n 1 --severity-level medium --recursive .
run: bandit -n 1 --severity-level medium --recursive backend
3 changes: 2 additions & 1 deletion api/api_wrappers.py → backend/api/api_wrappers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json

from datetime import datetime, timedelta
from functools import wraps
from flask import current_app, jsonify, request
import json
import jwt

from models.core_models import Player
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ def __validate_create_schedule(data: Optional[JSONObjectType]):
except KeyError:
error_message += "active has to be defined"
try:
deadlineData = data["deadline"]
deadline = None if deadlineData is None else str(deadlineData)
deadline_data = data["deadline"]
deadline = None if deadline_data is None else str(deadline_data)
except KeyError:
error_message += "deadline has to be defined"
try:
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions flask_app.py → backend/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@
@app.route("/global-scoreboard/<path:asset>", methods=["GET"])
def global_scoreboard(asset: str):
if asset[:6] == "static":
return send_from_directory("global-scoreboard/build/", asset)
return send_file("global-scoreboard/build/index.html")
return send_from_directory("../global-scoreboard/build/", asset)
return send_file("../global-scoreboard/build/index.html")


@app.route("/tournament-scheduler/", defaults={"asset": "index.html"})
@app.route("/tournament-scheduler/<path:asset>", methods=["GET"])
def tournament_scheduler(asset: str):
if asset[:6] == "static":
return send_from_directory("tournament-scheduler/build/", asset)
return send_file("tournament-scheduler/build/index.html")
return send_from_directory("../tournament-scheduler/build/", asset)
return send_file("../tournament-scheduler/build/index.html")


@app.route("/", methods=["GET"])
Expand Down
4 changes: 2 additions & 2 deletions models/core_models.py → backend/models/core_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def get(user_id: str):

@staticmethod
def get_all():
sql = text("SELECT user_id, name, country_code, score, last_update, CONVERT(rank, SIGNED INT) rank FROM ( " +
" SELECT *, "
sql = text("SELECT user_id, name, country_code, score, last_update, CONVERT(rank, SIGNED INT) rank FROM ( "
+ " SELECT *, "
+ " IF(score = @_last_score, @cur_rank := @cur_rank, @cur_rank := @_sequence) AS rank, "
+ " @_sequence := @_sequence + 1, "
+ " @_last_score := score "
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions services/user_updater.py → backend/services/user_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from services.user_updater_helpers import BasicJSONType, extract_valid_personal_bests, get_probability_terms, \
get_subcategory_variables, keep_runs_before_soft_cutoff, MIN_LEADERBOARD_SIZE, update_runner_in_database, \
extract_top_runs_and_score, extract_sorted_valid_runs_from_leaderboard
from services.utils import clear_cache_for_user_async, get_file, get_paginated_response, MAXIMUM_RESULTS_PER_PAGE, \
SpeedrunComError, start_and_wait_for_threads, UserUpdaterError
from services.utils import clear_cache_for_user_async, get_file, get_paginated_response, \
MAXIMUM_RESULTS_PER_PAGE, SpeedrunComError, start_and_wait_for_threads, UserUpdaterError
import configs

TIME_BONUS_DIVISOR = 3600 * 12 # 12h (1/2 day) for +100%
Expand Down
File renamed without changes.
4 changes: 1 addition & 3 deletions services/utils.py → backend/services/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from types import TracebackType
from typing import Any, Literal, Optional, Union

from collections import Counter
from concurrent.futures import ThreadPoolExecutor
from contextlib import nullcontext
from datetime import timedelta
Expand Down Expand Up @@ -359,9 +360,6 @@ def start_and_wait_for_threads(fn, items: list):
) from exception


from collections import Counter


def get_duplicates(array: list):
counter = Counter(array)
return [key for key in counter if counter[key] > 1]
Expand Down
4 changes: 3 additions & 1 deletion global-scoreboard/src/Models/GameSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ export const fetchValueNamesForRun = async (runId: string) => {
{ [response.data.game.data.id]: response.data.game.data.names.international },
{ [response.data.category.data.id]: response.data.category.data.name },
])
.catch(() => requestsStartedForRun.delete(runId))
.catch(() => {
requestsStartedForRun.delete(runId)
})
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ evaluation = "10.0 - error - ((float((warning + convention) * 10 + refactor ) /
[tool.pylint.MASTER]
fail-under = 9.0
# Needed for Pylint to discover our own modules
init-hook = "import os, sys; sys.path.append(os.path.dirname('.'))"
init-hook = "from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.join(os.path.dirname(find_pylintrc()), 'backend'))"
# https://pylint.pycqa.org/en/latest/technical_reference/extensions.html
load-plugins = [
"pylint.extensions.emptystring",
Expand Down
8 changes: 4 additions & 4 deletions scripts/lint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Write-Host $Script:MyInvocation.MyCommand.Path
$exitCodes = 0

Write-Host "`nRunning Pyright..."
pyright --warnings
pyright --warnings backend
$exitCodes += $LastExitCode
if ($LastExitCode -gt 0) {
Write-Host "`Pyright failed ($LastExitCode)" -ForegroundColor Red
Expand All @@ -13,7 +13,7 @@ if ($LastExitCode -gt 0) {
}

Write-Host "`nRunning Pylint..."
pylint --score=n --output-format=colorized $(git ls-files '**/*.py')
pylint --score=n --output-format=colorized $(git ls-files 'backend/*.py')
$exitCodes += $LastExitCode
if ($LastExitCode -gt 0) {
Write-Host "`Pylint failed ($LastExitCode)" -ForegroundColor Red
Expand All @@ -22,7 +22,7 @@ if ($LastExitCode -gt 0) {
}

Write-Host "`nRunning Flake8..."
flake8
flake8 backend
$exitCodes += $LastExitCode
if ($LastExitCode -gt 0) {
Write-Host "`Flake8 failed ($LastExitCode)" -ForegroundColor Red
Expand All @@ -31,7 +31,7 @@ if ($LastExitCode -gt 0) {
}

Write-Host "`nRunning Bandit..."
bandit -f custom --silent --recursive src
bandit -f custom --silent --recursive backend
# $exitCodes += $LastExitCode # Returns 1 on low
if ($LastExitCode -gt 0) {
Write-Host "`Bandit warning ($LastExitCode)" -ForegroundColor Yellow
Expand Down

0 comments on commit ddf27ae

Please sign in to comment.