Browse files

Added --no-cache option to build command.

  • Loading branch information...
1 parent 661a0f8 commit c9a2e7bd58164ca07cbf8bd919f0268aa911a22f @miracle2k committed Feb 11, 2012
Showing with 30 additions and 12 deletions.
  1. +0 −2 TODO
  2. +7 −5 src/webassets/bundle.py
  3. +12 −4 src/webassets/script.py
  4. +11 −1 tests/test_script.py
View
2 TODO
@@ -1,8 +1,6 @@
There is currently no locking going during auto-rebuilds, that is multiple
requests could potentially cause multiple builds!
-Add a switch to the rebuild() command to ignore the cache.
-
Should bundle names be namespacable, similar to Django urls? At the least,
we probably want to encourage a convention of prefixing your bundle names
with an id. Everything else would just intend to make this easier or more
View
12 src/webassets/bundle.py
@@ -344,7 +344,8 @@ def _merge_and_apply(self, env, output_path, force, parent_debug=None,
return apply_filters(final, filters, 'output',
env.cache, actually_skip_cache_here)
- def _build(self, env, extra_filters=[], force=None, output=None):
+ def _build(self, env, extra_filters=[], force=None, output=None,
+ disable_cache=None):
"""Internal bundle build function.
This actually tries to build this very bundle instance, as
@@ -384,7 +385,6 @@ def _build(self, env, extra_filters=[], force=None, output=None):
# Determine if we really need to build, or if the output file
# already exists and nothing has changed.
- disable_cache = None
if force:
update_needed = True
elif not env.updater:
@@ -402,7 +402,8 @@ def _build(self, env, extra_filters=[], force=None, output=None):
# _merge_and_apply() is now smart enough to do without
# this disable_cache hint, but for now, keep passing it
# along if we get the info from the updater.
- disable_cache = update_needed==SKIP_CACHE
+ if update_needed==SKIP_CACHE:
+ disable_cache = True
else:
update_needed = False
@@ -432,7 +433,7 @@ def _build(self, env, extra_filters=[], force=None, output=None):
return hunk
- def build(self, env=None, force=None, output=None):
+ def build(self, env=None, force=None, output=None, disable_cache=None):
"""Build this bundle, meaning create the file given by the
``output`` attribute, applying the configured filters etc.
@@ -454,7 +455,8 @@ def build(self, env=None, force=None, output=None):
hunks = []
for bundle, extra_filters in self.iterbuild(env):
hunks.append(bundle._build(
- env, extra_filters, force=force, output=output))
+ env, extra_filters, force=force, output=output,
+ disable_cache=disable_cache))
return hunks
def iterbuild(self, env=None):
View
16 src/webassets/script.py
@@ -55,7 +55,7 @@ def rebuild(self):
ImminentDeprecationWarning)
return self.build()
- def build(self, bundles=None, output=None, directory=None):
+ def build(self, bundles=None, output=None, directory=None, no_cache=None):
"""Build/Rebuild assets.
``bundles``
@@ -73,6 +73,9 @@ def build(self, bundles=None, output=None, directory=None):
used. If the ``output`` of the bundles are pointing to different
directories, they will be offset by their common prefix.
Cannot be used with ``output``.
+
+ ``no_cache``
+ If set, a cache (if one is configured) will not be used.
"""
if self.environment.debug != False:
self.log.warning(
@@ -151,7 +154,8 @@ def build(self, bundles=None, output=None, directory=None):
try:
if not overwrite_filename:
- bundle.build(force=True, env=self.environment)
+ bundle.build(force=True, env=self.environment,
+ disable_cache=no_cache)
else:
# TODO: Rethink how we deal with container bundles here.
# As it currently stands, we write all child bundles
@@ -160,7 +164,8 @@ def build(self, bundles=None, output=None, directory=None):
# using the ``Hunk`` objects that build() would return
# anyway.
output = StringIO()
- bundle.build(force=True, env=self.environment, output=output)
+ bundle.build(force=True, env=self.environment, output=output,
+ disable_cache=no_cache)
if directory:
# Only auto-create directories in this mode.
output_dir = os.path.dirname(overwrite_filename)
@@ -215,7 +220,7 @@ def check_for_changes():
pass
def clean(self):
- """ Delete generated assets.
+ """Delete generated assets.
TODO: Clean the cache?
"""
@@ -326,6 +331,9 @@ def make_build_parser(parser):
'basename defined by the bundle. Will offset '
'the original bundle output paths on their common '
'prefix. Cannot be used with --output.')
+ parser.add_argument(
+ '--no-cache', action='store_true',
+ help='Do not use a cache that might be configured.')
def run_with_argv(self, argv):
try:
View
12 tests/test_script.py
@@ -20,7 +20,7 @@ class MockBundle(Bundle):
build_called = False
on_build = None
def _build(self, *a, **kw):
- self.build_called = True
+ self.build_called = (True, a, kw)
self.on_build(*a, **kw) if self.on_build else None
@@ -107,3 +107,13 @@ def test_custom_directory_not_supported_for_container_bundles(self):
self.assets_env.add(b)
assert_raises(CommandError, self.cmd_env.build,
directory=self.path('some/path'))
+
+ def test_no_cache(self):
+ """Test the no_cache option."""
+ a = MockBundle(output='a')
+ self.assets_env.register('a', a)
+ self.cmd_env.build(no_cache=True)
+ assert a.build_called[2].get('disable_cache') == True
+
+ self.cmd_env.build(no_cache=False)
+ assert a.build_called[2].get('disable_cache') == False

0 comments on commit c9a2e7b

Please sign in to comment.