Skip to content

Commit

Permalink
lint and add pre-commit configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswilm committed Aug 9, 2022
1 parent f40705b commit a977753
Show file tree
Hide file tree
Showing 27 changed files with 101 additions and 128 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/lint.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
- name: Run Tests
run: |
echo "$(python --version) / Django $(django-admin --version)"
make test
coverage run --source=avatar `which django-admin` test tests
coverage report
coverage xml
- uses: codecov/codecov-action@v2
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pycqa/isort
rev: "5.10.1"
hooks:
- id: isort
args: ["--profile", "black"]

- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
args: [--target-version=py310]

- repo: https://github.com/pycqa/flake8
rev: '5.0.4'
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-tidy-imports
- flake8-print
args: [--max-line-length=120]
1 change: 0 additions & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

21 changes: 0 additions & 21 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion avatar/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _

from avatar.models import Avatar
from avatar.signals import avatar_updated
Expand Down
6 changes: 2 additions & 4 deletions avatar/conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from PIL import Image

from django.conf import settings

from appconf import AppConf
from django.conf import settings
from PIL import Image


class AvatarConf(AppConf):
Expand Down
2 changes: 1 addition & 1 deletion avatar/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from django import forms
from django.forms import widgets
from django.template.defaultfilters import filesizeformat
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django.template.defaultfilters import filesizeformat

from avatar.conf import settings
from avatar.models import Avatar
Expand Down
4 changes: 3 additions & 1 deletion avatar/management/commands/rebuild_avatars.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def handle(self, *args, **options):
for avatar in Avatar.objects.all():
for size in settings.AVATAR_AUTO_GENERATE_SIZES:
if options["verbosity"] != 0:
print("Rebuilding Avatar id=%s at size %s." % (avatar.id, size))
self.stdout.write(
"Rebuilding Avatar id=%s at size %s." % (avatar.id, size)
)

avatar.create_thumbnail(size)
7 changes: 4 additions & 3 deletions avatar/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.db import models, migrations
import django.utils.timezone
import avatar.models
import django.core.files.storage
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models

import avatar.models


class Migration(migrations.Migration):
Expand Down
7 changes: 4 additions & 3 deletions avatar/migrations/0002_add_verbose_names_to_avatar_fields.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import avatar.models
from django.conf import settings
import django.core.files.storage
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models

import avatar.models


class Migration(migrations.Migration):
Expand Down
3 changes: 2 additions & 1 deletion avatar/migrations/0003_auto_20170827_1345.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import avatar.models
from django.db import migrations

import avatar.models


class Migration(migrations.Migration):

Expand Down
17 changes: 8 additions & 9 deletions avatar/models.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import binascii
import os
import hashlib
import os
from io import BytesIO
from PIL import Image

from django.db import models
from django.core.files import File
from django.core.files.base import ContentFile
from django.core.files.storage import get_storage_class
from django.utils.module_loading import import_string
from django.utils.translation import gettext_lazy as _
from django.utils.encoding import force_str
from django.db import models
from django.db.models import signals
from django.utils.encoding import force_str
from django.utils.module_loading import import_string
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _
from PIL import Image

from avatar.conf import settings
from avatar.utils import get_username, force_bytes, invalidate_cache

from avatar.utils import force_bytes, get_username, invalidate_cache

avatar_storage = get_storage_class(settings.AVATAR_STORAGE)()

Expand Down Expand Up @@ -139,7 +138,7 @@ def transpose_image(self, image):
try:
orientation = image._getexif()[0x0112]
ops = EXIF_ORIENTATION_STEPS[orientation]
except:
except AttributeError:
ops = []
for method in ops:
image = image.transpose(getattr(Image, method))
Expand Down
9 changes: 2 additions & 7 deletions avatar/providers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import hashlib
from urllib.parse import urljoin, urlencode
from urllib.parse import urlencode, urljoin

from django.utils.module_loading import import_string

from avatar.conf import settings
from avatar.utils import (
force_bytes,
get_default_avatar_url,
get_primary_avatar,
)

from avatar.utils import force_bytes, get_default_avatar_url, get_primary_avatar

