Kronuz / pyScss

pyScss, a Scss compiler for Python
MIT License
582 stars 141 forks source link

Compass linear-gradient causes error when used with svg #292

Closed sjdemartini closed 10 years ago

sjdemartini commented 10 years ago

The following fails to process properly. Looks like the Sass List isn't being created properly when the first argument is the position, maybe? (Note that this used to work; the file parses fine with pyscss version 1.1.3.)

@import "compass/css3";
div {
    @include background-image(linear-gradient(top, #1F9CCA 0%, #2072B0 100%));
}   
Traceback (most recent call last):
  File "/Users/sjd/Envs/env_newpyscss/bin/pyscss", line 9, in <module>
    load_entry_point('pyScss==1.2.0.post3', 'console_scripts', 'pyscss')()
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/tool.py", line 149, in main
    do_build(options, args)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/tool.py", line 176, in do_build
    output.write(css.compile(scss_file=path, is_sass=options.is_sass))
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 438, in compile
    return self.Compilation(*args, **kwargs)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 396, in Compilation
    self.parse_children()
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/util.py", line 111, in wrapper
    return func(*args, **kwargs)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 489, in parse_children
    self.manage_children(rule, scope)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/util.py", line 111, in wrapper
    return func(*args, **kwargs)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 498, in manage_children
    self._manage_children_impl(rule, scope)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 596, in _manage_children_impl
    self._nest_rules(rule, scope, block)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/util.py", line 111, in wrapper
    return func(*args, **kwargs)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 1310, in _nest_rules
    self.manage_children(new_rule, scope)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/util.py", line 111, in wrapper
    return func(*args, **kwargs)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 498, in manage_children
    self._manage_children_impl(rule, scope)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 561, in _manage_children_impl
    self._do_include(rule, scope, block)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/util.py", line 111, in wrapper
    return func(*args, **kwargs)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 832, in _do_include
    self.manage_children(_rule, scope)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/util.py", line 111, in wrapper
    return func(*args, **kwargs)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 498, in manage_children
    self._manage_children_impl(rule, scope)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 565, in _manage_children_impl
    self._do_if(rule, scope, block)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/util.py", line 111, in wrapper
    return func(*args, **kwargs)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 1042, in _do_if
    self.manage_children(inner_rule, scope)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/util.py", line 111, in wrapper
    return func(*args, **kwargs)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 498, in manage_children
    self._manage_children_impl(rule, scope)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 583, in _manage_children_impl
    self._get_properties(rule, scope, block)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/util.py", line 111, in wrapper
    return func(*args, **kwargs)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/__init__.py", line 1212, in _get_properties
    value = calculator.calculate(raw_value)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/expression.py", line 104, in calculate
    better_expr_str = self.evaluate_expression(better_expr_str, divide=divide)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/expression.py", line 132, in evaluate_expression
    raise SassEvaluationError(e, expression=expr)
scss.errors.SassEvaluationError: Error evaluating expression:
    -svg($images)

...

Traceback:
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/expression.py", line 130, in evaluate_expression
    return ast.evaluate(self, divide=divide)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/expression.py", line 314, in evaluate
    ret = funct(*args, **kwargs)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/functions/compass/helpers.py", line 187, in dash_svg
    return prefix('_svg', *args)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/functions/compass/helpers.py", line 168, in prefix
    _value.append(to_fnct())
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/functions/compass/gradients.py", line 328, in to__svg
    return linear_svg_gradient(color_stops, position_and_angle or 'top')
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/functions/compass/gradients.py", line 353, in linear_svg_gradient
    args = List.from_maybe_starargs(args)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/types.py", line 616, in from_maybe_starargs
    return cls(args, use_comma=use_comma)
  File "/Users/sjd/Envs/env_newpyscss/lib/python2.7/site-packages/scss/types.py", line 563, in __init__
    raise TypeError("Expected a Sass type, got %r" % (item,))
TypeError: Expected a Sass type, got [(<Number(0.0%)>, <Color((31.0, 156.0, 202.0, 1.0))>), (<Number(100.0%)>, <Color((32.0, 114.0, 176.0, 1.0))>)]
eevee commented 10 years ago

It doesn't crash any more, but I have no idea if it works correctly — our Compass gradient stuff is very dense and not very well defined or tested :(

sjdemartini commented 10 years ago

Ah okay. Well thanks for looking into it and fixing the crash!

simpoir commented 10 years ago

I had the same problem which I traced back to this commit 028b73079c221f97f7ff1a9537a88279b8c0b098

There seems to be a return statement that disappeared on line extension/compass/gradients.py:25

Change

 list(args[0])

to

return list(arg[0])

and it already works better

eevee commented 10 years ago

@simpoir whoops, fixed that, thanks! I should be making a point release today or tomorrow.

I'm gonna close this, but feel free to open new issues for further problems. Eventually I hope to make the Compass support a little more well-defined and well-tested.