aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShyam Sunder2020-06-05 10:02:18 -0400
committerShyam Sunder2020-06-05 10:02:18 -0400
commitea623449e7c29801ab0a0ade043308937cca7506 (patch)
tree889147f8bec12ef170bd31fb9a61403e66d542f8
parentc5358f7f83ef49f51d5ba557dde1b16ce2c83d1d (diff)
server: format code to flake8
-rw-r--r--server/.dockerignore3
-rw-r--r--server/.pylintrc37
-rw-r--r--server/setup.cfg (renamed from server/mypy.ini)6
-rw-r--r--server/szurubooru/api/info_api.py2
-rw-r--r--server/szurubooru/config.py2
-rw-r--r--server/szurubooru/db.py2
-rw-r--r--server/szurubooru/facade.py3
-rw-r--r--server/szurubooru/func/auth.py2
-rw-r--r--server/szurubooru/func/image_hash.py4
-rw-r--r--server/szurubooru/func/mime.py3
-rw-r--r--server/szurubooru/func/net.py2
-rw-r--r--server/szurubooru/func/posts.py2
-rw-r--r--server/szurubooru/func/snapshots.py2
-rw-r--r--server/szurubooru/func/util.py2
-rw-r--r--server/szurubooru/migrations/env.py4
-rw-r--r--server/szurubooru/migrations/versions/02ef5f73f4ab_add_hashes_to_post_file_names.py2
-rw-r--r--server/szurubooru/migrations/versions/1cd4c7b22846_change_flags_column_to_string.py2
-rw-r--r--server/szurubooru/model/base.py2
-rw-r--r--server/szurubooru/rest/errors.py2
-rw-r--r--server/szurubooru/rest/middleware.py1
-rw-r--r--server/szurubooru/rest/routes.py1
-rw-r--r--server/szurubooru/search/configs/post_search_config.py3
-rw-r--r--server/szurubooru/search/configs/util.py2
-rw-r--r--server/szurubooru/tests/conftest.py4
-rw-r--r--server/szurubooru/tests/func/test_util.py2
-rw-r--r--server/szurubooru/tests/model/test_post.py1
-rw-r--r--server/szurubooru/tests/model/test_user.py1
-rw-r--r--server/szurubooru/tests/rest/test_context.py1
-rw-r--r--server/szurubooru/tests/search/configs/test_comment_search_config.py1
-rw-r--r--server/szurubooru/tests/search/configs/test_pool_search_config.py1
-rw-r--r--server/szurubooru/tests/search/configs/test_post_search_config.py1
-rw-r--r--server/szurubooru/tests/search/configs/test_tag_search_config.py1
-rw-r--r--server/szurubooru/tests/search/configs/test_user_search_config.py1
33 files changed, 27 insertions, 78 deletions
diff --git a/server/.dockerignore b/server/.dockerignore
index 725fbe6..8c1667b 100644
--- a/server/.dockerignore
+++ b/server/.dockerignore
@@ -1,6 +1,5 @@
# Linter configs
-.pylintrc
-mypy.ini
+setup.cfg
# Python requirements files
requirements.txt
diff --git a/server/.pylintrc b/server/.pylintrc
deleted file mode 100644
index 846bac6..0000000
--- a/server/.pylintrc
+++ /dev/null
@@ -1,37 +0,0 @@
-[basic]
-function-rgx=^_?[a-z_][a-z0-9_]{2,}$|^test_
-method-rgx=^[a-z_][a-z0-9_]{2,}$|^test_
-const-rgx=^[A-Z_]+$|^_[a-zA-Z_]*$
-good-names=ex,_,logger,i
-
-[variables]
-dummy-variables-rgx=_|dummy
-
-[format]
-max-line-length=79
-
-[messages control]
-reports=no
-disable=
- # we're not java
- missing-docstring,
- broad-except,
-
- # covered better by pycodestyle
- bad-continuation,
-
- # we're adults
- redefined-builtin,
- duplicate-code,
- too-many-return-statements,
- too-many-arguments,
-
- # plain stupid
- no-self-use,
- too-few-public-methods
-
-[typecheck]
-generated-members=add|add_all
-
-[similarities]
-min-similarity-lines=5
diff --git a/server/mypy.ini b/server/setup.cfg
index a0300b7..2179081 100644
--- a/server/mypy.ini
+++ b/server/setup.cfg
@@ -1,3 +1,9 @@
+[flake8]
+filename = szurubooru/
+exclude = __pycache__
+ignore = F401, W503, W504
+max-line-length = 79
+
[mypy]
ignore_missing_imports = True
follow_imports = skip
diff --git a/server/szurubooru/api/info_api.py b/server/szurubooru/api/info_api.py
index b072147..1e2fd1d 100644
--- a/server/szurubooru/api/info_api.py
+++ b/server/szurubooru/api/info_api.py
@@ -10,7 +10,7 @@ _cache_result = None # type: Optional[int]
def _get_disk_usage() -> int:
- global _cache_time, _cache_result # pylint: disable=global-statement
+ global _cache_time, _cache_result
threshold = timedelta(hours=48)
now = datetime.utcnow()
if _cache_time and _cache_time > now - threshold:
diff --git a/server/szurubooru/config.py b/server/szurubooru/config.py
index e9962a7..72a24b6 100644
--- a/server/szurubooru/config.py
+++ b/server/szurubooru/config.py
@@ -56,4 +56,4 @@ def _read_config() -> Dict:
return ret
-config = _read_config() # pylint: disable=invalid-name
+config = _read_config()
diff --git a/server/szurubooru/db.py b/server/szurubooru/db.py
index 561b748..03bfaff 100644
--- a/server/szurubooru/db.py
+++ b/server/szurubooru/db.py
@@ -4,7 +4,7 @@ import sqlalchemy as sa
import sqlalchemy.orm
from szurubooru import config
-# pylint: disable=invalid-name
+
_data = threading.local()
_engine = sa.create_engine(config.config['database']) # type: Any
_sessionmaker = sa.orm.sessionmaker(bind=_engine, autoflush=False) # type: Any
diff --git a/server/szurubooru/facade.py b/server/szurubooru/facade.py
index 7cac63c..d8d0b63 100644
--- a/server/szurubooru/facade.py
+++ b/server/szurubooru/facade.py
@@ -10,7 +10,6 @@ import sqlalchemy.orm.exc
from szurubooru import config, db, errors, rest
from szurubooru.func.posts import update_all_post_signatures
from szurubooru.func.file_uploads import purge_old_uploads
-# pylint: disable=unused-import
from szurubooru import api, middleware
@@ -147,4 +146,4 @@ def create_app() -> Callable[[Any, Any], Any]:
return rest.application
-app = create_app() # pylint: disable=invalid-name
+app = create_app()
diff --git a/server/szurubooru/func/auth.py b/server/szurubooru/func/auth.py
index 65be79a..504fe61 100644
--- a/server/szurubooru/func/auth.py
+++ b/server/szurubooru/func/auth.py
@@ -54,7 +54,7 @@ def create_password() -> str:
'n': list('0123456789'),
}
pattern = 'cvcvnncvcv'
- return ''.join(random.choice(alphabet[l]) for l in list(pattern))
+ return ''.join(random.choice(alphabet[type]) for type in list(pattern))
def is_valid_password(user: model.User, password: str) -> bool:
diff --git a/server/szurubooru/func/image_hash.py b/server/szurubooru/func/image_hash.py
index da2cd75..771302d 100644
--- a/server/szurubooru/func/image_hash.py
+++ b/server/szurubooru/func/image_hash.py
@@ -7,7 +7,7 @@ import numpy as np
from PIL import Image
from szurubooru import config, errors
-# pylint: disable=invalid-name
+
logger = logging.getLogger(__name__)
# Math based on paper from H. Chi Wong, Marshall Bern and David Goldberg
@@ -242,7 +242,6 @@ def pack_signature(signature: NpMatrix) -> bytes:
This is then converted into a more packed array consisting of
uint32 elements (for SIG_CHUNK_BITS = 32).
'''
- base = 2 * N_LEVELS + 1
coding_vector = np.flipud(SIG_BASE**np.arange(SIG_CHUNK_WIDTH))
return np.array([
np.dot(x, coding_vector) for x in
@@ -256,7 +255,6 @@ def unpack_signature(packed: bytes) -> NpMatrix:
Functions as an inverse transformation of pack_signature()
'''
- base = 2 * N_LEVELS + 1
return np.ravel(np.array([
[
int(digit) - N_LEVELS for digit in
diff --git a/server/szurubooru/func/mime.py b/server/szurubooru/func/mime.py
index 871a0a4..afab817 100644
--- a/server/szurubooru/func/mime.py
+++ b/server/szurubooru/func/mime.py
@@ -53,7 +53,8 @@ def is_video(mime_type: str) -> bool:
def is_image(mime_type: str) -> bool:
- return mime_type.lower() in ('image/jpeg', 'image/png', 'image/gif', 'image/webp')
+ return mime_type.lower() in (
+ 'image/jpeg', 'image/png', 'image/gif', 'image/webp')
def is_animated_gif(content: bytes) -> bool:
diff --git a/server/szurubooru/func/net.py b/server/szurubooru/func/net.py
index 17f4654..8110340 100644
--- a/server/szurubooru/func/net.py
+++ b/server/szurubooru/func/net.py
@@ -49,6 +49,6 @@ def _youtube_dl_wrapper(url: str) -> bytes:
except YoutubeDLError as ex:
raise errors.ThirdPartyError(
'Error downloading video %s (%s)' % (url, ex))
- except FileNotFoundError as ex:
+ except FileNotFoundError:
raise errors.ThirdPartyError(
'Error downloading video %s (file could not be saved)' % (url))
diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py
index d8e984b..e18656a 100644
--- a/server/szurubooru/func/posts.py
+++ b/server/szurubooru/func/posts.py
@@ -529,7 +529,7 @@ def update_all_post_signatures() -> None:
.filter(
(model.Post.type == model.Post.TYPE_IMAGE) |
(model.Post.type == model.Post.TYPE_ANIMATION))
- .filter(model.Post.signature == None)
+ .filter(model.Post.signature == None) # noqa: E711
.order_by(model.Post.post_id.asc())
.all())
for post in posts_to_hash:
diff --git a/server/szurubooru/func/snapshots.py b/server/szurubooru/func/snapshots.py
index 6646467..38d42a9 100644
--- a/server/szurubooru/func/snapshots.py
+++ b/server/szurubooru/func/snapshots.py
@@ -61,7 +61,6 @@ def get_post_snapshot(post: model.Post) -> Dict[str, Any]:
_snapshot_factories = {
# lambdas allow mocking target functions in the tests
- # pylint: disable=unnecessary-lambda
'tag_category': lambda entity: get_tag_category_snapshot(entity),
'tag': lambda entity: get_tag_snapshot(entity),
'post': lambda entity: get_post_snapshot(entity),
@@ -108,7 +107,6 @@ def create(entity: model.Base, auth_user: Optional[model.User]) -> None:
db.session.add(snapshot)
-# pylint: disable=protected-access
def modify(entity: model.Base, auth_user: Optional[model.User]) -> None:
assert entity
diff --git a/server/szurubooru/func/util.py b/server/szurubooru/func/util.py
index 5e82286..1bf34fa 100644
--- a/server/szurubooru/func/util.py
+++ b/server/szurubooru/func/util.py
@@ -84,7 +84,7 @@ def is_valid_email(email: Optional[str]) -> bool:
return not email or re.match(r'^[^@]*@[^@]*\.[^@]*$', email) is not None
-class dotdict(dict): # pylint: disable=invalid-name
+class dotdict(dict):
''' dot.notation access to dictionary attributes. '''
def __getattr__(self, attr: str) -> Any:
return self.get(attr)
diff --git a/server/szurubooru/migrations/env.py b/server/szurubooru/migrations/env.py
index e7d512e..f0a06dd 100644
--- a/server/szurubooru/migrations/env.py
+++ b/server/szurubooru/migrations/env.py
@@ -10,8 +10,8 @@ from time import sleep
dir_to_self = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(dir_to_self, *[os.pardir] * 2))
-import szurubooru.model.base
-import szurubooru.config
+import szurubooru.model.base # noqa: E402
+import szurubooru.config # noqa: E402
alembic_config = alembic.context.config
logging.config.fileConfig(alembic_config.config_file_name)
diff --git a/server/szurubooru/migrations/versions/02ef5f73f4ab_add_hashes_to_post_file_names.py b/server/szurubooru/migrations/versions/02ef5f73f4ab_add_hashes_to_post_file_names.py
index c7e5d01..1e09e34 100644
--- a/server/szurubooru/migrations/versions/02ef5f73f4ab_add_hashes_to_post_file_names.py
+++ b/server/szurubooru/migrations/versions/02ef5f73f4ab_add_hashes_to_post_file_names.py
@@ -36,7 +36,7 @@ def downgrade():
entry.name)
if match:
post_id = int(match.group('name'))
- security_hash = match.group('hash')
+ security_hash = match.group('hash') # noqa: F841
ext = match.group('ext')
new_name = '%s.%s' % (post_id, ext)
new_path = os.path.join(os.path.dirname(entry.path), new_name)
diff --git a/server/szurubooru/migrations/versions/1cd4c7b22846_change_flags_column_to_string.py b/server/szurubooru/migrations/versions/1cd4c7b22846_change_flags_column_to_string.py
index b450b1d..ce01751 100644
--- a/server/szurubooru/migrations/versions/1cd4c7b22846_change_flags_column_to_string.py
+++ b/server/szurubooru/migrations/versions/1cd4c7b22846_change_flags_column_to_string.py
@@ -29,7 +29,6 @@ def upgrade():
for row in conn.execute(posts.select()):
newflag = ','.join(row.oldflags) if row.oldflags else ''
conn.execute(
- # pylint: disable=no-value-for-parameter
posts.update().where(
posts.c.id == row.id
).values(
@@ -53,7 +52,6 @@ def downgrade():
for row in conn.execute(posts.select()):
newflag = [x for x in row.oldflags.split(',') if x]
conn.execute(
- # pylint: disable=no-value-for-parameter
posts.update().where(
posts.c.id == row.id
).values(
diff --git a/server/szurubooru/model/base.py b/server/szurubooru/model/base.py
index e61d35a..00ea8e1 100644
--- a/server/szurubooru/model/base.py
+++ b/server/szurubooru/model/base.py
@@ -1,4 +1,4 @@
from sqlalchemy.ext.declarative import declarative_base
-Base = declarative_base() # pylint: disable=invalid-name
+Base = declarative_base()
diff --git a/server/szurubooru/rest/errors.py b/server/szurubooru/rest/errors.py
index f90ac25..45dc615 100644
--- a/server/szurubooru/rest/errors.py
+++ b/server/szurubooru/rest/errors.py
@@ -1,7 +1,7 @@
from typing import Optional, Callable, Type, Dict
-error_handlers = {} # pylint: disable=invalid-name
+error_handlers = {}
class BaseHttpError(RuntimeError):
diff --git a/server/szurubooru/rest/middleware.py b/server/szurubooru/rest/middleware.py
index ce457e0..18b6b46 100644
--- a/server/szurubooru/rest/middleware.py
+++ b/server/szurubooru/rest/middleware.py
@@ -2,7 +2,6 @@ from typing import List, Callable
from szurubooru.rest.context import Context
-# pylint: disable=invalid-name
pre_hooks = [] # type: List[Callable[[Context], None]]
post_hooks = [] # type: List[Callable[[Context], None]]
diff --git a/server/szurubooru/rest/routes.py b/server/szurubooru/rest/routes.py
index 569cbe1..93e124e 100644
--- a/server/szurubooru/rest/routes.py
+++ b/server/szurubooru/rest/routes.py
@@ -3,7 +3,6 @@ from collections import defaultdict
from szurubooru.rest.context import Context, Response
-# pylint: disable=invalid-name
RouteHandler = Callable[[Context, Dict[str, str]], Response]
routes = defaultdict(dict) # type: Dict[str, Dict[str, RouteHandler]]
diff --git a/server/szurubooru/search/configs/post_search_config.py b/server/szurubooru/search/configs/post_search_config.py
index 281826f..dcf0255 100644
--- a/server/szurubooru/search/configs/post_search_config.py
+++ b/server/szurubooru/search/configs/post_search_config.py
@@ -80,8 +80,7 @@ def _user_filter(
assert criterion
if isinstance(criterion, criteria.PlainCriterion) \
and not criterion.value:
- # pylint: disable=singleton-comparison
- expr = model.Post.user_id == None
+ expr = model.Post.user_id == None # noqa: E711
if negated:
expr = ~expr
return query.filter(expr)
diff --git a/server/szurubooru/search/configs/util.py b/server/szurubooru/search/configs/util.py
index 9c4d3ae..ee201a2 100644
--- a/server/szurubooru/search/configs/util.py
+++ b/server/szurubooru/search/configs/util.py
@@ -17,7 +17,7 @@ def unescape(text: str, make_wildcards_special: bool = False) -> str:
while i < len(text):
if text[i] == '\\':
try:
- char = text[i+1]
+ char = text[i + 1]
i += 1
except IndexError:
raise errors.SearchError(
diff --git a/server/szurubooru/tests/conftest.py b/server/szurubooru/tests/conftest.py
index 13b1c00..c776601 100644
--- a/server/szurubooru/tests/conftest.py
+++ b/server/szurubooru/tests/conftest.py
@@ -1,4 +1,3 @@
-# pylint: disable=redefined-outer-name
import contextlib
import os
import random
@@ -39,7 +38,7 @@ def query_logger(pytestconfig):
@pytest.yield_fixture(scope='function', autouse=True)
-def session(query_logger, postgresql_db): # pylint: disable=unused-argument
+def session(query_logger, postgresql_db):
db.session = postgresql_db.session
postgresql_db.create_table(*model.Base.metadata.sorted_tables)
try:
@@ -141,7 +140,6 @@ def tag_factory():
@pytest.fixture
def post_factory():
- # pylint: disable=invalid-name
def factory(
id=None,
safety=model.Post.SAFETY_SAFE,
diff --git a/server/szurubooru/tests/func/test_util.py b/server/szurubooru/tests/func/test_util.py
index 24fe4e4..1307ab9 100644
--- a/server/szurubooru/tests/func/test_util.py
+++ b/server/szurubooru/tests/func/test_util.py
@@ -4,7 +4,7 @@ from szurubooru import errors
from szurubooru.func import util
-dt = datetime # pylint: disable=invalid-name
+dt = datetime
def test_parsing_empty_date_time():
diff --git a/server/szurubooru/tests/model/test_post.py b/server/szurubooru/tests/model/test_post.py
index 75bcbae..47c088d 100644
--- a/server/szurubooru/tests/model/test_post.py
+++ b/server/szurubooru/tests/model/test_post.py
@@ -50,7 +50,6 @@ def test_saving_post(post_factory, user_factory, tag_factory):
assert len(related_post2.relations) == 0
-# pylint: disable=too-many-statements
def test_cascade_deletions(
post_factory, user_factory, tag_factory, comment_factory):
user = user_factory()
diff --git a/server/szurubooru/tests/model/test_user.py b/server/szurubooru/tests/model/test_user.py
index 08875fa..ced3a5e 100644
--- a/server/szurubooru/tests/model/test_user.py
+++ b/server/szurubooru/tests/model/test_user.py
@@ -111,7 +111,6 @@ def test_disliked_post_count(user_factory, post_factory):
assert user1.disliked_post_count == 1
-# pylint: disable=too-many-statements
def test_cascade_deletions(post_factory, user_factory, comment_factory):
user = user_factory()
diff --git a/server/szurubooru/tests/rest/test_context.py b/server/szurubooru/tests/rest/test_context.py
index 34cf7ac..0de1e32 100644
--- a/server/szurubooru/tests/rest/test_context.py
+++ b/server/szurubooru/tests/rest/test_context.py
@@ -1,4 +1,3 @@
-# pylint: disable=unexpected-keyword-arg
import unittest.mock
import pytest
from szurubooru import rest, errors
diff --git a/server/szurubooru/tests/search/configs/test_comment_search_config.py b/server/szurubooru/tests/search/configs/test_comment_search_config.py
index 109629b..7279c1b 100644
--- a/server/szurubooru/tests/search/configs/test_comment_search_config.py
+++ b/server/szurubooru/tests/search/configs/test_comment_search_config.py
@@ -1,4 +1,3 @@
-# pylint: disable=redefined-outer-name
from datetime import datetime
import pytest
from szurubooru import db, search
diff --git a/server/szurubooru/tests/search/configs/test_pool_search_config.py b/server/szurubooru/tests/search/configs/test_pool_search_config.py
index 730511a..731a676 100644
--- a/server/szurubooru/tests/search/configs/test_pool_search_config.py
+++ b/server/szurubooru/tests/search/configs/test_pool_search_config.py
@@ -1,4 +1,3 @@
-# pylint: disable=redefined-outer-name
from datetime import datetime
import pytest
from szurubooru import db, errors, search
diff --git a/server/szurubooru/tests/search/configs/test_post_search_config.py b/server/szurubooru/tests/search/configs/test_post_search_config.py
index 4d541d1..462594c 100644
--- a/server/szurubooru/tests/search/configs/test_post_search_config.py
+++ b/server/szurubooru/tests/search/configs/test_post_search_config.py
@@ -1,4 +1,3 @@
-# pylint: disable=redefined-outer-name
from datetime import datetime
import pytest
from szurubooru import db, model, errors, search
diff --git a/server/szurubooru/tests/search/configs/test_tag_search_config.py b/server/szurubooru/tests/search/configs/test_tag_search_config.py
index d3d2de3..09a4c40 100644
--- a/server/szurubooru/tests/search/configs/test_tag_search_config.py
+++ b/server/szurubooru/tests/search/configs/test_tag_search_config.py
@@ -1,4 +1,3 @@
-# pylint: disable=redefined-outer-name
from datetime import datetime
import pytest
from szurubooru import db, errors, search
diff --git a/server/szurubooru/tests/search/configs/test_user_search_config.py b/server/szurubooru/tests/search/configs/test_user_search_config.py
index c4d9402..e9cea5a 100644
--- a/server/szurubooru/tests/search/configs/test_user_search_config.py
+++ b/server/szurubooru/tests/search/configs/test_user_search_config.py
@@ -1,4 +1,3 @@
-# pylint: disable=redefined-outer-name
from datetime import datetime
import pytest
from szurubooru import db, errors, search

© 2015 - 2026 Jakob L. Kreuze