Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[flake8]
max-line-length=100
docstring-convention=all
import-order-style=pycharm
application_import_names=pydis_site
exclude=__pycache__, venv, .venv, manage.py, **/migrations
ignore=
P102,B311,W503,E226,S311,
B311,W503,E226,S311,T000
# Missing Docstrings
D100,D104,D105,D107,
# Docstring Whitespace
Expand All @@ -10,11 +14,7 @@ ignore=
D301,D302,
# Docstring Content
D400,D401,D402,D404,D405,D406,D407,D408,D409,D410,D411,D412,D413,D414,D416,D417

# Type Annotations
TYP002,TYP003,TYP101,TYP102,TYP204,TYP206
per-file-ignores =
**/tests/**:D101,D102,D103,D105,D106,S106

application_import_names=pydis_site
exclude=__pycache__, venv, .venv, **/migrations
import-order-style=pycharm
max-line-length=100
**/tests/**:D1,S106,TYP
30 changes: 16 additions & 14 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@ name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
flake8 = "~=3.7.7"
flake8-bandit = "==1.0.2"
flake8-bugbear = "~=19.3.0"
flake8-docstrings = "~=1.4.0"
flake8-import-order = "~=0.18.1"
flake8-string-format = "~=0.2.3"
flake8-tidy-imports = "~=2.0.0"
mccabe = "~=0.6.1"
pep8-naming = "~=0.8.2"
coverage = "~=4.5.3"
unittest-xml-reporting = "~=2.5.1"
pre-commit = "~=1.17.0"

[packages]
django = "~=2.2"
django-crispy-forms = "~=1.7.2"
Expand All @@ -35,6 +21,22 @@ pygments = "~=2.3.1"
wiki = {path = "./docker/app/wheels/wiki-0.5.dev20190420204942-py3-none-any.whl"}
pyyaml = "*"

[dev-packages]
coverage = "~=4.5.3"
flake8 = "~=3.7"
flake8-annotations = "~=1.0"
flake8-bandit = "==1.0.2"
flake8-bugbear = "~=19.8"
flake8-docstrings = "~=1.4"
flake8-import-order = "~=0.18"
flake8-string-format = "~=0.2"
flake8-tidy-imports = "~=2.0"
flake8-todo = "~=0.7"
mccabe = "~=0.6.1"
pep8-naming = "~=0.8.2"
pre-commit = "~=1.18"
unittest-xml-reporting = "~=2.5.1"

[requires]
python_version = "3.7"

Expand Down
43 changes: 33 additions & 10 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pydis_site/apps/api/dblogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class DatabaseLogHandler(StreamHandler):
"""Logs entries into the database."""

def emit(self, record: LogRecord):
def emit(self, record: LogRecord) -> None:
"""Write the given `record` into the database."""
# This import needs to be deferred due to Django's application
# registry instantiation logic loading this handler before the
Expand Down
7 changes: 4 additions & 3 deletions pydis_site/apps/api/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .bot import ( # noqa
# flake8: noqa
from .bot import (
BotSetting,
DocumentationLink,
DeletedMessage,
Expand All @@ -12,5 +13,5 @@
Tag,
User
)
from .log_entry import LogEntry # noqa
from .utils import ModelReprMixin # noqa
from .log_entry import LogEntry
from .utils import ModelReprMixin
25 changes: 13 additions & 12 deletions pydis_site/apps/api/models/bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from .bot_setting import BotSetting # noqa
from .deleted_message import DeletedMessage # noqa
from .documentation_link import DocumentationLink # noqa
from .infraction import Infraction # noqa
from .message import Message # noqa
from .message_deletion_context import MessageDeletionContext # noqa
from .nomination import Nomination # noqa
from .off_topic_channel_name import OffTopicChannelName # noqa
from .reminder import Reminder # noqa
from .role import Role # noqa
from .tag import Tag # noqa
from .user import User # noqa
# flake8: noqa
from .bot_setting import BotSetting
from .deleted_message import DeletedMessage
from .documentation_link import DocumentationLink
from .infraction import Infraction
from .message import Message
from .message_deletion_context import MessageDeletionContext
from .nomination import Nomination
from .off_topic_channel_name import OffTopicChannelName
from .reminder import Reminder
from .role import Role
from .tag import Tag
from .user import User
2 changes: 1 addition & 1 deletion pydis_site/apps/api/models/bot/bot_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydis_site.apps.api.models.utils import ModelReprMixin


def validate_bot_setting_name(name):
def validate_bot_setting_name(name: str) -> None:
"""Raises a ValidationError if the given name is not a known setting."""
known_settings = (
'defcon',
Expand Down
12 changes: 6 additions & 6 deletions pydis_site/apps/api/models/bot/tag.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Mapping
from typing import Any
from typing import Any, Dict

from django.contrib.postgres import fields as pgfields
from django.core.exceptions import ValidationError
Expand All @@ -15,7 +15,7 @@ def is_bool_validator(value: Any) -> None:
raise ValidationError(f"This field must be of type bool, not {type(value)}.")


def validate_tag_embed_fields(fields):
def validate_tag_embed_fields(fields: dict) -> None:
Comment thread
SebastiaanZ marked this conversation as resolved.
"""Raises a ValidationError if any of the given embed fields is invalid."""
field_validators = {
'name': (MaxLengthValidator(limit_value=256),),
Expand All @@ -42,7 +42,7 @@ def validate_tag_embed_fields(fields):
validator(value)


def validate_tag_embed_footer(footer):
def validate_tag_embed_footer(footer: Dict[str, str]) -> None:
"""Raises a ValidationError if the given footer is invalid."""
field_validators = {
'text': (
Expand All @@ -67,7 +67,7 @@ def validate_tag_embed_footer(footer):
validator(value)


def validate_tag_embed_author(author):
def validate_tag_embed_author(author: Any) -> None:
Comment thread
SebastiaanZ marked this conversation as resolved.
"""Raises a ValidationError if the given author is invalid."""
field_validators = {
'name': (
Expand All @@ -93,7 +93,7 @@ def validate_tag_embed_author(author):
validator(value)


def validate_tag_embed(embed):
def validate_tag_embed(embed: Any) -> None:
"""
Validate a JSON document containing an embed as possible to send on Discord.

Expand All @@ -120,7 +120,7 @@ def validate_tag_embed(embed):
...

Args:
embed (Dict[str, Union[str, List[dict], dict]]):
embed (Any):
A dictionary describing the contents of this embed.
See the official documentation for a full reference
of accepted keys by this dictionary:
Expand Down
2 changes: 1 addition & 1 deletion pydis_site/apps/api/models/bot/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class User(ModelReprMixin, models.Model):
"""A Discord user."""

id = models.BigIntegerField( # noqa
id = models.BigIntegerField(
primary_key=True,
validators=(
MinValueValidator(
Expand Down
8 changes: 4 additions & 4 deletions pydis_site/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Meta:
fields = ('actor', 'creation', 'id', 'deletedmessage_set')
depth = 1

def create(self, validated_data):
def create(self, validated_data: dict) -> MessageDeletionContext:
"""
Return a `MessageDeletionContext` based on the given data.

Expand Down Expand Up @@ -106,7 +106,7 @@ class Meta:
'id', 'inserted_at', 'expires_at', 'active', 'user', 'actor', 'type', 'reason', 'hidden'
)

def validate(self, attrs):
def validate(self, attrs: dict) -> dict:
Comment thread
SebastiaanZ marked this conversation as resolved.
"""Validate data constraints for the given data and abort if it is invalid."""
infr_type = attrs.get('type')

Expand All @@ -129,7 +129,7 @@ class ExpandedInfractionSerializer(InfractionSerializer):
serializer also attaches the `user` and `actor` fields when serializing.
"""

def to_representation(self, instance):
def to_representation(self, instance: Infraction) -> dict:
"""Return the dictionary representation of this infraction."""
ret = super().to_representation(instance)

Expand Down Expand Up @@ -166,7 +166,7 @@ class Meta:
model = OffTopicChannelName
fields = ('name',)

def to_representation(self, obj):
def to_representation(self, obj: OffTopicChannelName) -> str:
"""
Return the representation of this `OffTopicChannelName`.

Expand Down
2 changes: 1 addition & 1 deletion pydis_site/apps/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class RulesView(APIView):
permission_classes = ()

@staticmethod
def _format_link(description, link, target):
def _format_link(description: str, link: str, target: str) -> str:
"""
Build the markup for rendering the link.

Expand Down
5 changes: 3 additions & 2 deletions pydis_site/apps/api/viewsets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .bot import ( # noqa
# flake8: noqa
from .bot import (
BotSettingViewSet,
DeletedMessageViewSet,
DocumentationLinkViewSet,
Expand All @@ -10,4 +11,4 @@
TagViewSet,
UserViewSet
)
from .log_entry import LogEntryViewSet # noqa
from .log_entry import LogEntryViewSet
21 changes: 11 additions & 10 deletions pydis_site/apps/api/viewsets/bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from .bot_setting import BotSettingViewSet # noqa
from .deleted_message import DeletedMessageViewSet # noqa
from .documentation_link import DocumentationLinkViewSet # noqa
from .infraction import InfractionViewSet # noqa
from .nomination import NominationViewSet # noqa
from .off_topic_channel_name import OffTopicChannelNameViewSet # noqa
from .reminder import ReminderViewSet # noqa
from .role import RoleViewSet # noqa
from .tag import TagViewSet # noqa
from .user import UserViewSet # noqa
# flake8: noqa
from .bot_setting import BotSettingViewSet
from .deleted_message import DeletedMessageViewSet
from .documentation_link import DocumentationLinkViewSet
from .infraction import InfractionViewSet
from .nomination import NominationViewSet
from .off_topic_channel_name import OffTopicChannelNameViewSet
from .reminder import ReminderViewSet
from .role import RoleViewSet
from .tag import TagViewSet
from .user import UserViewSet
Loading