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

support custom import extension #246

Merged
merged 4 commits into from
Apr 24, 2018

Conversation

samuelcolvin
Copy link
Contributor

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests -- really stellar work there 👍

Just a few little things

We should also add an argument to pysassc so this can be done from the cli. Probably action='append'

sass.py Outdated
@@ -239,7 +239,7 @@ def compile_dirname(
input_filename = input_filename.encode(fs_encoding)
s, v, _ = _sass.compile_filename(
input_filename, output_style, source_comments, include_paths,
precision, None, custom_functions, importers, None,
precision, None, custom_functions, importers, None, [],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compile_dirname should probably grow this parameter as well

sass.py Outdated
@@ -584,6 +596,21 @@ def _get_file_arg(key):
'not {1!r}'.format(SassFunction, custom_functions)
)

_custom_exts = kwargs.pop('custom_import_extensions', []) or []
if isinstance(_custom_exts, (text_type, bytes)):
_custom_exts = [_custom_exts]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, not sure how I feel about a parameter which ends with s that can take a str, let's instead raise a TypeError and require an iterable of some sort

Also let's just require that they are text or ascii compatible:

custom_import_extensions = [
    ext.encode('UTF-8')
    for ext in kwargs.pop('custom_import_extensions', ())
]

sasstests.py Outdated


def test_import_no_css(tmpdir):
tmpdir.join('other.css').write('body {colour: green}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

colour, I like it heh.

sasstests.py Outdated
b'.css',
[b'.css'],
['.foobar', '.css'],
['.foobar', '.css', b'anything'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this case is unreasonable 🤷‍♂️

@samuelcolvin
Copy link
Contributor Author

Done, except I'm now concerned this is just a sticking plaster over the problem.

It currently causes the warning

Including .css files with @import is non-standard behaviour which will be removed in future versions of LibSass.
Use a custom importer to maintain this behaviour. Check your implementations documentation on how to create a custom importer.

So this change will be broken again in libsass 3.6.0.

I guess the long-term solution is for libsass-python to provide a css loader. Perhaps we should change the api now to a allow_css_imports=True/False which will be a better fit for a future css loader function rather than changing the public API multiple times?

@asottile
Copy link
Member

It currently causes the warning

From sass/libsass#2636 (comment) it seems that the warning will disappear in 3.6.0 so I think this is fine? @xzyfer can you confirm that the this approach will continue to work in 3.6.0?

@asottile
Copy link
Member

@samuelcolvin now that the dust has settled, is this good to go? if so I'll merge and make a release

@samuelcolvin
Copy link
Contributor Author

Yes, I think good to go.

@asottile asottile merged commit 2b3361d into sass:master Apr 24, 2018
@asottile
Copy link
Member

This has been released as part of 0.14.4 -- thanks again for the fix!

@samuelcolvin samuelcolvin deleted the custom_import_extensions branch April 24, 2018 19:05
@samuelcolvin
Copy link
Contributor Author

Great, I'll update my tool grablib which uses libsass extensively now.

@asottile
Copy link
Member

asottile commented Jul 2, 2018

just a heads up @samuelcolvin -- looks like upstream has backtracked on the .css import situation so we'll be backing this out as well (the option / api from our side will remain but will be a noop):

sass/libsass#2684 (comment)

@samuelcolvin
Copy link
Contributor Author

Great news. Very good news they agreed to revert this.

Do we need to do anything here?

@asottile
Copy link
Member

asottile commented Jul 2, 2018

Nope! I'll handle it next time we pull in upstream :)

note that in the next version there will be a deprecation warning and some time after that the options will be removed but no immediate action (and I'll ping you again when that's happening 🎉)

@xzyfer
Copy link
Contributor

xzyfer commented Jul 3, 2018

To summaries the plan moving forward.

It's become clear that people rely on being able to resolve .css via @import. This is especially the case in Node ecosystem due to packages stylesheets in 3rd party modules. To that point a spec is drafted for officially adding that (behaviour to the language](https://github.com/sass/language/blob/master/proposal/css-imports.md)

Specifically the behaviour we want to deprecate is the using Sass language features in .css files. In the future we will produce (de-duped) deprecation warning when we detect a Sass language feature (i.e. nesting, variables, functions, mixins, Sass tyle @imports) in .css files.

@asottile
Copy link
Member

asottile commented Jul 3, 2018

@xzyfer thanks for the great communication on 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

Successfully merging this pull request may close these issues.

Raw CSS @imports no longer work
3 participants