Skip to content

Commit 1d7aafc

Browse files
committed
Apply new linters
1 parent de894d8 commit 1d7aafc

File tree

16 files changed

+41
-54
lines changed

16 files changed

+41
-54
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
version: 2
22
updates:
3-
- package-ecosystem: pip
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
- package-ecosystem: github-actions
8-
directory: "/"
9-
schedule:
10-
interval: daily
3+
- package-ecosystem: pip
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
- package-ecosystem: github-actions
8+
directory: "/"
9+
schedule:
10+
interval: daily

.github/workflows/release.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
name: Release
2-
32
on:
43
release:
54
types: [published]
65
workflow_dispatch:
7-
86
jobs:
97
pypi-build:
108
runs-on: ubuntu-latest
11-
129
steps:
1310
- uses: actions/checkout@v5
1411
- uses: actions/setup-python@v6
@@ -20,14 +17,12 @@ jobs:
2017
with:
2118
name: release-dists
2219
path: dist/
23-
2420
pypi-publish:
2521
runs-on: ubuntu-latest
2622
needs:
2723
- pypi-build
2824
permissions:
2925
id-token: write
30-
3126
steps:
3227
- uses: actions/download-artifact@v6
3328
with:

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and are ready to adopt in your project :)
3030
from django.db import models
3131
from pictures.models import PictureField
3232

33+
3334
class Profile(models.Model):
3435
title = models.CharField(max_length=255)
3536
picture = PictureField(upload_to="avatars")
@@ -77,7 +78,7 @@ python3 -m pip install django-pictures
7778
# settings.py
7879
INSTALLED_APPS = [
7980
# ...
80-
'pictures',
81+
"pictures",
8182
]
8283

8384
# the following are defaults, but you can override them
@@ -96,7 +97,6 @@ PICTURES = {
9697
"USE_PLACEHOLDERS": True,
9798
"QUEUE_NAME": "pictures",
9899
"PROCESSOR": "pictures.tasks.process_picture",
99-
100100
}
101101
```
102102

@@ -155,8 +155,8 @@ from pictures.models import PictureField
155155
class Profile(models.Model):
156156
title = models.CharField(max_length=255)
157157
picture = PictureField(
158-
upload_to="avatars",
159-
aspect_ratios=[None, "1/1", "3/2", "16/9"],
158+
upload_to="avatars",
159+
aspect_ratios=[None, "1/1", "3/2", "16/9"],
160160
)
161161
```
162162

@@ -263,6 +263,7 @@ available picture sizes in a DRF serializer.
263263
from rest_framework import serializers
264264
from pictures.contrib.rest_framework import PictureField
265265

266+
266267
class PictureSerializer(serializers.Serializer):
267268
picture = PictureField()
268269
```
@@ -274,6 +275,7 @@ providing the `aspect_ratios` and `file_types` arguments to the DRF field.
274275
from rest_framework import serializers
275276
from pictures.contrib.rest_framework import PictureField
276277

278+
277279
class PictureSerializer(serializers.Serializer):
278280
picture = PictureField(aspect_ratios=["16/9"], file_types=["AVIF"])
279281
```
@@ -366,5 +368,4 @@ class MyPicture(Picture):
366368
[django-rq]: https://github.com/rq/django-rq
367369
[dramatiq]: https://dramatiq.io/
368370
[drf]: https://www.django-rest-framework.org/
369-
[libavif-install]: https://pillow.readthedocs.io/en/latest/installation/building-from-source.html#external-libraries
370371
[migration]: tests/testapp/migrations/0002_alter_profile_picture.py

pictures/migrations.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Type
2-
31
from django.db import models
42
from django.db.migrations import AlterField
53
from django.db.models import Q
@@ -28,7 +26,7 @@ def database_backwards(self, app_label, schema_editor, from_state, to_state):
2826
self.alter_picture_field(from_model, to_model)
2927

3028
def alter_picture_field(
31-
self, from_model: Type[models.Model], to_model: Type[models.Model]
29+
self, from_model: type[models.Model], to_model: type[models.Model]
3230
):
3331
from_field = from_model._meta.get_field(self.name)
3432
to_field = to_model._meta.get_field(self.name)
@@ -46,7 +44,7 @@ def alter_picture_field(
4644
):
4745
self.update_pictures(from_field, to_model)
4846

