diff options
| author | Jannis Leidel <jannis@leidel.info> | 2011-09-06 14:11:37 +0200 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2011-09-06 14:11:37 +0200 |
| commit | 70cc7aa351e187513c650dcbc03ebefb84edf3b1 (patch) | |
| tree | 729d7af4127bd18be8c524d78c3923c6425eba1b | |
| parent | f57e495991708851d332e9c2500ae4f27ad61d91 (diff) | |
| download | django-compressor-70cc7aa351e187513c650dcbc03ebefb84edf3b1.tar.gz | |
Import settings from compressor.conf again instead of django.conf to make sure they are loaded correctly.
| -rw-r--r-- | compressor/base.py | 2 | ||||
| -rw-r--r-- | compressor/cache.py | 2 | ||||
| -rw-r--r-- | compressor/conf.py | 118 | ||||
| -rw-r--r-- | compressor/css.py | 3 | ||||
| -rw-r--r-- | compressor/filters/base.py | 2 | ||||
| -rw-r--r-- | compressor/filters/closure.py | 3 | ||||
| -rw-r--r-- | compressor/filters/css_default.py | 3 | ||||
| -rw-r--r-- | compressor/filters/csstidy.py | 3 | ||||
| -rw-r--r-- | compressor/filters/datauri.py | 3 | ||||
| -rw-r--r-- | compressor/filters/yui.py | 3 | ||||
| -rw-r--r-- | compressor/js.py | 3 | ||||
| -rw-r--r-- | compressor/management/commands/compress.py | 2 | ||||
| -rw-r--r-- | compressor/management/commands/mtime_cache.py | 2 | ||||
| -rw-r--r-- | compressor/models.py | 118 | ||||
| -rw-r--r-- | compressor/storage.py | 3 | ||||
| -rw-r--r-- | compressor/templatetags/compress.py | 2 | ||||
| -rw-r--r-- | compressor/utils/staticfiles.py | 11 | ||||
| -rw-r--r-- | tests/tests/base.py | 2 | ||||
| -rw-r--r-- | tests/tests/filters.py | 2 | ||||
| -rw-r--r-- | tests/tests/offline.py | 2 | ||||
| -rw-r--r-- | tests/tests/parsers.py | 3 | ||||
| -rw-r--r-- | tests/tests/storages.py | 2 | ||||
| -rw-r--r-- | tests/tests/templatetags.py | 4 |
23 files changed, 145 insertions, 153 deletions
diff --git a/compressor/base.py b/compressor/base.py index 4aff5ed..2c11a6a 100644 --- a/compressor/base.py +++ b/compressor/base.py @@ -2,7 +2,6 @@ from __future__ import with_statement import os import codecs -from django.conf import settings from django.core.files.base import ContentFile from django.template import Context from django.template.loader import render_to_string @@ -10,6 +9,7 @@ from django.utils.encoding import smart_unicode from compressor.cache import get_hexdigest, get_mtime +from compressor.conf import settings from compressor.exceptions import CompressorError, UncompressableFileError from compressor.filters import CompilerFilter from compressor.storage import default_storage diff --git a/compressor/cache.py b/compressor/cache.py index 170ce0a..d629497 100644 --- a/compressor/cache.py +++ b/compressor/cache.py @@ -2,13 +2,13 @@ import os import socket import time -from django.conf import settings from django.core.cache import get_cache from django.utils.encoding import smart_str from django.utils.functional import SimpleLazyObject from django.utils.hashcompat import md5_constructor from django.utils.importlib import import_module +from compressor.conf import settings from compressor.utils import get_mod_func _cachekey_func = None diff --git a/compressor/conf.py b/compressor/conf.py new file mode 100644 index 0000000..ee1b9be --- /dev/null +++ b/compressor/conf.py @@ -0,0 +1,118 @@ +import os +from django import VERSION as DJANGO_VERSION +from django.conf import settings +from django.core.exceptions import ImproperlyConfigured + +from appconf import AppConf + + +class CompressorConf(AppConf): + # Main switch + ENABLED = False + # Allows changing verbosity from the settings. + VERBOSE = False + # GET variable that disables compressor e.g. "nocompress" + DEBUG_TOGGLE = "None" + # the backend to use when parsing the JavaScript or Stylesheet files + PARSER = 'compressor.parser.AutoSelectParser' + OUTPUT_DIR = 'CACHE' + STORAGE = 'compressor.storage.CompressorFileStorage' + + CSS_COMPRESSOR = "compressor.css.CssCompressor" + JS_COMPRESSOR = "compressor.js.JsCompressor" + + URL = None + ROOT = None + + CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter'] + CSS_HASHING_METHOD = 'mtime' + + JS_FILTERS = ['compressor.filters.jsmin.JSMinFilter'] + PRECOMPILERS = ( + # ('text/coffeescript', 'coffee --compile --stdio'), + # ('text/less', 'lessc {infile} {outfile}'), + # ('text/x-sass', 'sass {infile} {outfile}'), + # ('text/x-scss', 'sass --scss {infile} {outfile}'), + ) + CLOSURE_COMPILER_BINARY = 'java -jar compiler.jar' + CLOSURE_COMPILER_ARGUMENTS = '' + CSSTIDY_BINARY = 'csstidy' + CSSTIDY_ARGUMENTS = '--template=highest' + YUI_BINARY = 'java -jar yuicompressor.jar' + YUI_CSS_ARGUMENTS = '' + YUI_JS_ARGUMENTS = '' + DATA_URI_MAX_SIZE = 1024 + + # the cache backend to use + CACHE_BACKEND = None + # the dotted path to the function that creates the cache key + CACHE_KEY_FUNCTION = 'compressor.cache.simple_cachekey' + # rebuilds the cache every 30 days if nothing has changed. + REBUILD_TIMEOUT = 60 * 60 * 24 * 30 # 30 days + # the upper bound on how long any compression should take to be generated + # (used against dog piling, should be a lot smaller than REBUILD_TIMEOUT + MINT_DELAY = 30 # seconds + # check for file changes only after a delay + MTIME_DELAY = 10 # seconds + # enables the offline cache -- also filled by the compress command + OFFLINE = False + # invalidates the offline cache after one year + OFFLINE_TIMEOUT = 60 * 60 * 24 * 365 # 1 year + # The context to be used when compressing the files "offline" + OFFLINE_CONTEXT = {} + + class Meta: + prefix = 'compress' + + def configure_enabled(self, value): + return value or not settings.DEBUG + + def configure_root(self, value): + if value is None: + value = getattr(settings, 'STATIC_ROOT', None) + if not value: + value = settings.MEDIA_ROOT + if not value: + raise ImproperlyConfigured( + "The COMPRESS_ROOT setting must be set.") + return os.path.normcase(os.path.abspath(value)) + + def configure_url(self, value): + # Uses Django 1.3's STATIC_URL by default or falls back to MEDIA_URL + if value is None: + value = getattr(settings, "STATIC_URL", None) + if not value: + value = settings.MEDIA_URL + if not value.endswith("/"): + raise ImproperlyConfigured("The URL settings (e.g. COMPRESS_URL) " + "must have a trailing slash.") + return value + + def configure_cache_backend(self, value): + if value is None: + # If we are on Django 1.3 AND using the new CACHES setting... + if DJANGO_VERSION[:2] >= (1, 3) and hasattr(settings, "CACHES"): + value = "default" + else: + # falling back to the old CACHE_BACKEND setting + value = getattr(settings, "CACHE_BACKEND", None) + if not value: + raise ImproperlyConfigured( + "Please specify a cache backend in your settings.") + return value + + def configure_offline_context(self, value): + if not value: + value = { + "MEDIA_URL": settings.MEDIA_URL, + } + # Adds the 1.3 STATIC_URL setting to the context if available + if getattr(settings, "STATIC_URL", None): + value["STATIC_URL"] = settings.STATIC_URL + return value + + def configure_precompilers(self, value): + if not isinstance(value, (list, tuple)): + raise ImproperlyConfigured("The COMPRESS_PRECOMPILERS setting " + "must be a list or tuple. Check for missing commas.") + return value diff --git a/compressor/css.py b/compressor/css.py index 3bbda22..641ff46 100644 --- a/compressor/css.py +++ b/compressor/css.py @@ -1,6 +1,5 @@ -from django.conf import settings - from compressor.base import Compressor, SOURCE_HUNK, SOURCE_FILE +from compressor.conf import settings from compressor.exceptions import UncompressableFileError diff --git a/compressor/filters/base.py b/compressor/filters/base.py index 4ec476c..51c7940 100644 --- a/compressor/filters/base.py +++ b/compressor/filters/base.py @@ -3,11 +3,11 @@ import os import logging import subprocess import tempfile -from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.core.files.temp import NamedTemporaryFile from django.utils.importlib import import_module +from compressor.conf import settings from compressor.exceptions import FilterError from compressor.utils import get_mod_func from compressor.utils.stringformat import FormattableString as fstr diff --git a/compressor/filters/closure.py b/compressor/filters/closure.py index e0ee65a..d229bcb 100644 --- a/compressor/filters/closure.py +++ b/compressor/filters/closure.py @@ -1,5 +1,4 @@ -from django.conf import settings - +from compressor.conf import settings from compressor.filters import CompilerFilter diff --git a/compressor/filters/css_default.py b/compressor/filters/css_default.py index c77cfb9..6f2ffb9 100644 --- a/compressor/filters/css_default.py +++ b/compressor/filters/css_default.py @@ -2,9 +2,8 @@ import os import re import posixpath -from django.conf import settings - from compressor.cache import get_hexdigest, get_hashed_mtime +from compressor.conf import settings from compressor.filters import FilterBase from compressor.utils import staticfiles diff --git a/compressor/filters/csstidy.py b/compressor/filters/csstidy.py index 5ab0d9b..4b7e4c7 100644 --- a/compressor/filters/csstidy.py +++ b/compressor/filters/csstidy.py @@ -1,5 +1,4 @@ -from django.conf import settings - +from compressor.conf import settings from compressor.filters import CompilerFilter diff --git a/compressor/filters/datauri.py b/compressor/filters/datauri.py index ca6f706..9425d72 100644 --- a/compressor/filters/datauri.py +++ b/compressor/filters/datauri.py @@ -3,8 +3,7 @@ import re import mimetypes from base64 import b64encode -from django.conf import settings - +from compressor.conf import settings from compressor.filters import FilterBase diff --git a/compressor/filters/yui.py b/compressor/filters/yui.py index cf34099..60fd1f7 100644 --- a/compressor/filters/yui.py +++ b/compressor/filters/yui.py @@ -1,5 +1,4 @@ -from django.conf import settings - +from compressor.conf import settings from compressor.filters import CompilerFilter diff --git a/compressor/js.py b/compressor/js.py index bf4c7c4..20d556d 100644 --- a/compressor/js.py +++ b/compressor/js.py @@ -1,5 +1,4 @@ -from django.conf import settings - +from compressor.conf import settings from compressor.base import Compressor, SOURCE_HUNK, SOURCE_FILE from compressor.exceptions import UncompressableFileError diff --git a/compressor/management/commands/compress.py b/compressor/management/commands/compress.py index 552809e..86e27e6 100644 --- a/compressor/management/commands/compress.py +++ b/compressor/management/commands/compress.py @@ -9,7 +9,6 @@ try: except ImportError: from StringIO import StringIO -from django.conf import settings from django.core.management.base import NoArgsCommand, CommandError from django.template import Context, Template, TemplateDoesNotExist, TemplateSyntaxError from django.utils.datastructures import SortedDict @@ -23,6 +22,7 @@ except ImportError: CachedLoader = None from compressor.cache import cache, get_offline_cachekey +from compressor.conf import settings from compressor.exceptions import OfflineGenerationError from compressor.templatetags.compress import CompressorNode from compressor.utils import walk, any diff --git a/compressor/management/commands/mtime_cache.py b/compressor/management/commands/mtime_cache.py index e9d80b2..4362c2e 100644 --- a/compressor/management/commands/mtime_cache.py +++ b/compressor/management/commands/mtime_cache.py @@ -2,9 +2,9 @@ import fnmatch import os from optparse import make_option -from django.conf import settings from django.core.management.base import NoArgsCommand, CommandError +from compressor.conf import settings from compressor.cache import cache, get_mtime, get_mtime_cachekey from compressor.utils import walk diff --git a/compressor/models.py b/compressor/models.py index ee1b9be..e69de29 100644 --- a/compressor/models.py +++ b/compressor/models.py @@ -1,118 +0,0 @@ -import os -from django import VERSION as DJANGO_VERSION -from django.conf import settings -from django.core.exceptions import ImproperlyConfigured - -from appconf import AppConf - - -class CompressorConf(AppConf): - # Main switch - ENABLED = False - # Allows changing verbosity from the settings. - VERBOSE = False - # GET variable that disables compressor e.g. "nocompress" - DEBUG_TOGGLE = "None" - # the backend to use when parsing the JavaScript or Stylesheet files - PARSER = 'compressor.parser.AutoSelectParser' - OUTPUT_DIR = 'CACHE' - STORAGE = 'compressor.storage.CompressorFileStorage' - - CSS_COMPRESSOR = "compressor.css.CssCompressor" - JS_COMPRESSOR = "compressor.js.JsCompressor" - - URL = None - ROOT = None - - CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter'] - CSS_HASHING_METHOD = 'mtime' - - JS_FILTERS = ['compressor.filters.jsmin.JSMinFilter'] - PRECOMPILERS = ( - # ('text/coffeescript', 'coffee --compile --stdio'), - # ('text/less', 'lessc {infile} {outfile}'), - # ('text/x-sass', 'sass {infile} {outfile}'), - # ('text/x-scss', 'sass --scss {infile} {outfile}'), - ) - CLOSURE_COMPILER_BINARY = 'java -jar compiler.jar' - CLOSURE_COMPILER_ARGUMENTS = '' - CSSTIDY_BINARY = 'csstidy' - CSSTIDY_ARGUMENTS = '--template=highest' - YUI_BINARY = 'java -jar yuicompressor.jar' - YUI_CSS_ARGUMENTS = '' - YUI_JS_ARGUMENTS = '' - DATA_URI_MAX_SIZE = 1024 - - # the cache backend to use - CACHE_BACKEND = None - # the dotted path to the function that creates the cache key - CACHE_KEY_FUNCTION = 'compressor.cache.simple_cachekey' - # rebuilds the cache every 30 days if nothing has changed. - REBUILD_TIMEOUT = 60 * 60 * 24 * 30 # 30 days - # the upper bound on how long any compression should take to be generated - # (used against dog piling, should be a lot smaller than REBUILD_TIMEOUT - MINT_DELAY = 30 # seconds - # check for file changes only after a delay - MTIME_DELAY = 10 # seconds - # enables the offline cache -- also filled by the compress command - OFFLINE = False - # invalidates the offline cache after one year - OFFLINE_TIMEOUT = 60 * 60 * 24 * 365 # 1 year - # The context to be used when compressing the files "offline" - OFFLINE_CONTEXT = {} - - class Meta: - prefix = 'compress' - - def configure_enabled(self, value): - return value or not settings.DEBUG - - def configure_root(self, value): - if value is None: - value = getattr(settings, 'STATIC_ROOT', None) - if not value: - value = settings.MEDIA_ROOT - if not value: - raise ImproperlyConfigured( - "The COMPRESS_ROOT setting must be set.") - return os.path.normcase(os.path.abspath(value)) - - def configure_url(self, value): - # Uses Django 1.3's STATIC_URL by default or falls back to MEDIA_URL - if value is None: - value = getattr(settings, "STATIC_URL", None) - if not value: - value = settings.MEDIA_URL - if not value.endswith("/"): - raise ImproperlyConfigured("The URL settings (e.g. COMPRESS_URL) " - "must have a trailing slash.") - return value - - def configure_cache_backend(self, value): - if value is None: - # If we are on Django 1.3 AND using the new CACHES setting... - if DJANGO_VERSION[:2] >= (1, 3) and hasattr(settings, "CACHES"): - value = "default" - else: - # falling back to the old CACHE_BACKEND setting - value = getattr(settings, "CACHE_BACKEND", None) - if not value: - raise ImproperlyConfigured( - "Please specify a cache backend in your settings.") - return value - - def configure_offline_context(self, value): - if not value: - value = { - "MEDIA_URL": settings.MEDIA_URL, - } - # Adds the 1.3 STATIC_URL setting to the context if available - if getattr(settings, "STATIC_URL", None): - value["STATIC_URL"] = settings.STATIC_URL - return value - - def configure_precompilers(self, value): - if not isinstance(value, (list, tuple)): - raise ImproperlyConfigured("The COMPRESS_PRECOMPILERS setting " - "must be a list or tuple. Check for missing commas.") - return value diff --git a/compressor/storage.py b/compressor/storage.py index 5d895bb..a8cfac1 100644 --- a/compressor/storage.py +++ b/compressor/storage.py @@ -2,10 +2,11 @@ import gzip from os import path from datetime import datetime -from django.conf import settings from django.core.files.storage import FileSystemStorage, get_storage_class from django.utils.functional import LazyObject +from compressor.conf import settings + class CompressorFileStorage(FileSystemStorage): """ diff --git a/compressor/templatetags/compress.py b/compressor/templatetags/compress.py index a92d595..3ce1350 100644 --- a/compressor/templatetags/compress.py +++ b/compressor/templatetags/compress.py @@ -1,9 +1,9 @@ from django import template -from django.conf import settings from django.core.exceptions import ImproperlyConfigured from compressor.cache import (cache, cache_get, cache_set, get_offline_cachekey, get_templatetag_cachekey) +from compressor.conf import settings from compressor.utils import get_class register = template.Library() diff --git a/compressor/utils/staticfiles.py b/compressor/utils/staticfiles.py index 1bf8f71..0bc4d0e 100644 --- a/compressor/utils/staticfiles.py +++ b/compressor/utils/staticfiles.py @@ -1,22 +1,21 @@ from __future__ import absolute_import -from django.conf import settings as django_settings from django.core.exceptions import ImproperlyConfigured -INSTALLED = ("staticfiles" in django_settings.INSTALLED_APPS or - "django.contrib.staticfiles" in django_settings.INSTALLED_APPS) +from compressor.conf import settings + +INSTALLED = ("staticfiles" in settings.INSTALLED_APPS or + "django.contrib.staticfiles" in settings.INSTALLED_APPS) finders = None settings = None if INSTALLED: - if "django.contrib.staticfiles" in django_settings.INSTALLED_APPS: + if "django.contrib.staticfiles" in settings.INSTALLED_APPS: from django.contrib.staticfiles import finders - settings = django_settings else: try: from staticfiles import finders - from staticfiles.conf import settings except ImportError: # Old (pre 1.0) and incompatible version of staticfiles INSTALLED = False diff --git a/tests/tests/base.py b/tests/tests/base.py index 228d6f9..7ec94f9 100644 --- a/tests/tests/base.py +++ b/tests/tests/base.py @@ -4,11 +4,11 @@ import re from BeautifulSoup import BeautifulSoup -from django.conf import settings from django.core.cache.backends import locmem from django.test import TestCase from compressor.base import SOURCE_HUNK, SOURCE_FILE +from compressor.conf import settings from compressor.css import CssCompressor from compressor.js import JsCompressor diff --git a/tests/tests/filters.py b/tests/tests/filters.py index 5ef0644..f6cf287 100644 --- a/tests/tests/filters.py +++ b/tests/tests/filters.py @@ -3,10 +3,10 @@ import os import sys from unittest2 import skipIf -from django.conf import settings from django.test import TestCase from compressor.cache import get_hashed_mtime +from compressor.conf import settings from compressor.css import CssCompressor from compressor.utils import find_command from compressor.filters.base import CompilerFilter diff --git a/tests/tests/offline.py b/tests/tests/offline.py index 6f6492a..903e15b 100644 --- a/tests/tests/offline.py +++ b/tests/tests/offline.py @@ -1,10 +1,10 @@ from __future__ import with_statement import os -from django.conf import settings from django.template import Template, Context from django.test import TestCase +from compressor.conf import settings from compressor.management.commands.compress import Command as CompressCommand from .base import test_dir, css_tag diff --git a/tests/tests/parsers.py b/tests/tests/parsers.py index e76a447..de6a0b3 100644 --- a/tests/tests/parsers.py +++ b/tests/tests/parsers.py @@ -18,9 +18,8 @@ except ImportError: BeautifulSoup = None -from django.conf import settings - from compressor.base import SOURCE_HUNK, SOURCE_FILE +from compressor.conf import settings from .base import CompressorTestCase diff --git a/tests/tests/storages.py b/tests/tests/storages.py index d7dae0a..7311bae 100644 --- a/tests/tests/storages.py +++ b/tests/tests/storages.py @@ -1,10 +1,10 @@ from __future__ import with_statement -from django.conf import settings from django.core.files.storage import get_storage_class from django.test import TestCase from compressor import base +from compressor.conf import settings from .base import css_tag from .templatetags import render diff --git a/tests/tests/templatetags.py b/tests/tests/templatetags.py index 7b3fd5d..e52baeb 100644 --- a/tests/tests/templatetags.py +++ b/tests/tests/templatetags.py @@ -1,11 +1,11 @@ from __future__ import with_statement -from django.conf import settings from django.template import Template, Context, TemplateSyntaxError from django.test import TestCase -from .base import css_tag +from compressor.conf import settings +from .base import css_tag def render(template_string, context_dict=None): """ |
