diff options
| author | Mathieu Pillard <mpillard@mozilla.com> | 2022-04-23 12:19:10 +0200 |
|---|---|---|
| committer | Mathieu Pillard <mpillard@mozilla.com> | 2022-04-23 12:19:10 +0200 |
| commit | 2961561b9b8bf43d48d190776db9e097548ab0a5 (patch) | |
| tree | 1d9cc8c6aaca13a19e096192ad5f359eba786d1c /compressor | |
| parent | eadb2f553d131b5bb8fff17dfe38f127b367c616 (diff) | |
| parent | 3be5bf6bae72acaca1defcf18c53ac49aadb52cb (diff) | |
| download | django-compressor-4.0.tar.gz | |
Merge branch 'develop'4.0
Diffstat (limited to 'compressor')
| -rw-r--r-- | compressor/__init__.py | 2 | ||||
| -rw-r--r-- | compressor/filters/jsmin/__init__.py | 17 | ||||
| -rw-r--r-- | compressor/storage.py | 17 | ||||
| -rw-r--r-- | compressor/tests/test_filters.py | 3 | ||||
| -rw-r--r-- | compressor/tests/test_storages.py | 6 |
5 files changed, 32 insertions, 13 deletions
diff --git a/compressor/__init__.py b/compressor/__init__.py index a4702e2..7f21c2d 100644 --- a/compressor/__init__.py +++ b/compressor/__init__.py @@ -1,2 +1,2 @@ # following PEP 386 -__version__ = "3.1" +__version__ = "4.0" diff --git a/compressor/filters/jsmin/__init__.py b/compressor/filters/jsmin/__init__.py index 3a2aade..c1a64cf 100644 --- a/compressor/filters/jsmin/__init__.py +++ b/compressor/filters/jsmin/__init__.py @@ -1,3 +1,5 @@ +import warnings + from django.core.exceptions import ImproperlyConfigured from compressor.filters import FilterBase, CallbackOutputFilter @@ -6,9 +8,7 @@ from compressor.filters import FilterBase, CallbackOutputFilter class rJSMinFilter(CallbackOutputFilter): callback = "rjsmin.jsmin" dependencies = ["rjsmin"] - kwargs = { - "keep_bang_comments": True - } + kwargs = {"keep_bang_comments": True} # This is for backwards compatibility @@ -22,6 +22,14 @@ class SlimItFilter(CallbackOutputFilter): "mangle": True, } + def __init__(self, *args, **kwargs): + warnings.warn( + "SlimItFilter is broken in Python 3.6+ and will be removed in " + "django-compressor 3.3.", + DeprecationWarning, + ) + super().__init__(*args, **kwargs) + class CalmjsFilter(FilterBase): def __init__(self, *args, **kwargs): @@ -39,7 +47,8 @@ class CalmjsFilter(FilterBase): except ImportError: raise ImproperlyConfigured( "The module calmjs.parse couldn't be imported. " - "Make sure it is correctly installed.") + "Make sure it is correctly installed." + ) if self._parser is None: self._parser = calmjs.parse.es5 if self._unparser is None: diff --git a/compressor/storage.py b/compressor/storage.py index a9d7a0c..5d12eb8 100644 --- a/compressor/storage.py +++ b/compressor/storage.py @@ -33,13 +33,16 @@ class CompressorFileStorage(FileSystemStorage): def modified_time(self, name): return datetime.fromtimestamp(os.path.getmtime(self.path(name))) - def get_available_name(self, name, max_length=None): - """ - Deletes the given file if it exists. - """ - if self.exists(name): - self.delete(name) - return name + def save(self, filename, content): + temp_filename = super().save(filename, content) + # If a file already exists in the target location, FileSystemStorage + # will generate an unique filename and save content there instead. + # When that happens, we move the file to the intended location using + # os.replace() (which is an atomic operation): + if temp_filename != filename: + os.replace(self.path(temp_filename), self.path(filename)) + + return filename compressor_file_storage = SimpleLazyObject( diff --git a/compressor/tests/test_filters.py b/compressor/tests/test_filters.py index 49716b7..ddcfab0 100644 --- a/compressor/tests/test_filters.py +++ b/compressor/tests/test_filters.py @@ -2,7 +2,7 @@ import io import os import sys from collections import defaultdict -from unittest import mock +from unittest import mock, skipIf from django.conf import settings from django.test import override_settings, TestCase @@ -202,6 +202,7 @@ class JsMinTestCase(TestCase): self.assertEqual(output, rJSMinFilter(content).output()) +@skipIf(sys.version_info >= (3, 7), reason="Unsupported in Python 3.7+") class SlimItTestCase(TestCase): def test_slimit_filter(self): content = """ diff --git a/compressor/tests/test_storages.py b/compressor/tests/test_storages.py index 8a99e45..9168510 100644 --- a/compressor/tests/test_storages.py +++ b/compressor/tests/test_storages.py @@ -61,3 +61,9 @@ class StorageTestCase(TestCase): context = {'STATIC_URL': settings.COMPRESS_URL} out = css_tag("/static/CACHE/css/output.e701f86c6430.css") self.assertEqual(out, render(template, context)) + + def test_duplicate_save_overwrites_same_file(self): + filename1 = self.default_storage.save('test.txt', ContentFile('yeah yeah')) + filename2 = self.default_storage.save('test.txt', ContentFile('yeah yeah')) + self.assertEqual(filename1, filename2) + self.assertNotIn("_", filename2) |
