From 32061eed7b551780c478c7c278ceadc9e878a236 Mon Sep 17 00:00:00 2001 From: YOGESHWARAN R Date: Tue, 18 May 2021 09:21:33 +0530 Subject: [PATCH] Fixed all pep8 errors Removed unused imports, variables --- app/__init__.py | 2 +- app/api_keys.py | 1 + app/app.py | 15 ++++++++------- app/flood.py | 1 - app/init.py | 11 +++++------ app/language.py | 3 +-- app/main.py | 1 + app/manage.py | 1 + install_models.py | 4 ++-- setup.cfg | 12 ++++++++++++ tests/test_init.py | 1 - 11 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 setup.cfg diff --git a/app/__init__.py b/app/__init__.py index 885b941..208da59 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,8 +1,8 @@ import os -from appdirs import user_data_dir # override polyglot path import polyglot +from appdirs import user_data_dir polyglot.polyglot_path = os.path.join( user_data_dir(appname="LibreTranslate", appauthor="uav4geo"), "polyglot_data" diff --git a/app/api_keys.py b/app/api_keys.py index 9546c85..905047b 100644 --- a/app/api_keys.py +++ b/app/api_keys.py @@ -1,5 +1,6 @@ import sqlite3 import uuid + from expiringdict import ExpiringDict DEFAULT_DB_PATH = "api_keys.db" diff --git a/app/app.py b/app/app.py index 23a09f3..36daece 100644 --- a/app/app.py +++ b/app/app.py @@ -1,12 +1,14 @@ import os -from flask import Flask, render_template, jsonify, request, abort, send_from_directory +from functools import wraps + +from flask import Flask, abort, jsonify, render_template, request from flask_swagger import swagger from flask_swagger_ui import get_swaggerui_blueprint -from pkg_resources import resource_filename -from .api_keys import Database -from app.language import detect_languages, transliterate + from app import flood -from functools import wraps +from app.language import detect_languages, transliterate + +from .api_keys import Database def get_json_dict(request): @@ -128,8 +130,7 @@ def create_app(args): ak = request.values.get("api_key") if ( - api_keys_db.lookup(ak) is None - and request.headers.get("Origin") != args.require_api_key_origin + api_keys_db.lookup(ak) is None and request.headers.get("Origin") != args.require_api_key_origin ): abort( 403, diff --git a/app/flood.py b/app/flood.py index 62ff317..ef0ed6b 100644 --- a/app/flood.py +++ b/app/flood.py @@ -1,4 +1,3 @@ -import time import atexit from apscheduler.schedulers.background import BackgroundScheduler diff --git a/app/init.py b/app/init.py index 873f502..b1c6997 100644 --- a/app/init.py +++ b/app/init.py @@ -1,9 +1,9 @@ -import os from pathlib import Path -from argostranslate import settings, package, translate -import os, glob, shutil, zipfile -import app.language + import polyglot +from argostranslate import package, translate + +import app.language def boot(load_only=None): @@ -39,8 +39,7 @@ def check_and_install_models(force=False, load_only_lang_codes=None): available_packages = [ pack for pack in available_packages - if pack.from_code in load_only_lang_codes - and pack.to_code in load_only_lang_codes + if pack.from_code in load_only_lang_codes and pack.to_code in load_only_lang_codes ] if not available_packages: raise ValueError("no available package") diff --git a/app/language.py b/app/language.py index a547d99..1b35812 100644 --- a/app/language.py +++ b/app/language.py @@ -4,7 +4,6 @@ from argostranslate import translate from polyglot.detect.base import Detector, UnknownLanguage from polyglot.transliteration.base import Transliterator - languages = translate.load_installed_languages() @@ -24,7 +23,7 @@ def detect_languages(text): for t in text: try: candidates.extend(Detector(t).languages) - except UnknownLanguage as e: + except UnknownLanguage: pass # total read bytes of the provided text diff --git a/app/main.py b/app/main.py index e22dcb7..a4ac6f9 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,6 @@ import argparse import operator + from app.app import create_app diff --git a/app/manage.py b/app/manage.py index 933622f..be548f7 100644 --- a/app/manage.py +++ b/app/manage.py @@ -1,4 +1,5 @@ import argparse + from app.api_keys import Database diff --git a/install_models.py b/install_models.py index 4768c3c..23631f4 100755 --- a/install_models.py +++ b/install_models.py @@ -3,5 +3,5 @@ from app.init import check_and_install_models, check_and_install_transliteration if __name__ == "__main__": - check_and_install_models(force=True) - check_and_install_transliteration(force=True) + check_and_install_models(force=True) + check_and_install_transliteration(force=True) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..6d52ae7 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,12 @@ +[flake8] +exclude = .git, + .vscode, + .gitignore, + README.md, + venv, + test, + setup.py, + app/__init__.py + +max-line-length = 136 +ignore = E741 \ No newline at end of file diff --git a/tests/test_init.py b/tests/test_init.py index 3d7008b..c1dbfe1 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -1,4 +1,3 @@ -import pytest from app.init import boot from argostranslate import package