Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow filters to provide paths for "depends" #240

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions src/webassets/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,31 @@ def _set_depends(self, value):
rebuild is required.
""")

def resolve_depends(self, ctx):
def resolve_depends(self, ctx, refresh=False):
# TODO: Caching is as problematic here as it is in resolve_contents().
if not self.depends:
return []
if getattr(self, '_resolved_depends', None) is None:
if getattr(self, '_resolved_depends', None) is None or refresh:
resolved = []
for item in self.depends:
try:
result = ctx.resolver.resolve_source(ctx, item)
except IOError as e:
raise BundleError(e)
if not isinstance(result, list):
result = [result]
resolved.extend(result)
for filter_ in self.filters:
# get dependencies from filter
if hasattr(filter_, "find_dependencies"):
filter_deps = filter_.find_dependencies()
filter_hash = (filter_,"deps")
if filter_deps is None:
# if not yet resolved, load from cache
filter_deps = ctx.cache.get(filter_hash) if ctx.cache else []
elif ctx.cache:
ctx.cache.set(filter_hash, filter_deps)
if filter_deps:
resolved.extend(filter_deps)
if self.depends:
for item in self.depends:
try:
result = ctx.resolver.resolve_source(ctx, item)
except IOError as e:
raise BundleError(e)
if not isinstance(result, list):
result = [result]
resolved.extend(result)
self._resolved_depends = resolved
return self._resolved_depends

Expand Down Expand Up @@ -551,7 +562,13 @@ def _merge_and_apply(self, ctx, output, force, parent_debug=None,
# it even required to consider them here with respect to the cache? We
# might be able to run this operation with the cache on (the FilterTool
# being possibly configured with cache reads off).
return filtertool.apply(final, selected_filters, 'output')
ret = filtertool.apply(final, selected_filters, 'output')

# Resolve deps second time and after building - in case filter
# didn't know them before.
self.resolve_depends(ctx, True)

return ret

def _build(self, ctx, extra_filters=None, force=None, output=None,
disable_cache=None):
Expand Down
7 changes: 7 additions & 0 deletions src/webassets/filter/pyscss.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from webassets.filter import Filter
from webassets.utils import working_directory
import os


__all__ = ('PyScss',)
Expand Down Expand Up @@ -73,6 +74,10 @@ class PyScss(Filter):
'assets_url': 'PYSCSS_ASSETS_URL',
}
max_debug_level = None
depends = None

def find_dependencies(self):
return self.depends

def setup(self):
super(PyScss, self).setup()
Expand Down Expand Up @@ -136,3 +141,5 @@ def input(self, _in, out, **kw):
# to stdout, via logging. We might have to do something about
# this, and evaluate such problems to an exception.
out.write(scss.compile())

self.depends = list(os.path.join(f.parent_dir, f.filename) for f in scss.source_files)