diff --git a/libsass b/libsass index 1e52b743..39e30874 160000 --- a/libsass +++ b/libsass @@ -1 +1 @@ -Subproject commit 1e52b74306b7d73a617396c912ca436dc55fd4d8 +Subproject commit 39e30874b9a5dd6a802c20e8b0470ba44eeba929 diff --git a/pysass.cpp b/pysass.cpp index 6cfdfb72..435d2698 100644 --- a/pysass.cpp +++ b/pysass.cpp @@ -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; @@ -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; } @@ -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); @@ -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; } @@ -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); diff --git a/pysassc.py b/pysassc.py index 455af197..118395b0 100644 --- a/pysassc.py +++ b/pysassc.py @@ -64,6 +64,7 @@ import io import optparse import sys +import warnings import sass @@ -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, @@ -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 @@ -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 @@ -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) diff --git a/sass.py b/sass.py index f8ec6612..5cb523e9 100644 --- a/sass.py +++ b/sass.py @@ -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): @@ -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') @@ -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` @@ -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 `_ description @@ -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) @@ -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)) @@ -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') @@ -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') @@ -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 diff --git a/sasstests.py b/sasstests.py index 597e539e..ff73bea4 100644 --- a/sasstests.py +++ b/sasstests.py @@ -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(): @@ -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'])