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

ruff: sort imports #757

Merged
merged 1 commit into from
Aug 20, 2024
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exclude = [
line-length = 100

[tool.ruff.lint]
select = ["B", "C901", "E", "F", "W"]
select = ["B", "C901", "E", "F", "I", "W"]
ignore = ["B904", "B017"]

[tool.ruff.lint.mccabe]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup, find_packages
from setuptools import find_packages, setup

setup(
name='sorl-thumbnail',
Expand Down
2 changes: 1 addition & 1 deletion sorl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from importlib.metadata import version, PackageNotFoundError
from importlib.metadata import PackageNotFoundError, version

try:
__version__ = version("sorl-thumbnail")
Expand Down
2 changes: 1 addition & 1 deletion sorl/thumbnail/admin/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from django import forms
from django.utils.safestring import mark_safe

from sorl.thumbnail.fields import ImageField
from sorl.thumbnail.shortcuts import get_thumbnail


logger = logging.getLogger(__name__)


Expand Down
8 changes: 4 additions & 4 deletions sorl/thumbnail/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import os
import re

from sorl.thumbnail.conf import settings, defaults as default_settings
from sorl.thumbnail.helpers import tokey, serialize
from sorl.thumbnail.images import ImageFile, DummyImageFile
from sorl.thumbnail import default
from sorl.thumbnail.conf import defaults as default_settings
from sorl.thumbnail.conf import settings
from sorl.thumbnail.helpers import serialize, tokey
from sorl.thumbnail.images import DummyImageFile, ImageFile
from sorl.thumbnail.parsers import parse_geometry


logger = logging.getLogger(__name__)

EXTENSIONS = {
Expand Down
1 change: 1 addition & 0 deletions sorl/thumbnail/conf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf import settings as user_settings

from sorl.thumbnail.conf import defaults


Expand Down
3 changes: 1 addition & 2 deletions sorl/thumbnail/engines/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from sorl.thumbnail.conf import settings
from sorl.thumbnail.helpers import toint
from sorl.thumbnail.parsers import parse_crop
from sorl.thumbnail.parsers import parse_cropbox
from sorl.thumbnail.parsers import parse_crop, parse_cropbox


class EngineBase:
Expand Down
6 changes: 3 additions & 3 deletions sorl/thumbnail/engines/convert_engine.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import re
import logging
import os
import re
import subprocess
import logging
from collections import OrderedDict

from django.utils.encoding import smart_str
from django.core.files.temp import NamedTemporaryFile
from django.utils.encoding import smart_str

from sorl.thumbnail.base import EXTENSIONS
from sorl.thumbnail.conf import settings
Expand Down
4 changes: 2 additions & 2 deletions sorl/thumbnail/engines/pgmagick_engine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pgmagick import Blob, Geometry, Image, ImageType
from pgmagick import InterlaceType, OrientationType
from pgmagick import Blob, Geometry, Image, ImageType, InterlaceType, OrientationType

from sorl.thumbnail.engines.base import EngineBase

try:
Expand Down
6 changes: 3 additions & 3 deletions sorl/thumbnail/engines/pil_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from sorl.thumbnail.engines.base import EngineBase

try:
from PIL import Image, ImageFile, ImageDraw, ImageFilter, ImageMode
from PIL import Image, ImageDraw, ImageFile, ImageFilter, ImageMode
except ImportError:
import Image
import ImageFile
import ImageDraw
import ImageFile
import ImageMode

if hasattr(Image, 'Resampling'):
Expand Down Expand Up @@ -36,7 +36,7 @@ def color_count(image):

def histogram_entropy_py(image):
""" Calculate the entropy of an images' histogram. """
from math import log2, fsum
from math import fsum, log2
histosum = float(color_count(image))
histonorm = (histocol / histosum for histocol in image.histogram())
return -fsum(p * log2(p) for p in histonorm if p != 0.0)
Expand Down
5 changes: 2 additions & 3 deletions sorl/thumbnail/engines/vipsthumbnail_engine.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import re
import os
import re
import subprocess
from collections import OrderedDict

from django.utils.encoding import smart_str
from django.core.files.temp import NamedTemporaryFile
from django.utils.encoding import smart_str

from sorl.thumbnail.base import EXTENSIONS
from sorl.thumbnail.conf import settings
from sorl.thumbnail.engines.base import EngineBase


size_re = re.compile(r'^(?:.+) (?P<x>\d+)x(?P<y>\d+)')


Expand Down
3 changes: 2 additions & 1 deletion sorl/thumbnail/engines/wand_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
Wand (>=v0.3.0) engine for Sorl-thumbnail
'''

from wand import exceptions
from wand.image import Image
from wand.version import MAGICK_VERSION_NUMBER
from wand import exceptions

from sorl.thumbnail.engines.base import EngineBase


Expand Down
3 changes: 1 addition & 2 deletions sorl/thumbnail/fields.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from django import forms
from django.db import models
from django.db.models import Q
from django import forms
from django.utils.translation import gettext_lazy as _

from sorl.thumbnail import default


__all__ = ('ImageField', 'ImageFormField')


Expand Down
7 changes: 4 additions & 3 deletions sorl/thumbnail/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
from functools import lru_cache
from urllib.error import URLError
from urllib.parse import quote, quote_plus, urlsplit, urlunsplit
from urllib.request import urlopen, Request
from urllib.request import Request, urlopen

from django.core.files.base import File, ContentFile
from django.core.files.base import ContentFile, File
from django.core.files.storage import Storage # , default_storage
from django.utils.encoding import force_str
from django.utils.functional import LazyObject, empty

from sorl.thumbnail import default
from sorl.thumbnail.conf import settings
from sorl.thumbnail.default import storage as default_storage
from sorl.thumbnail.helpers import ThumbnailError, tokey, get_module_class, deserialize
from sorl.thumbnail.helpers import ThumbnailError, deserialize, get_module_class, tokey
from sorl.thumbnail.parsers import parse_geometry

url_pat = re.compile(r'^(https?|ftp):\/\/')
Expand Down
4 changes: 2 additions & 2 deletions sorl/thumbnail/kvstores/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sorl.thumbnail.conf import settings
from sorl.thumbnail.helpers import serialize, deserialize, ThumbnailError
from sorl.thumbnail.images import serialize_image_file, deserialize_image_file
from sorl.thumbnail.helpers import ThumbnailError, deserialize, serialize
from sorl.thumbnail.images import deserialize_image_file, serialize_image_file


def add_prefix(key, identity='image'):
Expand Down
5 changes: 3 additions & 2 deletions sorl/thumbnail/kvstores/cached_db_kvstore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.core.cache import cache, caches, InvalidCacheBackendError
from sorl.thumbnail.kvstores.base import KVStoreBase
from django.core.cache import InvalidCacheBackendError, cache, caches

from sorl.thumbnail.conf import settings
from sorl.thumbnail.kvstores.base import KVStoreBase
from sorl.thumbnail.models import KVStore as KVStoreModel


Expand Down
3 changes: 1 addition & 2 deletions sorl/thumbnail/kvstores/dbm_kvstore.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os

from sorl.thumbnail.kvstores.base import KVStoreBase
from sorl.thumbnail.conf import settings

from sorl.thumbnail.kvstores.base import KVStoreBase

try:
import anydbm as dbm
Expand Down
5 changes: 3 additions & 2 deletions sorl/thumbnail/kvstores/dynamodb_kvstore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from boto.dynamodb2.table import Table
import boto
from sorl.thumbnail.kvstores.base import KVStoreBase
from boto.dynamodb2.table import Table

from sorl.thumbnail.conf import settings
from sorl.thumbnail.kvstores.base import KVStoreBase


class KVStore(KVStoreBase):
Expand Down
3 changes: 2 additions & 1 deletion sorl/thumbnail/kvstores/redis_kvstore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import redis
from sorl.thumbnail.kvstores.base import KVStoreBase

from sorl.thumbnail.conf import settings
from sorl.thumbnail.kvstores.base import KVStoreBase


class KVStore(KVStoreBase):
Expand Down
1 change: 0 additions & 1 deletion sorl/thumbnail/management/commands/thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from sorl.thumbnail import default
from sorl.thumbnail.images import delete_all_thumbnails


VALID_LABELS = ['cleanup', 'clear', 'clear_delete_referenced', 'clear_delete_all']


Expand Down
1 change: 0 additions & 1 deletion sorl/thumbnail/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from sorl.thumbnail.helpers import ThumbnailError, toint


bgpos_pat = re.compile(r'^(?P<value>\d+)(?P<unit>%|px)$')
geometry_pat = re.compile(r'^(?P<x>\d+)?(?:x(?P<y>\d+))?$')

Expand Down
11 changes: 5 additions & 6 deletions sorl/thumbnail/templatetags/thumbnail.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import decimal
import logging
import sys
import re
import os
import re
import sys
from functools import wraps

from django.conf import settings
from django.template import Library, Node, NodeList, TemplateSyntaxError
from django.utils.encoding import smart_str
from django.conf import settings

from sorl.thumbnail.conf import settings as sorl_settings
from sorl.thumbnail import default
from sorl.thumbnail.images import ImageFile, DummyImageFile
from sorl.thumbnail.conf import settings as sorl_settings
from sorl.thumbnail.images import DummyImageFile, ImageFile
from sorl.thumbnail.parsers import parse_geometry
from sorl.thumbnail.shortcuts import get_thumbnail


register = Library()
kw_pat = re.compile(r'^(?P<key>[\w]+)=(?P<value>.+)$')
logger = logging.getLogger('sorl.thumbnail')
Expand Down
3 changes: 1 addition & 2 deletions tests/thumbnail_tests/test_alternative_resolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

from sorl.thumbnail import get_thumbnail
from sorl.thumbnail.conf import settings
from sorl.thumbnail.images import ImageFile
from sorl.thumbnail.engines.pil_engine import Engine as PILEngine
from sorl.thumbnail.images import ImageFile

from .utils import BaseStorageTestCase


pytestmark = pytest.mark.django_db


Expand Down
10 changes: 5 additions & 5 deletions tests/thumbnail_tests/test_backends.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
from io import StringIO
import os
import platform
import sys
import shutil
import sys
import unittest
from PIL import Image
from io import StringIO

import pytest
from django.test import TestCase
from django.test.utils import override_settings
from PIL import Image

from sorl.thumbnail import default, delete, get_thumbnail
from sorl.thumbnail.base import ThumbnailBackend
from sorl.thumbnail.conf import settings
from sorl.thumbnail.helpers import get_module_class
from sorl.thumbnail.images import ImageFile
from .utils import BaseTestCase, FakeFile, same_open_fd_count
from .models import Item

from .models import Item
from .utils import BaseTestCase, FakeFile, same_open_fd_count

pytestmark = pytest.mark.django_db

Expand Down
4 changes: 2 additions & 2 deletions tests/thumbnail_tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from io import StringIO
import os
from io import StringIO

import pytest
from django.core import management

from sorl.thumbnail.conf import settings

from .models import Item
from .utils import BaseTestCase


pytestmark = pytest.mark.django_db


Expand Down
8 changes: 4 additions & 4 deletions tests/thumbnail_tests/test_engines.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import os
import platform
import unittest
from subprocess import Popen, PIPE
from subprocess import PIPE, Popen

import pytest
from PIL import Image
from django.core.files.storage import default_storage
from django.template.loader import render_to_string
from PIL import Image

from sorl.thumbnail import default
from sorl.thumbnail.base import ThumbnailBackend
from sorl.thumbnail.conf import settings
from sorl.thumbnail.engines.pil_engine import Engine as PILEngine
from sorl.thumbnail.helpers import get_module_class
from sorl.thumbnail.images import ImageFile
from sorl.thumbnail.parsers import parse_geometry
from sorl.thumbnail.templatetags.thumbnail import margin
from sorl.thumbnail.engines.pil_engine import Engine as PILEngine

from .models import Item
from .utils import BaseTestCase


pytestmark = pytest.mark.django_db


Expand Down
1 change: 0 additions & 1 deletion tests/thumbnail_tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from tests.thumbnail_tests.utils import BaseTestCase


pytestmark = pytest.mark.django_db


Expand Down
4 changes: 2 additions & 2 deletions tests/thumbnail_tests/test_storage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import unittest

import pytest

from sorl.thumbnail import get_thumbnail, default
from sorl.thumbnail import default, get_thumbnail
from sorl.thumbnail.helpers import get_module_class

from .utils import BaseStorageTestCase


pytestmark = pytest.mark.django_db


Expand Down
Loading
Loading