Skip to content

libsass 3.5.5 #275

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

Merged
merged 1 commit into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions pysass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,17 +507,6 @@ static void _add_custom_importers(
sass_option_set_c_importers(options, importer_list);
}

static void _add_custom_import_extensions(
struct Sass_Options* options, PyObject* custom_import_extensions
) {
Py_ssize_t i;

for (i = 0; i < PyList_GET_SIZE(custom_import_extensions); i += 1) {
PyObject* ext = PyList_GET_ITEM(custom_import_extensions, i);
sass_option_push_import_extension(options, PyBytes_AS_STRING(ext));
}
}

static PyObject *
PySass_compile_string(PyObject *self, PyObject *args) {
struct Sass_Context *ctx;
Expand All @@ -529,15 +518,13 @@ PySass_compile_string(PyObject *self, PyObject *args) {
int source_comments, error_status, precision, indented;
PyObject *custom_functions;
PyObject *custom_importers;
PyObject *custom_import_extensions;
PyObject *result;

if (!PyArg_ParseTuple(args,
PySass_IF_PY3("yiiyiOiOO", "siisiOiOO"),
PySass_IF_PY3("yiiyiOiO", "siisiOiO"),
&string, &output_style, &source_comments,
&include_paths, &precision,
&custom_functions, &indented, &custom_importers,
&custom_import_extensions)) {
&custom_functions, &indented, &custom_importers)) {
return NULL;
}

Expand All @@ -550,7 +537,6 @@ PySass_compile_string(PyObject *self, PyObject *args) {
sass_option_set_is_indented_syntax_src(options, indented);
_add_custom_functions(options, custom_functions);
_add_custom_importers(options, custom_importers);
_add_custom_import_extensions(options, custom_import_extensions);
sass_compile_data_context(context);

ctx = sass_data_context_get_context(context);
Expand All @@ -576,15 +562,14 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
Sass_Output_Style output_style;
int source_comments, error_status, precision;
PyObject *source_map_filename, *custom_functions, *custom_importers,
*result, *output_filename_hint, *custom_import_extensions;
*result, *output_filename_hint;

if (!PyArg_ParseTuple(args,
PySass_IF_PY3("yiiyiOOOOO", "siisiOOOOO"),
PySass_IF_PY3("yiiyiOOOO", "siisiOOOO"),
&filename, &output_style, &source_comments,
&include_paths, &precision,
&source_map_filename, &custom_functions,
&custom_importers, &output_filename_hint,
&custom_import_extensions)) {
&custom_importers, &output_filename_hint)) {
return NULL;
}

Expand All @@ -611,7 +596,6 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
sass_option_set_precision(options, precision);
_add_custom_functions(options, custom_functions);
_add_custom_importers(options, custom_importers);
_add_custom_import_extensions(options, custom_import_extensions);
sass_compile_file_context(context);

ctx = sass_file_context_get_context(context);
Expand Down
17 changes: 9 additions & 8 deletions pysassc.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import io
import optparse
import sys
import warnings

import sass

Expand Down Expand Up @@ -105,12 +106,7 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
'--source-comments', action='store_true', default=False,
help='Include debug info in output',
)
parser.add_option(
'--import-extensions',
dest='custom_import_extensions', action='append',
help='Extra extensions allowed for sass imports. '
'Can be multiply used.',
)
parser.add_option('--import-extensions', help=optparse.SUPPRESS_HELP)
options, args = parser.parse_args(argv[1:])
error = functools.partial(
print,
Expand All @@ -134,6 +130,13 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
)
return 2

if options.import_extensions:
warnings.warn(
'`--import-extensions` has no effect and will be removed in '
'a future version.',
FutureWarning,
)

try:
if options.source_map:
source_map_filename = args[1] + '.map' # FIXME
Expand All @@ -145,7 +148,6 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
output_filename_hint=args[1],
include_paths=options.include_paths,
precision=options.precision,
custom_import_extensions=options.custom_import_extensions,
)
else:
source_map_filename = None
Expand All @@ -156,7 +158,6 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
source_comments=options.source_comments,
include_paths=options.include_paths,
precision=options.precision,
custom_import_extensions=options.custom_import_extensions,
)
except (IOError, OSError) as e:
error(e)
Expand Down
31 changes: 11 additions & 20 deletions sass.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def _raise(e):

def compile_dirname(
search_path, output_path, output_style, source_comments, include_paths,
precision, custom_functions, importers, custom_import_extensions,
precision, custom_functions, importers,
):
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
for dirpath, _, filenames in os.walk(search_path, onerror=_raise):
Expand All @@ -243,7 +243,6 @@ def compile_dirname(
s, v, _ = _sass.compile_filename(
input_filename, output_style, source_comments, include_paths,
precision, None, custom_functions, importers, None,
custom_import_extensions,
)
if s:
v = v.decode('UTF-8')
Expand Down Expand Up @@ -296,9 +295,7 @@ def compile(**kwargs):
:type custom_functions: :class:`set`,
:class:`collections.abc.Sequence`,
:class:`collections.abc.Mapping`
:param custom_import_extensions: optional extra file extensions which
allow can be imported, eg. ``['.css']``
:type custom_import_extensions: :class:`list`, :class:`tuple`
:param custom_import_extensions: (ignored, for backward compatibility)
:param indented: optional declaration that the string is Sass, not SCSS
formatted. :const:`False` by default
:type indented: :class:`bool`
Expand Down Expand Up @@ -339,9 +336,7 @@ def compile(**kwargs):
:type custom_functions: :class:`set`,
:class:`collections.abc.Sequence`,
:class:`collections.abc.Mapping`
:param custom_import_extensions: optional extra file extensions which
allow can be imported, eg. ``['.css']``
:type custom_import_extensions: :class:`list`, :class:`tuple`
:param custom_import_extensions: (ignored, for backward compatibility)
:param importers: optional callback functions.
see also below `importer callbacks
<importer-callbacks_>`_ description
Expand Down Expand Up @@ -384,9 +379,7 @@ def compile(**kwargs):
:type custom_functions: :class:`set`,
:class:`collections.abc.Sequence`,
:class:`collections.abc.Mapping`
:param custom_import_extensions: optional extra file extensions which
allow can be imported, eg. ``['.css']``
:type custom_import_extensions: :class:`list`, :class:`tuple`
:param custom_import_extensions: (ignored, for backward compatibility)
:raises sass.CompileError: when it fails for any reason
(for example the given Sass has broken syntax)

Expand Down Expand Up @@ -606,13 +599,12 @@ def _get_file_arg(key):
'not {1!r}'.format(SassFunction, custom_functions),
)

_custom_exts = kwargs.pop('custom_import_extensions', []) or []
if not isinstance(_custom_exts, (list, tuple)):
raise TypeError(
'custom_import_extensions must be a list of strings '
'not {}'.format(type(_custom_exts)),
if kwargs.pop('custom_import_extensions', None) is not None:
warnings.warn(
'`custom_import_extensions` has no effect and will be removed in '
'a future version.',
FutureWarning,
)
custom_import_extensions = [ext.encode('utf-8') for ext in _custom_exts]

importers = _validate_importers(kwargs.pop('importers', None))

Expand All @@ -627,7 +619,7 @@ def _get_file_arg(key):
_check_no_remaining_kwargs(compile, kwargs)
s, v = _sass.compile_string(
string, output_style, source_comments, include_paths, precision,
custom_functions, indented, importers, custom_import_extensions,
custom_functions, indented, importers,
)
if s:
return v.decode('utf-8')
Expand All @@ -643,7 +635,7 @@ def _get_file_arg(key):
s, v, source_map = _sass.compile_filename(
filename, output_style, source_comments, include_paths, precision,
source_map_filename, custom_functions, importers,
output_filename_hint, custom_import_extensions,
output_filename_hint,
)
if s:
v = v.decode('utf-8')
Expand All @@ -663,7 +655,6 @@ def _get_file_arg(key):
s, v = compile_dirname(
search_path, output_path, output_style, source_comments,
include_paths, precision, custom_functions, importers,
custom_import_extensions,
)
if s:
return
Expand Down
56 changes: 12 additions & 44 deletions sasstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,12 @@ def test_pysassc_source_map_without_css_filename(self):
'actual error message is: ' + repr(err)
assert self.out.getvalue() == ''

def test_pysassc_warning_import_extensions(self):
with pytest.warns(FutureWarning):
pysassc.main(
['pysassc', os.devnull, '--import-extensions', '.css'],
)


@contextlib.contextmanager
def tempdir():
Expand Down Expand Up @@ -1529,59 +1535,21 @@ def test_imports_from_cwd(tmpdir):
assert out == ''


def test_import_no_css(tmpdir):
def test_import_css(tmpdir):
tmpdir.join('other.css').write('body {color: green}')
main_scss = tmpdir.join('main.scss')
main_scss.write("@import 'other';")
with pytest.raises(sass.CompileError):
sass.compile(filename=main_scss.strpath)


@pytest.mark.parametrize(
'exts', [
('.css',),
['.css'],
['.foobar', '.css'],
],
)
def test_import_css(exts, tmpdir):
tmpdir.join('other.css').write('body {color: green}')
main_scss = tmpdir.join('main.scss')
main_scss.write("@import 'other';")
out = sass.compile(
filename=main_scss.strpath,
custom_import_extensions=exts,
)
out = sass.compile(filename=main_scss.strpath)
assert out == 'body {\n color: green; }\n'


def test_import_css_error(tmpdir):
tmpdir.join('other.css').write('body {color: green}')
main_scss = tmpdir.join('main.scss')
main_scss.write("@import 'other';")
with pytest.raises(TypeError):
sass.compile(
filename=main_scss.strpath,
custom_import_extensions='.css',
)


def test_import_css_string(tmpdir):
tmpdir.join('other.css').write('body {color: green}')
with tmpdir.as_cwd():
out = sass.compile(
string="@import 'other';",
custom_import_extensions=['.css'],
)
out = sass.compile(string="@import 'other';")
assert out == 'body {\n color: green; }\n'


def test_import_ext_other(tmpdir):
tmpdir.join('other.foobar').write('body {color: green}')
main_scss = tmpdir.join('main.scss')
main_scss.write("@import 'other';")
out = sass.compile(
filename=main_scss.strpath,
custom_import_extensions=['.foobar'],
)
assert out == 'body {\n color: green; }\n'
def test_custom_import_extensions_warning():
with pytest.warns(FutureWarning):
sass.compile(string='a{b: c}', custom_import_extensions=['.css'])