# If the FacebookAvatarProvider is used, a mechanism needs to be defined on
# how to obtain the user's Facebook UID. This is done via
Expand Down
1 change: 0 additions & 1 deletion avatar/signals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import django.dispatch


avatar_updated = django.dispatch.Signal()
avatar_deleted = django.dispatch.Signal()
2 changes: 1 addition & 1 deletion avatar/templates/avatar/avatar_tag.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<img src="{{ url }}" width="{{ size }}" height="{{ size }}" {% for key, value in kwargs.items %}{{key}}="{{value}}" {% endfor %}/>
<img src="{{ url }}" width="{{ size }}" height="{{ size }}" {% for key, value in kwargs.items %}{{key}}="{{value}}" {% endfor %}/>
2 changes: 1 addition & 1 deletion avatar/templates/avatar/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
<body>
{% block content %}{% endblock %}
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion avatar/templates/notification/avatar_updated/notice.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% load i18n %}
{% blocktrans with user as avatar_creator and avatar.get_absolute_url as avatar_url %}You have updated your avatar <a href="{{ avatar_url }}">{{ avatar }}</a>.{% endblocktrans %}
{% blocktrans with user as avatar_creator and avatar.get_absolute_url as avatar_url %}You have updated your avatar <a href="{{ avatar_url }}">{{ avatar }}</a>.{% endblocktrans %}
13 changes: 3 additions & 10 deletions avatar/templatetags/avatar_tags.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
from django import template
from django.urls import reverse

from django.template.loader import render_to_string
from django.utils.translation import gettext as _
from django.urls import reverse
from django.utils.module_loading import import_string
from django.utils.translation import gettext as _

from avatar.conf import settings
from avatar.models import Avatar
from avatar.utils import (
cache_result,
get_default_avatar_url,
get_user_model,
get_user,
)

from avatar.utils import cache_result, get_default_avatar_url, get_user, get_user_model

register = template.Library()

Expand Down
3 changes: 1 addition & 2 deletions avatar/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import hashlib

from django.contrib.auth import get_user_model
from django.core.cache import cache
from django.template.defaultfilters import slugify
from django.utils.encoding import force_bytes
from django.contrib.auth import get_user_model

from avatar.conf import settings


cached_funcs = set()


Expand Down
14 changes: 7 additions & 7 deletions avatar/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from django.shortcuts import render, redirect
from django.utils.translation import gettext as _
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect, render
from django.utils.translation import gettext as _

from avatar.conf import settings
from avatar.forms import PrimaryAvatarForm, DeleteAvatarForm, UploadAvatarForm
from avatar.forms import DeleteAvatarForm, PrimaryAvatarForm, UploadAvatarForm
from avatar.models import Avatar
from avatar.signals import avatar_updated, avatar_deleted
from avatar.utils import get_primary_avatar, get_default_avatar_url, invalidate_cache
from avatar.signals import avatar_deleted, avatar_updated
from avatar.utils import get_default_avatar_url, get_primary_avatar, invalidate_cache


def _get_next(request):
Expand Down Expand Up @@ -60,7 +60,7 @@ def add(
next_override=None,
upload_form=UploadAvatarForm,
*args,
**kwargs
**kwargs,
):
if extra_context is None:
extra_context = {}
Expand Down Expand Up @@ -96,7 +96,7 @@ def change(
upload_form=UploadAvatarForm,
primary_form=PrimaryAvatarForm,
*args,
**kwargs
**kwargs,
):
if extra_context is None:
extra_context = {}
Expand Down
9 changes: 5 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -174,11 +175,11 @@

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
# 'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import codecs
import re
from os import path
from setuptools import setup, find_packages

from setuptools import find_packages, setup


def read(*parts):
Expand Down
28 changes: 14 additions & 14 deletions test_proj/manage.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys

if __name__ == "__main__":

def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_proj.settings")

# Add the django-avatar directory to the Python path. That way the
# avatar module can be imported.
sys.path.append("..")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion test_proj/test_proj/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf import settings
from django.conf.urls import url, include
from django.conf.urls import include, url
from django.contrib import admin
from django.views.static import serve

Expand Down
Loading

0 comments on commit a977753

Please sign in to comment.