Skip to content

Commit 44a2990

Browse files
authored
Merge pull request #275 from asottile/3_5_5
libsass 3.5.5
2 parents 610674f + 4776f7e commit 44a2990

File tree

5 files changed

+38
-94
lines changed

5 files changed

+38
-94
lines changed

pysass.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,6 @@ static void _add_custom_importers(
507507
sass_option_set_c_importers(options, importer_list);
508508
}
509509

510-
static void _add_custom_import_extensions(
511-
struct Sass_Options* options, PyObject* custom_import_extensions
512-
) {
513-
Py_ssize_t i;
514-
515-
for (i = 0; i < PyList_GET_SIZE(custom_import_extensions); i += 1) {
516-
PyObject* ext = PyList_GET_ITEM(custom_import_extensions, i);
517-
sass_option_push_import_extension(options, PyBytes_AS_STRING(ext));
518-
}
519-
}
520-
521510
static PyObject *
522511
PySass_compile_string(PyObject *self, PyObject *args) {
523512
struct Sass_Context *ctx;
@@ -529,15 +518,13 @@ PySass_compile_string(PyObject *self, PyObject *args) {
529518
int source_comments, error_status, precision, indented;
530519
PyObject *custom_functions;
531520
PyObject *custom_importers;
532-
PyObject *custom_import_extensions;
533521
PyObject *result;
534522

535523
if (!PyArg_ParseTuple(args,
536-
PySass_IF_PY3("yiiyiOiOO", "siisiOiOO"),
524+
PySass_IF_PY3("yiiyiOiO", "siisiOiO"),
537525
&string, &output_style, &source_comments,
538526
&include_paths, &precision,
539-
&custom_functions, &indented, &custom_importers,
540-
&custom_import_extensions)) {
527+
&custom_functions, &indented, &custom_importers)) {
541528
return NULL;
542529
}
543530

@@ -550,7 +537,6 @@ PySass_compile_string(PyObject *self, PyObject *args) {
550537
sass_option_set_is_indented_syntax_src(options, indented);
551538
_add_custom_functions(options, custom_functions);
552539
_add_custom_importers(options, custom_importers);
553-
_add_custom_import_extensions(options, custom_import_extensions);
554540
sass_compile_data_context(context);
555541

556542
ctx = sass_data_context_get_context(context);
@@ -576,15 +562,14 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
576562
Sass_Output_Style output_style;
577563
int source_comments, error_status, precision;
578564
PyObject *source_map_filename, *custom_functions, *custom_importers,
579-
*result, *output_filename_hint, *custom_import_extensions;
565+
*result, *output_filename_hint;
580566

581567
if (!PyArg_ParseTuple(args,
582-
PySass_IF_PY3("yiiyiOOOOO", "siisiOOOOO"),
568+
PySass_IF_PY3("yiiyiOOOO", "siisiOOOO"),
583569
&filename, &output_style, &source_comments,
584570
&include_paths, &precision,
585571
&source_map_filename, &custom_functions,
586-
&custom_importers, &output_filename_hint,
587-
&custom_import_extensions)) {
572+
&custom_importers, &output_filename_hint)) {
588573
return NULL;
589574
}
590575

@@ -611,7 +596,6 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
611596
sass_option_set_precision(options, precision);
612597
_add_custom_functions(options, custom_functions);
613598
_add_custom_importers(options, custom_importers);
614-
_add_custom_import_extensions(options, custom_import_extensions);
615599
sass_compile_file_context(context);
616600

617601
ctx = sass_file_context_get_context(context);

pysassc.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import io
6565
import optparse
6666
import sys
67+
import warnings
6768

6869
import sass
6970

@@ -105,12 +106,7 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
105106
'--source-comments', action='store_true', default=False,
106107
help='Include debug info in output',
107108
)
108-
parser.add_option(
109-
'--import-extensions',
110-
dest='custom_import_extensions', action='append',
111-
help='Extra extensions allowed for sass imports. '
112-
'Can be multiply used.',
113-
)
109+
parser.add_option('--import-extensions', help=optparse.SUPPRESS_HELP)
114110
options, args = parser.parse_args(argv[1:])
115111
error = functools.partial(
116112
print,
@@ -134,6 +130,13 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
134130
)
135131
return 2
136132

