Commit 31ab15fe authored by Deimos's avatar Deimos

Apply isort to make import styles consistent

This adds settings into pyproject.toml for the isort tool to match up
with the styles I've generally been using, and then applies it to the
whole project (by running "isort -rc").

Most of these changes are very minor, but it's good to fix the few
inconsistencies that were around.
parent 24517473
......@@ -7,10 +7,10 @@ from io import BytesIO
from os import path
from typing import Optional, Sequence
from amqpy import Message
from PIL import Image
import publicsuffix
import requests
from amqpy import Message
from PIL import Image
from tildes.enums import ScraperType
from tildes.lib.amqp import PgsqlQueueConsumer
......
......@@ -3,8 +3,8 @@
"""Consumer that fetches data from Embedly's Extract API for link topics."""
from datetime import timedelta
import os
from datetime import timedelta
from typing import Sequence
from amqpy import Message
......
......@@ -5,8 +5,8 @@
from typing import Any, Dict, Sequence
from amqpy import Message
import publicsuffix
from amqpy import Message
from sqlalchemy import cast, func
from sqlalchemy.dialects.postgresql import JSONB
......
......@@ -3,8 +3,8 @@
"""Consumer that fetches data from YouTube's data API for relevant link topics."""
from datetime import timedelta
import os
from datetime import timedelta
from typing import Sequence
from amqpy import Message
......
......@@ -31,3 +31,4 @@ pylint:
- no-self-use # schemas do this a lot, would be nice to only disable for schemas
- too-few-public-methods # plenty of classes that don't need multiple methods
- too-many-instance-attributes # models have many instance attributes
- ungrouped-imports # let isort handle this
[tool.black]
exclude = "(\\.mypy_cache|node_modules|scss|sql|static)"
[tool.isort]
skip = "alembic"
line_length = 88
multi_line_output = 3 # "Vertical Hanging Indent" style
include_trailing_comma = true
lines_after_imports = 2
known_third_party = "alembic"
order_by_type = false
......@@ -13,12 +13,12 @@ place, and will probably just crash completely if they aren't:
* The specified GPG recipient's public key is in the keyring
"""
from datetime import datetime, timedelta
from ftplib import FTP
import logging
from netrc import netrc
import os
import subprocess
from datetime import datetime, timedelta
from ftplib import FTP
from netrc import netrc
import click
......
......@@ -9,8 +9,8 @@ Other things that should probably be added here eventually:
- Delete old used invite codes (30 days after used?)
"""
from datetime import datetime, timedelta
import logging
from datetime import datetime, timedelta
from sqlalchemy.orm.session import Session
from sqlalchemy.sql.expression import text
......
......@@ -8,6 +8,7 @@ import shutil
import stat
from tempfile import NamedTemporaryFile
ICON_FOLDER = "/opt/tildes/static/images/site-icons"
OUTPUT_FILE = "/opt/tildes/static/css/site-icons.css"
......
# Copyright (c) 2018 Tildes contributors <[email protected]>
# SPDX-License-Identifier: AGPL-3.0-or-later
from http.cookiejar import CookieJar
import os
from http.cookiejar import CookieJar
from pyramid import testing
from pyramid.paster import get_app, get_appsettings
......
......@@ -2,7 +2,6 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
from pytest import fixture
from sqlalchemy import and_
from tildes.enums import CommentNotificationType
......
......@@ -5,7 +5,7 @@
from pytest import raises
from tildes.lib.id import id_to_id36, id36_to_id
from tildes.lib.id import id36_to_id, id_to_id36
def test_id_to_id36():
......
......@@ -8,10 +8,10 @@ from random import randint
from pytest import raises
from tildes.lib.ratelimit import (
RATE_LIMITED_ACTIONS,
RateLimitedAction,
RateLimitError,
RateLimitResult,
RATE_LIMITED_ACTIONS,
)
......
......@@ -5,13 +5,13 @@
from typing import Any, Dict, Optional, Tuple
import sentry_sdk
from marshmallow.exceptions import ValidationError
from paste.deploy.config import PrefixMiddleware
from pyramid.config import Configurator
from pyramid.httpexceptions import HTTPTooManyRequests
from pyramid.request import Request
from redis import Redis
import sentry_sdk
from sentry_sdk.integrations.pyramid import PyramidIntegration
from webassets import Bundle
......
......@@ -5,8 +5,8 @@
from typing import Any
from cornice import Service
import venusian
from cornice import Service
class APIv0(Service):
......
......@@ -3,9 +3,8 @@
"""Contains Enum classes."""
from typing import Optional
import enum
from typing import Optional
class CommentNotificationType(enum.Enum):
......
......@@ -3,9 +3,9 @@
"""Contains classes related to handling AMQP (rabbitmq) messages."""
from abc import abstractmethod
import json
import os
from abc import abstractmethod
from typing import Sequence
from amqpy import AbstractConsumer, Connection, Message
......
"""Set up the shared libcmark-gfm library and extensions."""
# pylint: disable=invalid-name
from ctypes import CDLL, c_char_p, c_int, c_size_t, c_void_p
from ctypes import c_char_p, c_int, c_size_t, c_void_p, CDLL
CMARK_DLL = CDLL("/usr/local/lib/libcmark-gfm.so")
......
......@@ -7,7 +7,6 @@ import enum
from typing import Any, Callable, List, Optional
from pyramid.paster import bootstrap
from sqlalchemy import cast, func
from sqlalchemy.dialects.postgresql import ARRAY
from sqlalchemy.engine.interfaces import Dialect
......
......@@ -3,8 +3,8 @@
"""Functions/classes related to dates and times."""
from datetime import datetime, timedelta, timezone
import re
from datetime import datetime, timedelta, timezone
from typing import Any, Optional
from ago import human
......
......@@ -6,6 +6,7 @@
from argon2 import PasswordHasher
from argon2.exceptions import VerifyMismatchError
# These parameter values were chosen to achieve a hash-verification time of about 10ms
# on the current production server. They can be updated to different values if the
# server changes (consider upgrading old password hashes on login as well if that
......
......@@ -3,12 +3,12 @@
"""Functions/constants related to markdown handling."""
from functools import partial
import re
from functools import partial
from typing import Any, Callable, Iterator, List, Match, Optional, Pattern, Tuple
from bs4 import BeautifulSoup
import bleach
from bs4 import BeautifulSoup
from html5lib.filters.base import Filter
from html5lib.treewalkers.base import NonRecursiveTreeWalker
from pygments import highlight
......@@ -20,11 +20,12 @@ from tildes.enums import HTMLSanitizationContext
from tildes.metrics import histogram_timer
from tildes.schemas.group import is_valid_group_path
from tildes.schemas.user import is_valid_username
from .cmark import (
CMARK_EXTENSIONS,
CMARK_OPTS,
cmark_find_syntax_extension,
cmark_node_free,
CMARK_OPTS,
cmark_parser_attach_syntax_extension,
cmark_parser_feed,
cmark_parser_finish,
......
......@@ -7,6 +7,7 @@ from hashlib import sha1
from redis import ConnectionError, Redis, ResponseError # noqa
# unix socket path for redis server with the breached passwords bloom filter
BREACHED_PASSWORDS_REDIS_SOCKET = "/run/redis_breached_passwords/socket"
......
......@@ -3,12 +3,11 @@
"""Functions related to processing/manipulating strings."""
from xml.etree.ElementTree import Element
import re
from typing import Iterator, List, Optional
import unicodedata
from typing import Iterator, List, Optional
from urllib.parse import quote
from xml.etree.ElementTree import Element
from html5lib import HTMLParser
......
......@@ -3,13 +3,13 @@
"""Functions related to transforming URLs (sanitization, cleanup, etc.)."""
import logging
from abc import ABC, abstractmethod
from collections import Counter
import logging
from urllib.parse import (
ParseResult,
parse_qs,
parse_qsl,
ParseResult,
urlencode,
urlparse,
urlunparse,
......
......@@ -2,9 +2,9 @@
from .comment import Comment, EDIT_GRACE_PERIOD
from .comment_bookmark import CommentBookmark
from .comment_label import CommentLabel
from .comment_notification import CommentNotification
from .comment_notification_query import CommentNotificationQuery
from .comment_query import CommentQuery
from .comment_label import CommentLabel
from .comment_tree import CommentInTree, CommentTree
from .comment_vote import CommentVote
......@@ -15,6 +15,7 @@ from tildes.enums import CommentLabelOption
from tildes.metrics import incr_counter
from tildes.models import DatabaseModel
from tildes.models.user import User
from .comment import Comment
......
......@@ -3,8 +3,8 @@
"""Contains the CommentNotification class."""
from datetime import datetime
import re
from datetime import datetime
from typing import Any, List, Sequence, Tuple
from pyramid.security import Allow, DENY_ALL
......@@ -17,6 +17,7 @@ from tildes.enums import CommentNotificationType
from tildes.lib.markdown import LinkifyFilter
from tildes.models import DatabaseModel
from tildes.models.user import User
from .comment import Comment
......
......@@ -10,6 +10,7 @@ from sqlalchemy.orm import joinedload
from tildes.lib.id import id_to_id36
from tildes.models.pagination import PaginatedQuery, PaginatedResults
from .comment_notification import CommentNotification
from .comment_vote import CommentVote
......
......@@ -10,6 +10,7 @@ from sqlalchemy.sql.expression import and_
from tildes.enums import CommentSortOption
from tildes.models.pagination import PaginatedQuery
from .comment import Comment
from .comment_bookmark import CommentBookmark
from .comment_vote import CommentVote
......
......@@ -12,6 +12,7 @@ from wrapt import ObjectProxy
from tildes.enums import CommentTreeSortOption
from tildes.metrics import get_histogram
from tildes.models.user import User
from .comment import Comment
......
......@@ -12,6 +12,7 @@ from sqlalchemy.sql.expression import text
from tildes.metrics import incr_counter
from tildes.models import DatabaseModel
from tildes.models.user import User
from .comment import Comment
......
......@@ -8,6 +8,7 @@ from typing import Any
from pyramid.request import Request
from tildes.models import ModelQuery
from .group import Group
from .group_subscription import GroupSubscription
......
......@@ -12,6 +12,7 @@ from sqlalchemy.sql.expression import text
from tildes.metrics import incr_counter
from tildes.models import DatabaseModel
from tildes.models.user import User
from .group import Group
......
......@@ -21,6 +21,7 @@ from tildes.lib.string import convert_to_url_slug
from tildes.models import DatabaseModel
from tildes.models.user import User
from tildes.schemas.group_wiki_page import GroupWikiPageSchema, PAGE_NAME_MAX_LENGTH
from .group import Group
......
......@@ -9,7 +9,8 @@ from typing import Any, Iterator, List, Optional, Sequence, TypeVar
from pyramid.request import Request
from sqlalchemy import Column, func, inspect
from tildes.lib.id import id_to_id36, id36_to_id
from tildes.lib.id import id36_to_id, id_to_id36
from .model_query import ModelQuery
......
......@@ -14,6 +14,7 @@ from tildes.enums import TopicSortOption
from tildes.lib.datetime import SimpleHoursPeriod, utc_now
from tildes.models.group import Group
from tildes.models.pagination import PaginatedQuery
from .topic import Topic
from .topic_bookmark import TopicBookmark
from .topic_visit import TopicVisit
......
......@@ -13,6 +13,7 @@ from sqlalchemy.orm import relationship
from tildes.lib.datetime import utc_now
from tildes.models import DatabaseModel
from tildes.models.user import User
from .topic import Topic
......
......@@ -12,6 +12,7 @@ from sqlalchemy.sql.expression import text
from tildes.metrics import incr_counter
from tildes.models import DatabaseModel
from tildes.models.user import User
from .topic import Topic
......
......@@ -3,15 +3,16 @@
"""Contains the UserInviteCode class."""
from datetime import datetime
import random
import string
from datetime import datetime
from sqlalchemy import CheckConstraint, Column, ForeignKey, Integer, Text, TIMESTAMP
from sqlalchemy.sql.expression import text
from tildes.lib.string import separate_string
from tildes.models import DatabaseModel
from .user import User
......
......@@ -6,10 +6,10 @@
import enum
from typing import Any, Optional, Type
import sqlalchemy_utils
from marshmallow.exceptions import ValidationError
from marshmallow.fields import Field, String
from marshmallow.validate import Length, OneOf, Regexp
import sqlalchemy_utils
from tildes.lib.datetime import SimpleHoursPeriod
from tildes.lib.id import ID36_REGEX
......
......@@ -5,10 +5,10 @@
import re
import sqlalchemy_utils
from marshmallow import pre_load, Schema, validates
from marshmallow.exceptions import ValidationError
from marshmallow.fields import DateTime
import sqlalchemy_utils
from tildes.schemas.fields import Ltree, Markdown, SimpleString
......
......@@ -7,15 +7,16 @@ import re
import typing
from urllib.parse import urlparse
import sqlalchemy_utils
from marshmallow import pre_load, Schema, validates, validates_schema, ValidationError
from marshmallow.fields import DateTime, List, Nested, String, URL
import sqlalchemy_utils
from tildes.lib.url_transform import apply_url_transformations
from tildes.schemas.fields import Enum, ID36, Ltree, Markdown, SimpleString
from tildes.schemas.group import GroupSchema
from tildes.schemas.user import UserSchema
TITLE_MAX_LENGTH = 200
TAG_SYNONYMS = {"spoiler": ["spoilers"]}
......
......@@ -3,16 +3,17 @@
"""Contains the YoutubeScraper class."""
from datetime import timedelta
import re
from datetime import timedelta
from typing import Any, Dict
from urllib.parse import parse_qs, urlparse
from dateutil import parser
import requests
from dateutil import parser
from tildes.enums import ScraperType
from tildes.models.scraper import ScraperResult
from .exceptions import ScraperError
......
......@@ -14,7 +14,7 @@ from sqlalchemy.orm.exc import FlushError
from webargs.pyramidparser import use_kwargs
from zope.sqlalchemy import mark_changed
from tildes.enums import CommentNotificationType, CommentLabelOption, LogEventType
from tildes.enums import CommentLabelOption, CommentNotificationType, LogEventType
from tildes.lib.datetime import utc_now
from tildes.models.comment import (
Comment,
......@@ -25,7 +25,7 @@ from tildes.models.comment import (
)
from tildes.models.log import LogComment
from tildes.models.topic import TopicVisit
from tildes.schemas.comment import CommentSchema, CommentLabelSchema
from tildes.schemas.comment import CommentLabelSchema, CommentSchema
from tildes.views import IC_NOOP
from tildes.views.decorators import ic_view_config, rate_limit_view
......
......@@ -6,8 +6,8 @@
from marshmallow import ValidationError
from marshmallow.fields import String
from pyramid.httpexceptions import HTTPNotFound
from pyramid.response import Response
from pyramid.request import Request
from pyramid.response import Response
from sqlalchemy import cast, Text
from sqlalchemy.dialects.postgresql import ARRAY
from sqlalchemy.exc import IntegrityError
......
......@@ -6,11 +6,11 @@
from io import BytesIO
import pyotp
import qrcode
from pyramid.httpexceptions import HTTPForbidden, HTTPUnprocessableEntity
from pyramid.request import Request
from pyramid.response import Response
from pyramid.view import view_config
import qrcode
from webargs.pyramidparser import use_kwargs
from tildes.lib.string import separate_string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment