miracle2k / webassets

Asset management for Python web development.
BSD 2-Clause "Simplified" License
921 stars 258 forks source link

SCSS filter runs command sass without --scss #537

Open kernc opened 4 years ago

kernc commented 4 years ago

Given the following mwe SCSS file:

/* /tmp/file.scss: */
$baseFontFamily : "Droid Sans", sans-serif;

body {
  font: 14px/1.5 $baseFontFamily;
}

the following script snippet:

# webassets_bug.py:
from webassets import Bundle, Environment

bundle = Bundle('/tmp/file.scss', filters='scss', output='/tmp/out.css')
env = Environment(directory='/tmp/')
env.register('css', bundle)

print(bundle.urls())

fails with:

$ python webassets_bug.py
Traceback (most recent call last):
  File "webassets_bug.py", line 7, in <module>
    print(bundle.urls())
  File "/usr/lib/python3.7/site-packages/webassets/bundle.py", line 833, in urls
    urls.extend(bundle._urls(new_ctx, extra_filters, *args, **kwargs))
  File "/usr/lib/python3.7/site-packages/webassets/bundle.py", line 768, in _urls
    *args, **kwargs)
  File "/usr/lib/python3.7/site-packages/webassets/bundle.py", line 620, in _build
    force, disable_cache=disable_cache, extra_filters=extra_filters)
  File "/usr/lib/python3.7/site-packages/webassets/bundle.py", line 544, in _merge_and_apply
    kwargs=item_data)
  File "/usr/lib/python3.7/site-packages/webassets/merge.py", line 280, in apply
    return self._wrap_cache(key, func)
  File "/usr/lib/python3.7/site-packages/webassets/merge.py", line 222, in _wrap_cache
    content = func().getvalue()
  File "/usr/lib/python3.7/site-packages/webassets/merge.py", line 255, in func
    getattr(filter, type)(data, out, **kwargs_final)
  File "/usr/lib/python3.7/site-packages/webassets/filter/sass.py", line 148, in input
    self._apply_sass(_in, out, os.path.dirname(source_path))
  File "/usr/lib/python3.7/site-packages/webassets/filter/sass.py", line 142, in _apply_sass
    return self.subprocess(args, out, _in, cwd=child_cwd)
  File "/usr/lib/python3.7/site-packages/webassets/filter/__init__.py", line 529, in subprocess
    stderr.decode('utf-8').strip()))
webassets.exceptions.FilterError: scss: subprocess returned a non-success result code: 65, stdout=, stderr=(sass):3: Invalid CSS after "...ns", sans-serif": expected expression (e.g. 1px, bold), was ";" (Sass::SyntaxError)
    from /usr/lib/ruby/vendor_ruby/sass/scss/parser.rb:1278:in `expected'
    from /usr/lib/ruby/vendor_ruby/sass/script/lexer.rb:231:in `expected!'
    from /usr/lib/ruby/vendor_ruby/sass/script/parser.rb:762:in `assert_done'
    from /usr/lib/ruby/vendor_ruby/sass/script/parser.rb:69:in `parse'
    from /usr/lib/ruby/vendor_ruby/sass/script/parser.rb:228:in `parse'
    from /usr/lib/ruby/vendor_ruby/sass/script.rb:27:in `parse'
    from /usr/lib/ruby/vendor_ruby/sass/engine.rb:1177:in `parse_script'
    from /usr/lib/ruby/vendor_ruby/sass/engine.rb:783:in `parse_variable'
    from /usr/lib/ruby/vendor_ruby/sass/engine.rb:651:in `parse_line'
    from /usr/lib/ruby/vendor_ruby/sass/engine.rb:540:in `build_tree'
    from /usr/lib/ruby/vendor_ruby/sass/engine.rb:559:in `block in append_children'
    from /usr/lib/ruby/vendor_ruby/sass/engine.rb:558:in `each'
    from /usr/lib/ruby/vendor_ruby/sass/engine.rb:558:in `append_children'
    from /usr/lib/ruby/vendor_ruby/sass/engine.rb:417:in `_to_tree'
    from /usr/lib/ruby/vendor_ruby/sass/engine.rb:290:in `render'
    from /usr/lib/ruby/vendor_ruby/sass/exec/sass_scss.rb:396:in `run'
    from /usr/lib/ruby/vendor_ruby/sass/exec/sass_scss.rb:63:in `process_result'
    from /usr/lib/ruby/vendor_ruby/sass/exec/base.rb:52:in `parse'
    from /usr/lib/ruby/vendor_ruby/sass/exec/base.rb:19:in `parse!'
    from /usr/bin/sass:8:in `<main>'
kernc commented 4 years ago

A solution appears to be to append --scss if binary is sass and self.use_scss: https://github.com/miracle2k/webassets/blob/41ff9e57f5c872eeeb253ef6c6b1853742231a1c/src/webassets/filter/sass.py#L128-L133

kernc commented 4 years ago

The switch was once present and lost in https://github.com/miracle2k/webassets/pull/523.