mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 14:19:59 +00:00
Apply isort & flake8 (#312)
* Update isort settings * Apply import sorting (isort) on all files in nyaa/ * Fixed Flake8 errors in nyaa/ (see PR for list) * Add isort to lint.sh and requirements.txt
This commit is contained in:
parent
99c052c85f
commit
b992467dad
12
lint.sh
12
lint.sh
|
@ -1,6 +1,7 @@
|
||||||
# Lint checker/fixer
|
# Lint checker/fixer
|
||||||
|
|
||||||
check_paths="nyaa/ utils/"
|
check_paths="nyaa/ utils/"
|
||||||
|
isort_paths="nyaa/" # just nyaa/ for now
|
||||||
max_line_length=100
|
max_line_length=100
|
||||||
|
|
||||||
function auto_pep8() {
|
function auto_pep8() {
|
||||||
|
@ -9,14 +10,21 @@ function auto_pep8() {
|
||||||
--in-place \
|
--in-place \
|
||||||
--pep8-passes 2000 \
|
--pep8-passes 2000 \
|
||||||
--max-line-length ${max_line_length} \
|
--max-line-length ${max_line_length} \
|
||||||
--verbose
|
--verbose \
|
||||||
|
&& \
|
||||||
|
isort ${isort_paths}
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_lint() {
|
function check_lint() {
|
||||||
pycodestyle ${check_paths} \
|
pycodestyle ${check_paths} \
|
||||||
--show-source \
|
--show-source \
|
||||||
--max-line-length=${max_line_length} \
|
--max-line-length=${max_line_length} \
|
||||||
--format '%(path)s [%(row)s:%(col)s] %(code)s: %(text)s'
|
--format '%(path)s [%(row)s:%(col)s] %(code)s: %(text)s' \
|
||||||
|
&& \
|
||||||
|
isort ${isort_paths} \
|
||||||
|
--recursive \
|
||||||
|
--diff \
|
||||||
|
--check-only
|
||||||
}
|
}
|
||||||
|
|
||||||
# MAIN
|
# MAIN
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
import flask
|
import os
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
|
||||||
from flask_assets import Environment, Bundle
|
|
||||||
from flask_debugtoolbar import DebugToolbarExtension
|
|
||||||
from nyaa import fix_paginate
|
|
||||||
|
|
||||||
|
import flask
|
||||||
|
from flask_assets import Bundle, Environment # noqa F401
|
||||||
|
from flask_debugtoolbar import DebugToolbarExtension
|
||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
|
from nyaa import fix_paginate # noqa F401
|
||||||
|
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
app.config.from_object('config')
|
app.config.from_object('config')
|
||||||
|
@ -70,4 +71,4 @@ assets = Environment(app)
|
||||||
# output='style.css', depends='**/*.scss')
|
# output='style.css', depends='**/*.scss')
|
||||||
# assets.register('style_all', css)
|
# assets.register('style_all', css)
|
||||||
|
|
||||||
from nyaa import routes # noqa E402
|
from nyaa import routes # noqa E402 isort:skip
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
import flask
|
import binascii
|
||||||
from werkzeug.datastructures import ImmutableMultiDict, CombinedMultiDict
|
|
||||||
|
|
||||||
from nyaa import app, db
|
|
||||||
from nyaa import models, forms
|
|
||||||
from nyaa import bencode, backend, utils
|
|
||||||
from nyaa import torrents
|
|
||||||
|
|
||||||
from nyaa.views.torrents import _create_upload_category_choices
|
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
import json
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import binascii
|
import flask
|
||||||
|
|
||||||
|
from nyaa import backend, bencode, db, forms, models, utils
|
||||||
|
from nyaa.views.torrents import _create_upload_category_choices
|
||||||
|
|
||||||
api_blueprint = flask.Blueprint('api', __name__)
|
api_blueprint = flask.Blueprint('api', __name__)
|
||||||
|
|
||||||
|
@ -124,7 +118,7 @@ def v2_api_upload():
|
||||||
|
|
||||||
# #################################### TEMPORARY ####################################
|
# #################################### TEMPORARY ####################################
|
||||||
|
|
||||||
from orderedset import OrderedSet # noqa: E402
|
from orderedset import OrderedSet # noqa: E402 isort:skip
|
||||||
|
|
||||||
|
|
||||||
@api_blueprint.route('/ghetto_import', methods=['POST'])
|
@api_blueprint.route('/ghetto_import', methods=['POST'])
|
||||||
|
@ -146,7 +140,7 @@ def ghetto_import():
|
||||||
return 'Malformed torrent metadata ({})'.format(e.args[0]), 500
|
return 'Malformed torrent metadata ({})'.format(e.args[0]), 500
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tracker_found = forms._validate_trackers(torrent_dict)
|
tracker_found = forms._validate_trackers(torrent_dict) # noqa F841
|
||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
return 'Malformed torrent trackers ({})'.format(e.args[0]), 500
|
return 'Malformed torrent trackers ({})'.format(e.args[0]), 500
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
import flask
|
|
||||||
from nyaa import app, db
|
|
||||||
from nyaa import models, forms
|
|
||||||
from nyaa import bencode, utils
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from werkzeug import secure_filename
|
import os
|
||||||
from collections import OrderedDict
|
|
||||||
from orderedset import OrderedSet
|
|
||||||
from ipaddress import ip_address
|
from ipaddress import ip_address
|
||||||
|
|
||||||
|
import flask
|
||||||
|
from werkzeug import secure_filename
|
||||||
|
|
||||||
|
from orderedset import OrderedSet
|
||||||
|
|
||||||
|
from nyaa import app, db, models, utils
|
||||||
|
|
||||||
|
|
||||||
@utils.cached_function
|
@utils.cached_function
|
||||||
def get_category_id_map():
|
def get_category_id_map():
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import sqlalchemy
|
|
||||||
from flask_sqlalchemy import Pagination, BaseQuery
|
|
||||||
from flask import abort
|
from flask import abort
|
||||||
|
from flask_sqlalchemy import BaseQuery, Pagination
|
||||||
|
|
||||||
|
|
||||||
def paginate_faste(self, page=1, per_page=50, max_page=None, step=5, count_query=None):
|
def paginate_faste(self, page=1, per_page=50, max_page=None, step=5, count_query=None):
|
||||||
|
|
|
@ -1,25 +1,21 @@
|
||||||
import flask
|
import functools
|
||||||
from nyaa import db, app
|
|
||||||
from nyaa.models import User
|
|
||||||
from nyaa import bencode, utils, models
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import functools
|
|
||||||
|
import flask
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from flask_wtf.file import FileField, FileRequired
|
from flask_wtf.file import FileField, FileRequired
|
||||||
from wtforms import StringField, PasswordField, BooleanField, TextAreaField, SelectField,\
|
|
||||||
HiddenField
|
|
||||||
from wtforms.validators import DataRequired, Optional, Email, Length, EqualTo, ValidationError,\
|
|
||||||
StopValidation
|
|
||||||
from wtforms.validators import Regexp
|
|
||||||
|
|
||||||
# For DisabledSelectField
|
|
||||||
from wtforms.widgets import Select as SelectWidget
|
|
||||||
from wtforms.widgets import html_params, HTMLString
|
|
||||||
|
|
||||||
from flask_wtf.recaptcha import RecaptchaField
|
from flask_wtf.recaptcha import RecaptchaField
|
||||||
from flask_wtf.recaptcha.validators import Recaptcha as RecaptchaValidator
|
from flask_wtf.recaptcha.validators import Recaptcha as RecaptchaValidator
|
||||||
|
from wtforms import (BooleanField, HiddenField, PasswordField, SelectField, StringField,
|
||||||
|
TextAreaField)
|
||||||
|
from wtforms.validators import (DataRequired, Email, EqualTo, Length, Optional, Regexp,
|
||||||
|
StopValidation, ValidationError)
|
||||||
|
from wtforms.widgets import Select as SelectWidget # For DisabledSelectField
|
||||||
|
from wtforms.widgets import HTMLString, html_params # For DisabledSelectField
|
||||||
|
|
||||||
|
from nyaa import app, bencode, models, utils
|
||||||
|
from nyaa.models import User
|
||||||
|
|
||||||
|
|
||||||
class Unique(object):
|
class Unique(object):
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
import flask
|
import base64
|
||||||
|
import re
|
||||||
|
from datetime import datetime
|
||||||
from enum import Enum, IntEnum
|
from enum import Enum, IntEnum
|
||||||
from datetime import datetime, timezone
|
from hashlib import md5
|
||||||
|
from ipaddress import ip_address
|
||||||
|
from urllib.parse import unquote as unquote_url
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
|
import flask
|
||||||
|
from markupsafe import escape as escape_markup
|
||||||
|
|
||||||
|
from sqlalchemy import ForeignKeyConstraint, Index
|
||||||
|
from sqlalchemy.ext import declarative
|
||||||
|
from sqlalchemy_fulltext import FullText
|
||||||
|
from sqlalchemy_utils import ChoiceType, EmailType, PasswordType
|
||||||
|
|
||||||
from nyaa import app, db
|
from nyaa import app, db
|
||||||
from nyaa.torrents import create_magnet
|
from nyaa.torrents import create_magnet
|
||||||
|
|
||||||
from sqlalchemy import func, ForeignKeyConstraint, Index
|
|
||||||
from sqlalchemy.ext import declarative
|
|
||||||
from sqlalchemy_utils import ChoiceType, EmailType, PasswordType
|
|
||||||
from sqlalchemy_fulltext import FullText
|
|
||||||
|
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
|
||||||
from ipaddress import ip_address
|
|
||||||
|
|
||||||
import re
|
|
||||||
import base64
|
|
||||||
from markupsafe import escape as escape_markup
|
|
||||||
from urllib.parse import urlencode, unquote as unquote_url
|
|
||||||
from hashlib import md5
|
|
||||||
|
|
||||||
if app.config['USE_MYSQL']:
|
if app.config['USE_MYSQL']:
|
||||||
from sqlalchemy.dialects import mysql
|
from sqlalchemy.dialects import mysql
|
||||||
BinaryType = mysql.BINARY
|
BinaryType = mysql.BINARY
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
import flask
|
|
||||||
import re
|
|
||||||
import math
|
import math
|
||||||
import json
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from nyaa import app, db
|
import flask
|
||||||
from nyaa import models
|
|
||||||
|
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
import sqlalchemy_fulltext.modes as FullTextMode
|
import sqlalchemy_fulltext.modes as FullTextMode
|
||||||
from sqlalchemy_fulltext import FullTextSearch
|
|
||||||
from elasticsearch import Elasticsearch
|
from elasticsearch import Elasticsearch
|
||||||
from elasticsearch_dsl import Search, Q
|
from elasticsearch_dsl import Q, Search
|
||||||
|
from sqlalchemy_fulltext import FullTextSearch
|
||||||
|
|
||||||
|
from nyaa import app, db, models
|
||||||
|
|
||||||
DEFAULT_MAX_SEARCH_RESULT = 1000
|
DEFAULT_MAX_SEARCH_RESULT = 1000
|
||||||
DEFAULT_PER_PAGE = 75
|
DEFAULT_PER_PAGE = 75
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import os
|
|
||||||
import base64
|
import base64
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from orderedset import OrderedSet
|
|
||||||
from nyaa import app
|
|
||||||
|
|
||||||
from nyaa import bencode
|
from orderedset import OrderedSet
|
||||||
from nyaa import app
|
|
||||||
from nyaa import models
|
from nyaa import app, bencode
|
||||||
|
|
||||||
USED_TRACKERS = OrderedSet()
|
USED_TRACKERS = OrderedSet()
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import hashlib
|
|
||||||
import functools
|
import functools
|
||||||
|
import hashlib
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from nyaa.views import (
|
from nyaa.views import ( # isort:skip
|
||||||
account,
|
account,
|
||||||
admin,
|
admin,
|
||||||
main,
|
main,
|
||||||
|
|
|
@ -19,6 +19,7 @@ Flask-WTF==0.14.2
|
||||||
gevent==1.2.1
|
gevent==1.2.1
|
||||||
greenlet==0.4.12
|
greenlet==0.4.12
|
||||||
itsdangerous==0.24
|
itsdangerous==0.24
|
||||||
|
isort==4.2.15
|
||||||
Jinja2==2.9.6
|
Jinja2==2.9.6
|
||||||
libsass==0.12.3
|
libsass==0.12.3
|
||||||
Mako==1.0.6
|
Mako==1.0.6
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
[isort]
|
[isort]
|
||||||
line_length = 100
|
line_length = 100
|
||||||
|
not_skip = __init__.py
|
||||||
default_section = THIRDPARTY
|
default_section = THIRDPARTY
|
||||||
known_first_party = nyaa
|
known_first_party = nyaa
|
||||||
known_flask = flask, flask_wtf, flask_paginate, jinja2, werkzeug
|
known_flask =
|
||||||
|
flask*,
|
||||||
|
jinja2,
|
||||||
|
markupsafe,
|
||||||
|
werkzeug,
|
||||||
|
wtforms
|
||||||
sections = STDLIB,FLASK,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
|
sections = STDLIB,FLASK,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
|
||||||
|
|
Loading…
Reference in a new issue