133+
if options.import_extensions:
134+
warnings.warn(
135+
'`--import-extensions` has no effect and will be removed in '
136+
'a future version.',
137+
FutureWarning,
138+
)
139+
137140
try:
138141
if options.source_map:
139142
source_map_filename = args[1] + '.map' # FIXME
@@ -145,7 +148,6 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
145148
output_filename_hint=args[1],
146149
include_paths=options.include_paths,
147150
precision=options.precision,
148-
custom_import_extensions=options.custom_import_extensions,
149151
)
150152
else:
151153
source_map_filename = None
@@ -156,7 +158,6 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
156158
source_comments=options.source_comments,
157159
include_paths=options.include_paths,
158160
precision=options.precision,
159-
custom_import_extensions=options.custom_import_extensions,
160161
)
161162
except (IOError, OSError) as e:
162163
error(e)

sass.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def _raise(e):
225225

226226
def compile_dirname(
227227
search_path, output_path, output_style, source_comments, include_paths,
228-
precision, custom_functions, importers, custom_import_extensions,
228+
precision, custom_functions, importers,
229229
):
230230
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
231231
for dirpath, _, filenames in os.walk(search_path, onerror=_raise):
@@ -243,7 +243,6 @@ def compile_dirname(
243243
s, v, _ = _sass.compile_filename(
244244
input_filename, output_style, source_comments, include_paths,
245245
precision, None, custom_functions, importers, None,
246-
custom_import_extensions,
247246
)
248247
if s:
249248
v = v.decode('UTF-8')
@@ -296,9 +295,7 @@ def compile(**kwargs):
296295
:type custom_functions: :class:`set`,
297296
:class:`collections.abc.Sequence`,
298297
:class:`collections.abc.Mapping`
299-
:param custom_import_extensions: optional extra file extensions which
300-
allow can be imported, eg. ``['.css']``
301-
:type custom_import_extensions: :class:`list`, :class:`tuple`
298+
:param custom_import_extensions: (ignored, for backward compatibility)
302299
:param indented: optional declaration that the string is Sass, not SCSS
303300
formatted. :const:`False` by default
304301
:type indented: :class:`bool`
@@ -339,9 +336,7 @@ def compile(**kwargs):
339336
:type custom_functions: :class:`set`,
340337
:class:`collections.abc.Sequence`,
341338
:class:`collections.abc.Mapping`
342-
:param custom_import_extensions: optional extra file extensions which
343-
allow can be imported, eg. ``['.css']``
344-
:type custom_import_extensions: :class:`list`, :class:`tuple`
339+
:param custom_import_extensions: (ignored, for backward compatibility)
345340
:param importers: optional callback functions.
346341
see also below `importer callbacks
347342
<importer-callbacks_>`_ description
@@ -384,9 +379,7 @@ def compile(**kwargs):
384379
:type custom_functions: :class:`set`,
385380
:class:`collections.abc.Sequence`,
386381
:class:`collections.abc.Mapping`
387-
:param custom_import_extensions: optional extra file extensions which
388-
allow can be imported, eg. ``['.css']``
389-
:type custom_import_extensions: :class:`list`, :class:`tuple`
382+
:param custom_import_extensions: (ignored, for backward compatibility)
390383
:raises sass.CompileError: when it fails for any reason
391384
(for example the given Sass has broken syntax)
392385
@@ -606,13 +599,12 @@ def _get_file_arg(key):
606599
'not {1!r}'.format(SassFunction, custom_functions),
607600
)
608601