49-
def update_pictures(self, from_field: PictureField, to_model: Type[models.Model]):
47+
def update_pictures(self, from_field: PictureField, to_model: type[models.Model]):
5048
"""Remove obsolete pictures and create new ones."""
5149
for obj in to_model._default_manager.exclude(
5250
Q(**{self.name: ""}) | Q(**{self.name: None})
@@ -57,13 +55,13 @@ def update_pictures(self, from_field: PictureField, to_model: Type[models.Model]
5755
)
5856
new_field_file.update_all(old_field_file)
5957

60-
def from_picture_field(self, from_model: Type[models.Model]):
58+
def from_picture_field(self, from_model: type[models.Model]):
6159
for obj in from_model._default_manager.all().iterator():
6260
field_file = getattr(obj, self.name)
6361
field_file.delete_all()
6462

6563
def to_picture_field(
66-
self, from_model: Type[models.Model], to_model: Type[models.Model]
64+
self, from_model: type[models.Model], to_model: type[models.Model]
6765
):
6866
from_field = from_model._meta.get_field(self.name)
6967
if hasattr(from_field.attr_class, "delete_variations"):

pictures/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def url(self) -> str:
9292
def height(self) -> int | None:
9393
if self.aspect_ratio:
9494
return math.floor(self.width / self.aspect_ratio)
95+
return None
9596

9697
@property
9798
def name(self) -> str:
@@ -129,7 +130,6 @@ def delete(self):
129130

130131

131132
class PictureFieldFile(ImageFieldFile):
132-
133133
def __xor__(self, other) -> tuple[set[Picture], set[Picture]]:
134134
"""Return the new and obsolete :class:`Picture` instances."""
135135
if not isinstance(other, PictureFieldFile):
@@ -176,7 +176,7 @@ def update_all(self, other: PictureFieldFile | None = None):
176176
@property
177177
def width(self):
178178
self._require_file()
179-
if self._committed and self.field.width_field:
179+
if self._committed and self.field.width_field: # NoQA SIM102
180180
if width := getattr(self.instance, self.field.width_field, None):
181181
# get width from width field, to avoid loading image
182182
return width
@@ -185,7 +185,7 @@ def width(self):
185185
@property
186186
def height(self):
187187
self._require_file()
188-
if self._committed and self.field.height_field:
188+
if self._committed and self.field.height_field: # NoQA SIM102
189189
if height := getattr(self.instance, self.field.height_field, None):
190190
# get height from height field, to avoid loading image
191191
return height

pictures/tasks.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def noop(*args, **kwargs) -> None:
1313

1414

1515
class PictureProcessor(Protocol):
16-
1716
def __call__(
1817
self,
1918
storage: tuple[str, list, dict],
@@ -33,11 +32,10 @@ def _process_picture(
3332
old = old or []
3433
storage = utils.reconstruct(*storage)
3534
if new:
36-
with storage.open(file_name) as fs:
37-
with Image.open(fs) as img:
38-
for picture in new:
39-
picture = utils.reconstruct(*picture)
40-
picture.save(img)
35+
with storage.open(file_name) as fs, Image.open(fs) as img:
36+
for picture in new:
37+
picture = utils.reconstruct(*picture)
38+
picture.save(img)
4139

4240
for picture in old:
4341
picture = utils.reconstruct(*picture)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{% for name, value in attrs.items %}{% if value is not False %} {{ name }}{% if value is not True %}="{{ value|stringformat:'s' }}"{% endif %}{% endif %}{% endfor %}
1+
{% for name, value in attrs.items %}{% if value is not False %} {{ name }}{% if value is not True %}="{{ value|stringformat:'s' }}"{% endif %}{% endif %}{% endfor %}

pictures/templatetags/pictures.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,16 @@ def picture(field_file, img_alt=None, ratio=None, container=None, **kwargs):
3838
img_attrs[key[4:]] = value
3939
else:
4040
raise TypeError(f"Invalid keyword argument: {key}")
41-
return tmpl.render(
42-
{
43-
"field_file": field_file,
44-
"alt": img_alt,
45-
"ratio": (ratio or "3/2").replace("/", "x"),
46-
"sources": sources,
47-
"media": utils.sizes(field=field, container_width=container, **breakpoints),
48-
"picture_attrs": picture_attrs,
49-
"img_attrs": img_attrs,
50-
"use_placeholders": settings.USE_PLACEHOLDERS,
51-
}
52-
)
41+
return tmpl.render({
42+
"field_file": field_file,
43+
"alt": img_alt,
44+
"ratio": (ratio or "3/2").replace("/", "x"),
45+
"sources": sources,
46+
"media": utils.sizes(field=field, container_width=container, **breakpoints),
47+
"picture_attrs": picture_attrs,
48+
"img_attrs": img_attrs,
49+
"use_placeholders": settings.USE_PLACEHOLDERS,
50+
})
5351

5452

5553
@register.simple_tag()

pictures/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def source_set(
7979

8080
@lru_cache
8181
def placeholder(width: int, height: int, alt):
82-
hue = random.randint(0, 360) # nosec
82+
hue = random.randint(0, 360) # NoQA S311
8383
img = Image.new("RGB", (width, height), color=f"hsl({hue}, 40%, 80%)")
8484
draw = ImageDraw.Draw(img)
8585
draw.line(((0, 0, width, height)), width=3, fill=f"hsl({hue}, 60%, 20%)")

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def large_image_upload_file():
3535
return SimpleUploadedFile("image.png", output.getvalue())
3636

3737

38-
@pytest.fixture(autouse=True, scope="function")
38+
@pytest.fixture(autouse=True)
3939
def media_root(settings, tmpdir_factory):
4040
settings.MEDIA_ROOT = tmpdir_factory.mktemp("media", numbered=True)
4141

@@ -45,7 +45,7 @@ def instant_commit(monkeypatch):
4545
monkeypatch.setattr("django.db.transaction.on_commit", lambda f: f())
4646

4747

48-
@pytest.fixture()
48+
@pytest.fixture
4949
def stub_worker():
5050
try:
5151
import dramatiq

0 commit comments

Comments
 (0)