From c255c0988ee6e155fc19f001791ce5f620f61ff8 Mon Sep 17 00:00:00 2001 From: Jacob Rief Date: Wed, 18 Jan 2023 14:53:35 +0100 Subject: [PATCH 1/6] update license file --- LICENSE-MIT | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE-MIT b/LICENSE-MIT index 6eb7629..c114e30 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Jacob Rief +Copyright (c) 2015-2023 Jacob Rief Copyright (c) 2021 Dominik George Permission is hereby granted, free of charge, to any person obtaining a copy From 57f8264571d2dec319a5b3f57f8e72185a7a2735 Mon Sep 17 00:00:00 2001 From: Jacob Rief Date: Thu, 19 Jan 2023 09:57:48 +0100 Subject: [PATCH 2/6] revert processor to version 1.2.1 --- sass_processor/processor.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sass_processor/processor.py b/sass_processor/processor.py index a8f6b83..e725199 100644 --- a/sass_processor/processor.py +++ b/sass_processor/processor.py @@ -6,6 +6,7 @@ from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.core.files.base import ContentFile +from django.core.files.storage import get_storage_class from django.template import Context from django.utils.encoding import force_bytes @@ -24,6 +25,7 @@ class SassProcessor: source_storage = SassFileStorage() + delivery_storage = get_storage_class(settings.STATICFILES_STORAGE)() include_paths = [str(ip) for ip in getattr(settings, 'SASS_PROCESSOR_INCLUDE_DIRS', [])] try: sass_precision = int(settings.SASS_PRECISION) @@ -140,7 +142,10 @@ def is_latest(self, sourcemap_file, base): @classmethod def handle_simple(cls, path): - return cls.source_storage.url(path) + try: + return cls.delivery_storage.url(path) + except ValueError: + return cls.source_storage.url(path) _sass_processor = SassProcessor() From 2fe02f6ca52b8b2f741a3fecda4f2ca842319828 Mon Sep 17 00:00:00 2001 From: Jacob Rief Date: Thu, 19 Jan 2023 14:02:03 +0100 Subject: [PATCH 3/6] add repr method to LazyObject --- sass_processor/storage.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sass_processor/storage.py b/sass_processor/storage.py index 8c13def..deaa908 100644 --- a/sass_processor/storage.py +++ b/sass_processor/storage.py @@ -16,6 +16,9 @@ def _setup(self): self._wrapped = storage_class(**storage_options) + def __repr__(self): + return repr(self._wrapped) + def find_file(path): for finder in get_finders(): From 53558f0ddf46fb8f91dc9f78ab476fbc8c38c4f8 Mon Sep 17 00:00:00 2001 From: Jacob Rief Date: Thu, 19 Jan 2023 14:02:53 +0100 Subject: [PATCH 4/6] use pathlib.Path for setup during tests --- tests/settings.py | 13 ++++++------ tests/test_sass_processor.py | 40 ++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/tests/settings.py b/tests/settings.py index 56b1322..3345674 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,4 +1,4 @@ -import os +from pathlib import Path from tests.jinja2 import environment @@ -13,6 +13,8 @@ } } +PROJECT_ROOT = Path(__file__).parent + INSTALLED_APPS = [ 'django.contrib.contenttypes', 'django.contrib.sites', @@ -64,8 +66,6 @@ STATIC_URL = '/static/' -PROJECT_ROOT = os.path.abspath(os.path.join(__file__, os.path.pardir)) - STATICFILES_FINDERS = [ 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', @@ -73,9 +73,11 @@ ] STATICFILES_DIRS = [ - os.path.join(PROJECT_ROOT, 'static'), + PROJECT_ROOT / 'static', ] +STATIC_ROOT = PROJECT_ROOT / 'tmpstatic' + SASS_PROCESSOR_ENABLED = True SASS_PROCESSOR_CUSTOM_FUNCTIONS = { @@ -85,6 +87,3 @@ } SASS_BLUE_COLOR = '#0000ff' - - -STATIC_ROOT = os.path.join(os.path.dirname(__file__), "tmpstatic") diff --git a/tests/test_sass_processor.py b/tests/test_sass_processor.py index 1d38e6b..5c9c047 100644 --- a/tests/test_sass_processor.py +++ b/tests/test_sass_processor.py @@ -28,30 +28,30 @@ def assert_sass_src_engine(self, template_name, engine): ) # Strip the line breaks. template_content = template.render({}).strip() - self.assertEqual('/static/tests/css/main.css', template_content) + assert template_content == '/static/tests/css/main.css' - css_file = os.path.join(settings.STATIC_ROOT, 'tests/css/main.css') - self.assertTrue(os.path.exists(css_file)) - with open(css_file, 'r') as f: + css_file = settings.STATIC_ROOT / 'tests/css/main.css' + assert css_file.exists() + with css_file.open('r') as f: output = f.read() expected = "#main p{color:#00ff00;width:97%}#main p .redbox{background-color:#ff0000}#main p .redbox:hover{color:#000000}\n\n/*# sourceMappingURL=main.css.map */" - self.assertEqual(expected, output) + assert expected == output # check if compilation is skipped file for a second invocation of `sass_src` - timestamp = os.path.getmtime(css_file) + timestamp = css_file.stat().st_mtime template.render({}) - self.assertEqual(timestamp, os.path.getmtime(css_file)) + assert timestamp == css_file.stat().st_mtime # removing `main.css.map` should trigger a recompilation - os.remove(css_file + '.map') + css_file.with_suffix(css_file.suffix + '.map').unlink() template.render({}) - self.assertTrue(os.path.exists(css_file + '.map')) + assert css_file.with_suffix(css_file.suffix + '.map').exists() # if `main.scss` is newer than `main.css`, recompile everything longago = calendar.timegm(datetime(2017, 1, 1).timetuple()) os.utime(css_file, (longago, longago)) template.render({}) - self.assertGreater(timestamp, os.path.getmtime(css_file)) + assert timestamp > css_file.stat().st_mtime def test_sass_src_django(self): self.assert_sass_src_engine( @@ -76,12 +76,12 @@ def test_sass_processor(self): css_file = sass_processor('tests/css/bluebox.scss') self.assertEqual('/static/tests/css/bluebox.css', css_file) - css_file = os.path.join(settings.STATIC_ROOT, 'tests/css/bluebox.css') - self.assertTrue(os.path.exists(css_file)) - with open(css_file, 'r') as f: + css_file = settings.STATIC_ROOT / 'tests/css/bluebox.css' + assert css_file.exists() + with css_file.open('r') as f: output = f.read() expected = '.bluebox{background-color:#0000ff;margin:10.0px 5.0px 20.0px 15.0px;color:#fa0a78}\n\n/*# sourceMappingURL=bluebox.css.map */' - self.assertEqual(expected, output) + assert expected == output def assert_management_command(self, **kwargs): call_command( @@ -89,18 +89,18 @@ def assert_management_command(self, **kwargs): **kwargs ) if kwargs.get('use_storage', False): - css_file = os.path.join(settings.STATIC_ROOT, 'tests/css/main.css') + css_file = settings.STATIC_ROOT / 'tests/css/main.css' else: - css_file = os.path.join(settings.PROJECT_ROOT, 'static/tests/css/main.css') - with open(css_file, 'r') as f: + css_file = settings.PROJECT_ROOT / 'static/tests/css/main.css' + with css_file.open('r') as f: output = f.read() expected = '#main p{color:#00ff00;width:97%}#main p .redbox{background-color:#ff0000}#main p .redbox:hover{color:#000000}\n' - self.assertEqual(expected, output) - self.assertFalse(os.path.exists(css_file + '.map')) + assert expected == output + assert not css_file.with_suffix(css_file.suffix + '.map').exists() if not kwargs.get('use_storage', False): call_command('compilescss', delete_files=True) - self.assertFalse(os.path.exists(css_file)) + assert not css_file.exists() @override_settings(DEBUG=False) def test_management_command_django(self): From 184a700a2cd8b10a3f335525bd3949ad50b2dd11 Mon Sep 17 00:00:00 2001 From: Jacob Rief Date: Thu, 19 Jan 2023 14:03:43 +0100 Subject: [PATCH 5/6] test if manifest static files storage works --- tests/test_sass_processor.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_sass_processor.py b/tests/test_sass_processor.py index 5c9c047..5551cf9 100644 --- a/tests/test_sass_processor.py +++ b/tests/test_sass_processor.py @@ -140,3 +140,26 @@ def test_use_storage_multiple(self): engine=['jinja2', 'django'], use_storage=True ) + + @override_settings( + DEBUG=False, + SASS_PROCESSOR_STORAGE='django.contrib.staticfiles.storage.StaticFilesStorage', + STATICFILES_STORAGE='django.contrib.staticfiles.storage.ManifestStaticFilesStorage', + ) + def test_manifest_static_files_storage(self): + css_file = settings.PROJECT_ROOT / 'static/tests/css/main.css' + assert not css_file.exists() + call_command('compilescss', use_storage=False) + assert css_file.exists() + with css_file.open('r') as f: + output = f.read() + expected = '#main p{color:#00ff00;width:97%}#main p .redbox{background-color:#ff0000}#main p .redbox:hover{color:#000000}\n' + assert expected == output + hashed_css_file = settings.PROJECT_ROOT / 'tmpstatic/tests/css/main.08b498e281f7.css' + assert not hashed_css_file.exists() + call_command('collectstatic', interactive=False, ignore_patterns=['*.scss']) + assert hashed_css_file.exists() + with hashed_css_file.open('r') as f: + output = f.read() + assert expected == output + call_command('compilescss', use_storage=False, delete_files=True) From 176464ac879bad5f97d9adc01be055c1d812cd7d Mon Sep 17 00:00:00 2001 From: Jacob Rief Date: Tue, 23 May 2023 13:05:58 +0200 Subject: [PATCH 6/6] fix versioning problem --- setup.cfg | 1 - setup.py | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index ca7c44d..64b9876 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,5 @@ [metadata] name = django-sass-processor -version = attr: sass_processor.__version__ description = SASS processor to compile SCSS files into *.css, while rendering, or offline. long_description = file: README.md long_description_content_type = text/markdown diff --git a/setup.py b/setup.py index c823345..a361fd4 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,7 @@ #!/usr/bin/env python from setuptools import setup +from sass_processor import __version__ -setup() +setup( + version=__version__, +)