Skip to content

Commit

Permalink
Flake8 improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
stevelacey committed Jan 22, 2023
1 parent cff47d7 commit e652023
Show file tree
Hide file tree
Showing 10 changed files with 519 additions and 146 deletions.
6 changes: 5 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ build = "*"
coverage = "*"
factory-boy = "*"
flake8 = "*"
flake8-bandit = "*"
flake8-bugbear = "*"
flake8-docstrings = "*"
flake8-pyproject = "*"
flake8-quotes = "*"
isort = "*"
pytest = "*"
Expand All @@ -27,6 +31,6 @@ pytest-xdist = {extras = ["psutil"], version = "*"}
twine = "*"

[scripts]
install_linters = "pipenv install autoflake black flake8 isort --dev --skip-lock"
install_linters = "pipenv install black flake8 flake8-bandit flake8-bugbear flake8-docstrings flake8-pyproject flake8-quotes isort --dev --skip-lock"
check = "./script/check"
lint = "./script/lint"
575 changes: 462 additions & 113 deletions Pipfile.lock

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
[tool.black]
line-length = 88

[tool.flake8]
ignore = [
"B001",
"B006",
"B028",
"D100",
"D101",
"D102",
"D103",
"D104",
"D105",
"D106",
"D107",
"D203",
"D202",
"D205",
"D212",
"D213",
"D400",
"D401",
"D404",
"E203",
"E501",
"N818",
"S101",
"S105",
"S106",
"S107",
"S110",
"S311",
"W503",
]
inline-quotes = "double"
per-file-ignores = [
"__init__.py:F403",
]
max-complexity = 12

[tool.isort]
combine_as_imports = true
known_django = "django"
Expand Down
2 changes: 1 addition & 1 deletion tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_avatar_url(self):
return self.avatar.url if self.avatar else self.get_gravatar_url()

def get_gravatar_hash(self):
return md5(self.user.email.lower().encode()).hexdigest()
return md5(self.user.email.lower().encode(), usedforsecurity=False).hexdigest()

def get_gravatar_url(self, default="identicon", size=512):
return f"https://www.gravatar.com/avatar/{self.get_gravatar_hash()}?d={default}&s={size}"
Expand Down
5 changes: 0 additions & 5 deletions tests/test_shortcuts.py

This file was deleted.

6 changes: 4 additions & 2 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ def profile_view_fixture(db, now, profile_factory, rf):

def test_strip_fields(profile_view):
profile_view.set_bundle(dict(slug="te\x00st "))
profile_view.validate_bundle("slug") == "test"
profile_view.validate_bundle("slug")
assert profile_view.bundle["slug"] == "test"

profile_view.secure_fields = ["slug"]

profile_view.set_bundle(dict(slug="te\x00st "))
profile_view.validate_bundle("slug") == "te\x00st "
profile_view.validate_bundle("slug")
assert profile_view.bundle["slug"] == "te\x00st "


def test_validate_bundle(profile_view):
Expand Down
2 changes: 1 addition & 1 deletion worf/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings

DATA_UPLOAD_MAX_MEMORY_SIZE = getattr(settings, "DATA_UPLOAD_MAX_MEMORY_SIZE")
DATA_UPLOAD_MAX_MEMORY_SIZE = settings.DATA_UPLOAD_MAX_MEMORY_SIZE

WORF_API_NAME = getattr(settings, "WORF_API_NAME", "Worf API")
WORF_API_ROOT = getattr(settings, "WORF_API_ROOT", "/api/")
Expand Down
15 changes: 0 additions & 15 deletions worf/shortcuts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import subprocess

from worf import __version__
from worf.casing import camel_to_snake


Expand All @@ -11,17 +8,5 @@ def field_list(value, delimiter="."):
]


def get_version():
try:
hash = (
subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
.strip()
.decode()
)
return f"{__version__}@{hash}"
except: # pragma: no cover # noqa E722 Dont crash for any reason whatsoever
return __version__


def string_list(value):
return value.split(",") if isinstance(value, str) else value
2 changes: 1 addition & 1 deletion worf/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def validate_email(self, value):
raise ValidationError(f"{value} is not a valid email address")
return email

def validate_bundle(self, key):
def validate_bundle(self, key): # noqa: C901
"""
Handle basic type validation and coercion.
Expand Down
14 changes: 7 additions & 7 deletions worf/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from worf.views.action import ActionAPI # noqa
from worf.views.base import AbstractBaseAPI, APIResponse # noqa
from worf.views.create import CreateAPI # noqa
from worf.views.delete import DeleteAPI # noqa
from worf.views.detail import DetailAPI, DetailUpdateAPI # noqa
from worf.views.list import ListAPI, ListCreateAPI # noqa
from worf.views.update import UpdateAPI # noqa
from worf.views.action import ActionAPI # noqa: F401
from worf.views.base import AbstractBaseAPI, APIResponse # noqa: F401
from worf.views.create import CreateAPI # noqa: F401
from worf.views.delete import DeleteAPI # noqa: F401
from worf.views.detail import DetailAPI, DetailUpdateAPI # noqa: F401
from worf.views.list import ListAPI, ListCreateAPI # noqa: F401
from worf.views.update import UpdateAPI # noqa: F401

0 comments on commit e652023

Please sign in to comment.