609-
_custom_exts = kwargs.pop('custom_import_extensions', []) or []
610-
if not isinstance(_custom_exts, (list, tuple)):
611-
raise TypeError(
612-
'custom_import_extensions must be a list of strings '
613-
'not {}'.format(type(_custom_exts)),
602+
if kwargs.pop('custom_import_extensions', None) is not None:
603+
warnings.warn(
604+
'`custom_import_extensions` has no effect and will be removed in '
605+
'a future version.',
606+
FutureWarning,
614607
)
615-
custom_import_extensions = [ext.encode('utf-8') for ext in _custom_exts]
616608

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

@@ -627,7 +619,7 @@ def _get_file_arg(key):
627619
_check_no_remaining_kwargs(compile, kwargs)
628620
s, v = _sass.compile_string(
629621
string, output_style, source_comments, include_paths, precision,
630-
custom_functions, indented, importers, custom_import_extensions,
622+
custom_functions, indented, importers,
631623
)
632624
if s:
633625
return v.decode('utf-8')
@@ -643,7 +635,7 @@ def _get_file_arg(key):
643635
s, v, source_map = _sass.compile_filename(
644636
filename, output_style, source_comments, include_paths, precision,
645637
source_map_filename, custom_functions, importers,
646-
output_filename_hint, custom_import_extensions,
638+
output_filename_hint,
647639
)
648640
if s:
649641
v = v.decode('utf-8')
@@ -663,7 +655,6 @@ def _get_file_arg(key):
663655
s, v = compile_dirname(
664656
search_path, output_path, output_style, source_comments,
665657
include_paths, precision, custom_functions, importers,
666-
custom_import_extensions,
667658
)
668659
if s:
669660
return

sasstests.py

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,12 @@ def test_pysassc_source_map_without_css_filename(self):
891891
'actual error message is: ' + repr(err)
892892
assert self.out.getvalue() == ''
893893

894+
def test_pysassc_warning_import_extensions(self):
895+
with pytest.warns(FutureWarning):
896+
pysassc.main(
897+
['pysassc', os.devnull, '--import-extensions', '.css'],
898+
)
899+
894900

895901
@contextlib.contextmanager
896902
def tempdir():
@@ -1532,59 +1538,21 @@ def test_imports_from_cwd(tmpdir):
15321538
assert out == ''
15331539

15341540

1535-
def test_import_no_css(tmpdir):
1541+
def test_import_css(tmpdir):
15361542
tmpdir.join('other.css').write('body {color: green}')
15371543
main_scss = tmpdir.join('main.scss')
15381544
main_scss.write("@import 'other';")
1539-
with pytest.raises(sass.CompileError):
1540-
sass.compile(filename=main_scss.strpath)
1541-
1542-
1543-
@pytest.mark.parametrize(
1544-
'exts', [
1545-
('.css',),
1546-
['.css'],
1547-
['.foobar', '.css'],
1548-
],
1549-
)
1550-
def test_import_css(exts, tmpdir):
1551-
tmpdir.join('other.css').write('body {color: green}')
1552-
main_scss = tmpdir.join('main.scss')
1553-
main_scss.write("@import 'other';")
1554-
out = sass.compile(
1555-
filename=main_scss.strpath,
1556-
custom_import_extensions=exts,
1557-
)
1545+
out = sass.compile(filename=main_scss.strpath)
15581546
assert out == 'body {\n color: green; }\n'
15591547

15601548

1561-
def test_import_css_error(tmpdir):
1562-
tmpdir.join('other.css').write('body {color: green}')
1563-
main_scss = tmpdir.join('main.scss')
1564-
main_scss.write("@import 'other';")
1565-
with pytest.raises(TypeError):
1566-
sass.compile(
1567-
filename=main_scss.strpath,
1568-
custom_import_extensions='.css',
1569-
)
1570-
1571-
15721549
def test_import_css_string(tmpdir):
15731550
tmpdir.join('other.css').write('body {color: green}')
15741551
with tmpdir.as_cwd():
1575-
out = sass.compile(
1576-
string="@import 'other';",
1577-
custom_import_extensions=['.css'],
1578-
)
1552+
out = sass.compile(string="@import 'other';")
15791553
assert out == 'body {\n color: green; }\n'
15801554

15811555

1582-
def test_import_ext_other(tmpdir):
1583-
tmpdir.join('other.foobar').write('body {color: green}')
1584-
main_scss = tmpdir.join('main.scss')
1585-
main_scss.write("@import 'other';")
1586-
out = sass.compile(
1587-
filename=main_scss.strpath,
1588-
custom_import_extensions=['.foobar'],
1589-
)
1590-
assert out == 'body {\n color: green; }\n'
1556+
def test_custom_import_extensions_warning():
1557+
with pytest.warns(FutureWarning):
1558+
sass.compile(string='a{b: c}', custom_import_extensions=['.css'])

0 commit comments

Comments
 (0)