如何使用python webassets编译Bootstrap 4 scss?

时间:2018-03-18 02:36:49

标签: python sass

我试图用python webassets简单地编译Bootstrap 4并且没有成功。现在我只想尝试在bootstrap / scss目录中执行此操作,因此路径问题不是什么大问题。在这个目录中,我添加了一行main.scss文件:

@import "bootstrap.scss";

我有一个名为test_scss.py的脚本,如下所示:

from webassets import Bundle, Environment
my_env = Environment(directory='.', url='/')
css = Bundle('main.scss', filters='scss', output='all.css')
my_env.register('css_all', css)
print(my_env['css_all'].urls())

当我运行此命令时,我得到如下错误跟踪:

Traceback (most recent call last):
  File "./test_scss.py", line 11, in <module>
    print(my_env['css_all'].urls())
  File "/Users/benlindsay/miniconda/lib/python3.6/site-packages/webassets/bundle.py", line 806, in urls
    urls.extend(bundle._urls(new_ctx, extra_filters, *args, **kwargs))
  File "/Users/benlindsay/miniconda/lib/python3.6/site-packages/webassets/bundle.py", line 765, in _urls
    *args, **kwargs)
  File "/Users/benlindsay/miniconda/lib/python3.6/site-packages/webassets/bundle.py", line 619, in _build
    force, disable_cache=disable_cache, extra_filters=extra_filters)
  File "/Users/benlindsay/miniconda/lib/python3.6/site-packages/webassets/bundle.py", line 543, in _merge_and_apply
    kwargs=item_data)
  File "/Users/benlindsay/miniconda/lib/python3.6/site-packages/webassets/merge.py", line 276, in apply
    return self._wrap_cache(key, func)
  File "/Users/benlindsay/miniconda/lib/python3.6/site-packages/webassets/merge.py", line 218, in _wrap_cache
    content = func().getvalue()
  File "/Users/benlindsay/miniconda/lib/python3.6/site-packages/webassets/merge.py", line 251, in func
    getattr(filter, type)(data, out, **kwargs_final)
  File "/Users/benlindsay/miniconda/lib/python3.6/site-packages/webassets/filter/sass.py", line 196, in input
    self._apply_sass(_in, out, os.path.dirname(source_path))
  File "/Users/benlindsay/miniconda/lib/python3.6/site-packages/webassets/filter/sass.py", line 190, in _apply_sass
    return self.subprocess(args, out, _in, cwd=child_cwd)
  File "/Users/benlindsay/miniconda/lib/python3.6/site-packages/webassets/filter/__init__.py", line 527, in subprocess
    proc.returncode, stdout, stderr))
webassets.exceptions.FilterError: scss: subprocess returned a non-success result code: 65, stdout=b'',
stderr=b'DEPRECATION WARNING: Importing from the current working directory will
not be automatic in future versions of Sass.  To avoid future errors, you can add it
to your environment explicitly by setting `SASS_PATH=.`, by using the -I command
line option, or by changing your Sass configuration options.

Error: Invalid CSS after "...lor}: #{$value}": expected "{", was ";"
        on line 4 of /Users/benlindsay/scratch/python/webassets/test-2/bootstrap/scss/_root.scss
        from line 11 of /Users/benlindsay/scratch/python/webassets/test-2/bootstrap/scss/bootstrap.scss
        from line 1 of standard input
  Use --trace for backtrace.

如果我按照说明设置环境变量SASS_PATH=.,那就摆脱了错误信息的那一部分,但我仍然得到错误

Error: Invalid CSS after "...lor}: #{$value}": expected "{", was ";"
        on line 4 of /Users/benlindsay/scratch/python/webassets/test-2/bootstrap/scss/_root.scss
        from line 11 of /Users/benlindsay/scratch/python/webassets/test-2/bootstrap/scss/bootstrap.scss
        from line 1 of standard input
  Use --trace for backtrace.

我还不太了解SCSS语法,但我打赌要花很多钱,这是我做错了,而不是Bootstrap SCSS中的错误。任何关于我做错事的想法都将不胜感激。

1 个答案:

答案 0 :(得分:0)

事实证明它实际上是Bootstrap结束时的一个问题。请参阅https://nodogmablog.bryanhogan.net/2017/11/unit-testing-entity-framework-core-stored-procedures/,特别是引用:

  

这是我们实现中的一个错误 - 解析器不应该崩溃 - 但是这些Bootstrap样式对于编写的Sass 3.5无效。

无论如何,我只需要更新到最新版本的Ruby Sass(显然是webassets模块所依赖的)并修复它。