Skip to content

Commit 22d8ff8

Browse files
authored
Merge pull request #147 from kevinmarsh/support-django-32-to-41
Drop support for deprecated Django versions <3.2 and add support for Django 4.1
2 parents 1a6a191 + 3b640ed commit 22d8ff8

File tree

5 files changed

+34
-50
lines changed

5 files changed

+34
-50
lines changed

.github/workflows/python-package.yml

+13-25
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,20 @@ jobs:
1313
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}
1414
strategy:
1515
matrix:
16-
python-version: [3.6, 3.7, 3.8, 3.9, '3.10']
16+
python-version:
17+
- '3.7'
18+
- '3.8'
19+
- '3.9'
20+
- '3.10'
1721
django-version:
18-
- '>=4.0a1,<4.1'
19-
- '>=3.2,<4.0'
20-
- '>=3.1,<3.2'
21-
- '>=3.0,<3.1'
22-
- '>=2.2,<3.0'
23-
- '>=2.1,<2.2'
24-
- '>=2.0,<2.1'
22+
- '3.2'
23+
- '4.0'
24+
- '4.1'
2525
exclude:
26-
- python-version: 3.6
27-
django-version: '>=4.0a1,<4.1'
28-
- python-version: 3.7
29-
django-version: '>=4.0a1,<4.1'
30-
- python-version: '3.10'
31-
django-version: '>=3.2,<4.0'
32-
- python-version: '3.10'
33-
django-version: '>=3.1,<3.2'
34-
- python-version: '3.10'
35-
django-version: '>=3.0,<3.1'
36-
- python-version: '3.10'
37-
django-version: '>=2.2,<3.0'
38-
- python-version: '3.10'
39-
django-version: '>=2.1,<2.2'
40-
- python-version: '3.10'
41-
django-version: '>=2.0,<2.1'
26+
- python-version: '3.7'
27+
django-version: '4.0'
28+
- python-version: '3.7'
29+
django-version: '4.1'
4230
steps:
4331
- uses: actions/checkout@v2
4432
- name: Set up Python ${{ matrix.python-version }}
@@ -48,7 +36,7 @@ jobs:
4836
- name: Install dependencies (Django ${{ matrix.django-version }})
4937
run: |
5038
python -m pip install --upgrade pip
51-
python -m pip install --pre django'${{ matrix.django-version }}'
39+
python -m pip install --pre Django~='${{ matrix.django-version }}'
5240
python -m pip install flake8 coverage requests pytz -e .
5341
- name: Lint with flake8
5442
run: |

django_s3_storage/management/commands/s3_sync_meta.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import unicode_literals
21
from django.core.management.base import BaseCommand, CommandError
32
from django.utils.module_loading import import_string
43

@@ -8,7 +7,7 @@ class Command(BaseCommand):
87
help = "Syncronizes the meta information on S3 files."
98

