diff --git a/sass.py b/sass.py index 7319ad52..7f258913 100644 --- a/sass.py +++ b/sass.py @@ -308,8 +308,6 @@ def compile(**kwargs): :param source_map_filename: use source maps and indicate the source map output filename. :const:`None` means not using source maps. :const:`None` by default. - note that it implies ``source_comments`` - is also :const:`True` :type source_map_filename: :class:`str` :param include_paths: an optional list of paths to find ``@import``\ ed SASS/CSS source files @@ -327,7 +325,7 @@ def compile(**kwargs): `_ description :type importers: :class:`collections.Callable` :returns: the compiled CSS string, or a pair of the compiled CSS string - and the source map string if ``source_comments='map'`` + and the source map string if ``source_map_filename`` is set :rtype: :class:`str`, :class:`tuple` :raises sass.CompileError: when it fails for any reason (for example the given SASS has broken syntax) @@ -480,6 +478,9 @@ def my_importer(path): .. versionadded:: 0.7.0 Added ``custom_functions`` parameter. + .. versionadded:: 0.11.0 + ``source_map_filename`` no longer implies ``source_comments``. + """ modes = set() for mode_name in MODES: diff --git a/sassc.py b/sassc.py index eac88f59..0536747f 100755 --- a/sassc.py +++ b/sassc.py @@ -48,6 +48,12 @@ .. versionadded:: 0.7.0 +.. option:: --source-comments + + Include debug info in output. + + .. versionadded:: 0.11.0 + .. option:: -v, --version Prints the program version. @@ -101,6 +107,10 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr): '-p', '--precision', action='store', type='int', default=5, help='Set the precision for numbers. [default: %default]' ) + parser.add_option( + '--source-comments', action='store_true', default=False, + help='Include debug info in output', + ) options, args = parser.parse_args(argv[1:]) error = functools.partial(print, parser.get_prog_name() + ': error:', @@ -134,6 +144,7 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr): css, source_map = compile( filename=filename, output_style=options.style, + source_comments=options.source_comments, source_map_filename=source_map_filename, include_paths=options.include_paths, precision=options.precision @@ -144,6 +155,7 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr): css = compile( filename=filename, output_style=options.style, + source_comments=options.source_comments, include_paths=options.include_paths, precision=options.precision ) diff --git a/sasstests.py b/sasstests.py index 011d732f..3a810e86 100644 --- a/sasstests.py +++ b/sasstests.py @@ -728,7 +728,7 @@ def setUp(self): self.err = StringIO() def test_no_args(self): - exit_code = sassc.main(['sassc', ], self.out, self.err) + exit_code = sassc.main(['sassc'], self.out, self.err) self.assertEqual(2, exit_code) err = self.err.getvalue() assert err.strip().endswith('error: too few arguments'), \ @@ -794,12 +794,11 @@ def test_sassc_source_map_without_css_filename(self): self.assertEqual('', self.out.getvalue()) def test_sassc_sourcemap(self): - tmp_dir = tempfile.mkdtemp() - src_dir = os.path.join(tmp_dir, 'test') - shutil.copytree('test', src_dir) - src_filename = os.path.join(src_dir, 'a.scss') - out_filename = os.path.join(tmp_dir, 'a.scss.css') - try: + with tempdir() as tmp_dir: + src_dir = os.path.join(tmp_dir, 'test') + shutil.copytree('test', src_dir) + src_filename = os.path.join(src_dir, 'a.scss') + out_filename = os.path.join(tmp_dir, 'a.scss.css') exit_code = sassc.main( ['sassc', '-m', src_filename, out_filename], self.out, self.err @@ -817,8 +816,6 @@ def test_sassc_sourcemap(self): dict(A_EXPECTED_MAP, sources=None), dict(json.load(f), sources=None) ) - finally: - shutil.rmtree(tmp_dir) @contextlib.contextmanager @@ -1421,3 +1418,8 @@ def test_stack_trace_formatting(): '>> a{☃\n' ' --^\n\n' ) + + +def test_source_comments(): + out = sass.compile(string='a{color: red}', source_comments=True) + assert out == '/* line 1, stdin */\na {\n color: red; }\n'