Browse Source

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.
merge-requests/72/head
Deimos 6 years ago
parent
commit
31ab15fe51
  1. 4
      tildes/consumers/site_icon_downloader.py
  2. 2
      tildes/consumers/topic_embedly_extractor.py
  3. 2
      tildes/consumers/topic_metadata_generator.py
  4. 2
      tildes/consumers/topic_youtube_scraper.py
  5. 1
      tildes/prospector.yaml
  6. 9
      tildes/pyproject.toml
  7. 6
      tildes/scripts/backup_database.py
  8. 2
      tildes/scripts/clean_private_data.py
  9. 1
      tildes/scripts/generate_site_icons_css.py
  10. 2
      tildes/tests/conftest.py
  11. 1
      tildes/tests/test_comment_user_mentions.py
  12. 2
      tildes/tests/test_id.py
  13. 2
      tildes/tests/test_ratelimit.py
  14. 2
      tildes/tildes/__init__.py
  15. 2
      tildes/tildes/api.py
  16. 3
      tildes/tildes/enums.py
  17. 2
      tildes/tildes/lib/amqp.py
  18. 2
      tildes/tildes/lib/cmark.py
  19. 1
      tildes/tildes/lib/database.py
  20. 2
      tildes/tildes/lib/datetime.py
  21. 1
      tildes/tildes/lib/hash.py
  22. 7
      tildes/tildes/lib/markdown.py
  23. 1
      tildes/tildes/lib/password.py
  24. 5
      tildes/tildes/lib/string.py
  25. 4
      tildes/tildes/lib/url_transform.py
  26. 2
      tildes/tildes/models/comment/__init__.py
  27. 1
      tildes/tildes/models/comment/comment_label.py
  28. 3
      tildes/tildes/models/comment/comment_notification.py
  29. 1
      tildes/tildes/models/comment/comment_notification_query.py
  30. 1
      tildes/tildes/models/comment/comment_query.py
  31. 1
      tildes/tildes/models/comment/comment_tree.py
  32. 1
      tildes/tildes/models/comment/comment_vote.py
  33. 1
      tildes/tildes/models/group/group_query.py
  34. 1
      tildes/tildes/models/group/group_subscription.py
  35. 1
      tildes/tildes/models/group/group_wiki_page.py
  36. 3
      tildes/tildes/models/pagination.py
  37. 1
      tildes/tildes/models/topic/topic_query.py
  38. 1
      tildes/tildes/models/topic/topic_visit.py
  39. 1
      tildes/tildes/models/topic/topic_vote.py
  40. 3
      tildes/tildes/models/user/user_invite_code.py
  41. 2
      tildes/tildes/schemas/fields.py
  42. 2
      tildes/tildes/schemas/group.py
  43. 3
      tildes/tildes/schemas/topic.py
  44. 5
      tildes/tildes/scrapers/youtube_scraper.py
  45. 4
      tildes/tildes/views/api/web/comment.py
  46. 2
      tildes/tildes/views/api/web/topic.py
  47. 2
      tildes/tildes/views/settings.py

4
tildes/consumers/site_icon_downloader.py

@ -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

2
tildes/consumers/topic_embedly_extractor.py

@ -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

2
tildes/consumers/topic_metadata_generator.py

@ -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

2
tildes/consumers/topic_youtube_scraper.py

@ -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

1
tildes/prospector.yaml

@ -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

9
tildes/pyproject.toml

@ -1,2 +1,11 @@
[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

6
tildes/scripts/backup_database.py

@ -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

2
tildes/scripts/clean_private_data.py

@ -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

1
tildes/scripts/generate_site_icons_css.py

@ -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"

2
tildes/tests/conftest.py

@ -1,8 +1,8 @@
# Copyright (c) 2018 Tildes contributors <code@tildes.net>
# 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

1
tildes/tests/test_comment_user_mentions.py

@ -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

2
tildes/tests/test_id.py

@ -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():

2
tildes/tests/test_ratelimit.py

@ -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,
)

2
tildes/tildes/__init__.py

@ -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

2
tildes/tildes/api.py

@ -5,8 +5,8 @@
from typing import Any
from cornice import Service
import venusian
from cornice import Service
class APIv0(Service):

3
tildes/tildes/enums.py

@ -3,9 +3,8 @@
"""Contains Enum classes."""
from typing import Optional
import enum
from typing import Optional
class CommentNotificationType(enum.Enum):

2
tildes/tildes/lib/amqp.py

@ -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

2
tildes/tildes/lib/cmark.py

@ -1,7 +1,7 @@
"""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")

1
tildes/tildes/lib/database.py

@ -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

2
tildes/tildes/lib/datetime.py

@ -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

1
tildes/tildes/lib/hash.py

@ -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

7
tildes/tildes/lib/markdown.py

@ -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,

1
tildes/tildes/lib/password.py

@ -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"

5
tildes/tildes/lib/string.py

@ -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

4
tildes/tildes/lib/url_transform.py

@ -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
tildes/tildes/models/comment/__init__.py

@ -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

1
tildes/tildes/models/comment/comment_label.py

@ -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
tildes/tildes/models/comment/comment_notification.py

@ -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

1
tildes/tildes/models/comment/comment_notification_query.py

@ -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

1
tildes/tildes/models/comment/comment_query.py

@ -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

1
tildes/tildes/models/comment/comment_tree.py

@ -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

1
tildes/tildes/models/comment/comment_vote.py

@ -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

1
tildes/tildes/models/group/group_query.py

@ -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

1
tildes/tildes/models/group/group_subscription.py

@ -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

1
tildes/tildes/models/group/group_wiki_page.py

@ -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

3
tildes/tildes/models/pagination.py

@ -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

1
tildes/tildes/models/topic/topic_query.py

@ -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

1
tildes/tildes/models/topic/topic_visit.py

@ -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

1
tildes/tildes/models/topic/topic_vote.py

@ -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
tildes/tildes/models/user/user_invite_code.py

@ -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

2
tildes/tildes/schemas/fields.py

@ -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

2
tildes/tildes/schemas/group.py

@ -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

3
tildes/tildes/schemas/topic.py

@ -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"]}

5
tildes/tildes/scrapers/youtube_scraper.py

@ -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

4
tildes/tildes/views/api/web/comment.py

@ -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

2
tildes/tildes/views/api/web/topic.py

@ -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

2
tildes/tildes/views/settings.py

@ -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

Loading…
Cancel
Save