109
def add_arguments(self, parser):
11-
super(Command, self).add_arguments(parser)
10+
super().add_arguments(parser)
1211
parser.add_argument(
1312
"storage_path",
1413
metavar="storage_path",
@@ -20,13 +19,13 @@ def handle(self, **kwargs):
2019
verbosity = int(kwargs.get("verbosity", 1))
2120
for storage_path in kwargs["storage_path"]:
2221
if verbosity >= 1:
23-
self.stdout.write("Syncing meta for {}".format(storage_path))
22+
self.stdout.write(f"Syncing meta for {storage_path}")
2423
# Import the storage.
2524
try:
2625
storage = import_string(storage_path)
2726
except ImportError:
28-
raise CommandError("Could not import {}".format(storage_path))
27+
raise CommandError(f"Could not import {storage_path}")
2928
# Sync the meta.
3029
for path in storage.sync_meta_iter():
3130
if verbosity >= 1:
32-
self.stdout.write(" Synced meta for {}".format(path))
31+
self.stdout.write(f" Synced meta for {path}")

django_s3_storage/storage.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import unicode_literals
2-
31
import gzip
42
import logging
53
import mimetypes
@@ -41,7 +39,7 @@ def _do_wrap_errors(self, name, *args, **kwargs):
4139
err_cls = OSError
4240
if code == "NoSuchKey":
4341
err_cls = FileNotFoundError
44-
raise err_cls("S3Storage error at {!r}: {}".format(name, force_str(ex)))
42+
raise err_cls(f"S3Storage error at {name!r}: {force_str(ex)}")
4543
return _do_wrap_errors
4644

4745

@@ -84,13 +82,13 @@ class S3File(File):
8482
"""
8583

8684
def __init__(self, file, name, storage):
87-
super(S3File, self).__init__(file, name)
85+
super().__init__(file, name)
8886
self._storage = storage
8987

9088
def open(self, mode="rb"):
9189
if self.closed:
9290
self.file = self._storage.open(self.name, mode).file
93-
return super(S3File, self).open(mode)
91+
return super().open(mode)
9492

9593

9694
class _Local(local):
@@ -209,14 +207,14 @@ def __init__(self, **kwargs):
209207
kwarg_key.upper() not in self.default_auth_settings and
210208
kwarg_key.upper() not in self.default_s3_settings
211209
):
212-
raise ImproperlyConfigured("Unknown S3Storage parameter: {}".format(kwarg_key))
210+
raise ImproperlyConfigured(f"Unknown S3Storage parameter: {kwarg_key}")
213211
# Set up the storage.
214212
self._kwargs = kwargs
215213
self._setup()
216214
# Re-initialize the storage if an AWS setting changes.
217215
setting_changed.connect(self._setting_changed_received)
218216
# All done!
219-
super(S3Storage, self).__init__()
217+
super().__init__()
220218

221219
def __reduce__(self):
222220
return unpickle_helper, (self.__class__, self._kwargs)
@@ -326,7 +324,7 @@ def _save(self, name, content):
326324
temp_file.seek(0)
327325
content = temp_file
328326
put_params["ContentEncoding"] = "gzip"
329-
put_params["Metadata"][_UNCOMPRESSED_SIZE_META_KEY] = "{:d}".format(orig_size)
327+
put_params["Metadata"][_UNCOMPRESSED_SIZE_META_KEY] = f"{orig_size:d}"
330328
else:
331329
content.seek(0)
332330
# Save the file.
@@ -350,17 +348,17 @@ def _save(self, name, content):
350348

351349
@_wrap_path_impl
352350
def get_valid_name(self, name):
353-
return super(S3Storage, self).get_valid_name(name)
351+
return super().get_valid_name(name)
354352

355353
@_wrap_path_impl
356354
def get_available_name(self, name, max_length=None):
357355
if self.settings.AWS_S3_FILE_OVERWRITE:
358356
return _to_posix_path(name)
359-
return super(S3Storage, self).get_available_name(name, max_length=max_length)
357+
return super().get_available_name(name, max_length=max_length)
360358

361359
@_wrap_path_impl
362360
def generate_filename(self, filename):
363-
return super(S3Storage, self).generate_filename(filename)
361+
return super().generate_filename(filename)
364362

365363
@_wrap_errors
366364
def meta(self, name):
@@ -537,7 +535,6 @@ def post_process(self, *args, **kwargs):
537535
initial_aws_s3_max_age_seconds = self.settings.AWS_S3_MAX_AGE_SECONDS
538536
self.settings.AWS_S3_MAX_AGE_SECONDS = self.settings.AWS_S3_MAX_AGE_SECONDS_CACHED
539537
try:
540-
for r in super(ManifestStaticS3Storage, self).post_process(*args, **kwargs):
541-
yield r
538+
yield from super().post_process(*args, **kwargs)
542539
finally:
543540
self.settings.AWS_S3_MAX_AGE_SECONDS = initial_aws_s3_max_age_seconds

setup.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
url="https://github.com/etianen/django-s3-storage",
1717
packages=find_packages(),
1818
install_requires=[
19-
"django>=1.11",
19+
"django>=3.2",
2020
"boto3>=1.4.4,<2",
2121
],
2222
classifiers=[
@@ -26,10 +26,13 @@
2626
"License :: OSI Approved :: BSD License",
2727
"Operating System :: OS Independent",
2828
"Programming Language :: Python",
29-
"Programming Language :: Python :: 3.6",
3029
"Programming Language :: Python :: 3.7",
3130
"Programming Language :: Python :: 3.8",
3231
"Programming Language :: Python :: 3.9",
32+
"Programming Language :: Python :: 3.10",
3333
"Framework :: Django",
34+
'Framework :: Django :: 3.2',
35+
'Framework :: Django :: 4.0',
36+
'Framework :: Django :: 4.1',
3437
],
3538
)

tests/django_s3_storage_test/tests.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# coding=utf-8
2-
from __future__ import unicode_literals
3-
41
import posixpath
52
import time
63
from contextlib import contextmanager
@@ -246,7 +243,7 @@ def testSyncMeta(self):
246243
with self.settings(
247244
AWS_S3_BUCKET_AUTH=False,
248245
AWS_S3_MAX_AGE_SECONDS=9999,
249-
AWS_S3_CONTENT_DISPOSITION=lambda name: "attachment; filename={}".format(name),
246+
AWS_S3_CONTENT_DISPOSITION=lambda name: f"attachment; filename={name}",
250247
AWS_S3_CONTENT_LANGUAGE="eo",
251248
AWS_S3_METADATA={
252249
"foo": "bar",
@@ -291,7 +288,7 @@ def testSyncMetaWithGzip(self):
291288
with self.settings(
292289
AWS_S3_BUCKET_AUTH=False,
293290
AWS_S3_MAX_AGE_SECONDS=9999,
294-
AWS_S3_CONTENT_DISPOSITION=lambda name: "attachment; filename={}".format(name),
291+
AWS_S3_CONTENT_DISPOSITION=lambda name: f"attachment; filename={name}",
295292
AWS_S3_CONTENT_LANGUAGE="eo",
296293
AWS_S3_METADATA={
297294
"foo": "bar",

0 commit comments

Comments
 (0)