Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Improvement) Flake8 improvements #137

Merged
merged 1 commit into from
Jan 23, 2023
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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- run: pip install pipenv
- run: pipenv run install_linters
- run: pipenv run check
5 changes: 4 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,5 @@ pytest-xdist = {extras = ["psutil"], version = "*"}
twine = "*"

[scripts]
install_linters = "pipenv install autoflake black flake8 isort --dev --skip-lock"
check = "./script/check"
lint = "./script/lint"
287 changes: 286 additions & 1 deletion 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
4 changes: 4 additions & 0 deletions script/check
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ cd "$(dirname "$0")/.."

ARROW="\033[93m==>\033[0m"

if [ ${CI:+x} ]; then
cat Pipfile | grep "^black\|^flake8\|^isort" | sed "s/ = .*//g" | xargs pipenv install --dev --skip-lock
fi

echo -e "$ARROW black worf tests --check"
black worf tests --check

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()).hexdigest() # noqa: S324

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