Skip to content

Different behaviour when reading from filename vs string #393

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

Closed
adamlwgriffiths opened this issue Jun 10, 2022 · 1 comment
Closed

Different behaviour when reading from filename vs string #393

adamlwgriffiths opened this issue Jun 10, 2022 · 1 comment

Comments

@adamlwgriffiths
Copy link

Using compile(string='<sass content>') I get the following error: Invalid CSS after ""

But if I put that same SASS into a file and load it, the error disappears.
The output below describes this issue.

In [4]: sass.compile(filename='server/style.sass')
Out[4]: 'a b {\n  color: blue; }\n'

In [5]: x = '''
   ...: a
   ...:   b
   ...:     color: blue
   ...: '''

In [6]: sass.compile(string=x)
---------------------------------------------------------------------------
CompileError                              Traceback (most recent call last)
<ipython-input-6-030bbd1c42f9> in <module>
----> 1 sass.compile(string=x)

/nix/store/p5qcpw0b0y290wdkw4dxwrs6c0m9nzk0-python3-3.9.9-env/lib/python3.9/site-packages/sass.py in compile(**kwargs)
    736         raise TypeError('something went wrong')
    737     assert not s
--> 738     raise CompileError(v)
    739 
    740 

CompileError: Error: Invalid CSS after "": expected 1 selector or at-rule, was "a"
        on line 1:1 of stdin
>> 

   ^


In [7]: with open('server/style.sass', 'r') as f:
   ...:     print(f.read())
   ...: 
a
  b
    color: blue

In [8]: sass.__version__
Out[8]: '0.21.0'
@adamlwgriffiths
Copy link
Author

adamlwgriffiths commented Jun 10, 2022

The front page doesn't mention this, but I delved into stackoverflow and found a post stating that you must pass indented=True to compile.

This really should be on the front page, especially as the way the flask-style docs are generated, it's not obvious how to actually get to the API docs.
There's no API on the table of contents.

image

It's hidden down under "Module Index".
This is below about 40 different version links

image

Then external references, licensing, credits, and finally, Indices and Tables (which again doesn't say the words API).

image

The only reason I found this was because I noticed a large docstring for the compile function, but nothing I could see in the documentation.

I suggest:
Adding mention of the indented keyword being required for SASS passes as strings to the examples.
Providing links to the API in the left column rather than just external references. I'm using this library. References are not relevant.
Providing links to the API higher up that page. Anything after version information is generally superfluous.

Preferably the SASS/SCSS distinction would be automatically detected and this argument would not be required.
The code could re-try with indented=True and print a warning to the user.
Or the error could suggest trying indented=True if they didn't specify it and the error appears to be related to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants