Skip to content

Commit 793bc16

Browse files
committed
Add --source-comments option to sassc (help, etc. from node-sass)
1 parent f9fe779 commit 793bc16

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

sass.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,6 @@ def compile(**kwargs):
308308
:param source_map_filename: use source maps and indicate the source map
309309
output filename. :const:`None` means not
310310
using source maps. :const:`None` by default.
311-
note that it implies ``source_comments``
312-
is also :const:`True`
313311
:type source_map_filename: :class:`str`
314312
:param include_paths: an optional list of paths to find ``@import``\ ed
315313
SASS/CSS source files
@@ -327,7 +325,7 @@ def compile(**kwargs):
327325
<importer-callbacks>`_ description
328326
:type importers: :class:`collections.Callable`
329327
:returns: the compiled CSS string, or a pair of the compiled CSS string
330-
and the source map string if ``source_comments='map'``
328+
and the source map string if ``source_map_filename`` is set
331329
:rtype: :class:`str`, :class:`tuple`
332330
:raises sass.CompileError: when it fails for any reason
333331
(for example the given SASS has broken syntax)
@@ -480,6 +478,9 @@ def my_importer(path):
480478
.. versionadded:: 0.7.0
481479
Added ``custom_functions`` parameter.
482480
481+
.. versionadded:: 0.11.0
482+
``source_map_filename`` no longer implies ``source_comments``.
483+
483484
"""
484485
modes = set()
485486
for mode_name in MODES:

sassc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
4949
.. versionadded:: 0.7.0
5050
51+
.. option:: --source-comments
52+
53+
Include debug info in output.
54+
55+
.. versionadded:: 0.11.0
56+
5157
.. option:: -v, --version
5258
5359
Prints the program version.
@@ -101,6 +107,10 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
101107
'-p', '--precision', action='store', type='int', default=5,
102108
help='Set the precision for numbers. [default: %default]'
103109
)
110+
parser.add_option(
111+
'--source-comments', action='store_true', default=False,
112+
help='Include debug info in output',
113+
)
104114
options, args = parser.parse_args(argv[1:])
105115
error = functools.partial(print,
106116
parser.get_prog_name() + ': error:',
@@ -134,6 +144,7 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
134144
css, source_map = compile(
135145
filename=filename,
136146
output_style=options.style,
147+
source_comments=options.source_comments,
137148
source_map_filename=source_map_filename,
138149
include_paths=options.include_paths,
139150
precision=options.precision
@@ -144,6 +155,7 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
144155
css = compile(
145156
filename=filename,
146157
output_style=options.style,
158+
source_comments=options.source_comments,
147159
include_paths=options.include_paths,
148160
precision=options.precision
149161
)

sasstests.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ def setUp(self):
728728
self.err = StringIO()
729729

730730
def test_no_args(self):
731-
exit_code = sassc.main(['sassc', ], self.out, self.err)
731+
exit_code = sassc.main(['sassc'], self.out, self.err)
732732
self.assertEqual(2, exit_code)
733733
err = self.err.getvalue()
734734
assert err.strip().endswith('error: too few arguments'), \
@@ -794,12 +794,11 @@ def test_sassc_source_map_without_css_filename(self):
794794
self.assertEqual('', self.out.getvalue())
795795

796796
def test_sassc_sourcemap(self):
797-
tmp_dir = tempfile.mkdtemp()
798-
src_dir = os.path.join(tmp_dir, 'test')
799-
shutil.copytree('test', src_dir)
800-
src_filename = os.path.join(src_dir, 'a.scss')
801-
out_filename = os.path.join(tmp_dir, 'a.scss.css')
802-
try:
797+
with tempdir() as tmp_dir:
798+
src_dir = os.path.join(tmp_dir, 'test')
799+
shutil.copytree('test', src_dir)
800+
src_filename = os.path.join(src_dir, 'a.scss')
801+
out_filename = os.path.join(tmp_dir, 'a.scss.css')
803802
exit_code = sassc.main(
804803
['sassc', '-m', src_filename, out_filename],
805804
self.out, self.err
@@ -817,8 +816,6 @@ def test_sassc_sourcemap(self):
817816
dict(A_EXPECTED_MAP, sources=None),
818817
dict(json.load(f), sources=None)
819818
)
820-
finally:
821-
shutil.rmtree(tmp_dir)
822819

823820

824821
@contextlib.contextmanager
@@ -1421,3 +1418,8 @@ def test_stack_trace_formatting():
14211418
'>> a{☃\n'
14221419
' --^\n\n'
14231420
)
1421+
1422+
1423+
def test_source_comments():
1424+
out = sass.compile(string='a{color: red}', source_comments=True)
1425+
assert out == '/* line 1, stdin */\na {\n color: red; }\n'

0 commit comments

Comments
 (0)