1515import os .path
1616import re
1717import sys
18+ import warnings
1819
1920from six import string_types , text_type
2021
@@ -64,11 +65,9 @@ def compile(**kwargs):
6465 choose one of: ``'nested'`` (default), ``'expanded'``,
6566 ``'compact'``, ``'compressed'``
6667 :type output_style: :class:`str`
67- :param source_comments: an optional source comments mode of the compiled
68- result. choose one of ``'none'`` (default) or
69- ``'line_numbers'``. ``'map'`` is unavailable for
70- ``string``
71- :type source_comments: :class:`str`
68+ :param source_comments: whether to add comments about source lines.
69+ :const:`False` by default
70+ :type source_comments: :class:`bool`
7271 :param include_paths: an optional list of paths to find ``@import``\ ed
7372 SASS/CSS source files
7473 :type include_paths: :class:`collections.Sequence`, :class:`str`
@@ -89,19 +88,14 @@ def compile(**kwargs):
8988 choose one of: ``'nested'`` (default), ``'expanded'``,
9089 ``'compact'``, ``'compressed'``
9190 :type output_style: :class:`str`
92- :param source_comments: an optional source comments mode of the compiled
93- result. choose one of ``'none'`` (default),
94- ``'line_numbers'``, ``'map'``.
95- if ``'map'`` is used it requires
96- ``source_map_filename`` argument as well and
97- returns a (compiled CSS string,
98- source map string) pair instead of a string
99- :type source_comments: :class:`str`
100- :param source_map_filename: indicate the source map output filename.
101- it's only available and required
102- when ``source_comments`` is ``'map'``.
103- note that it will ignore all other parts of
104- the path except for its basename
91+ :param source_comments: whether to add comments about source lines.
92+ :const:`False` by default
93+ :type source_comments: :class:`bool`
94+ :param source_map_filename: use source maps and indicate the source map
95+ output filename. :const:`None` means not
96+ using source maps. :const:`None` by default.
97+ note that it implies ``source_comments``
98+ is also :const:`True`
10599 :type source_map_filename: :class:`str`
106100 :param include_paths: an optional list of paths to find ``@import``\ ed
107101 SASS/CSS source files
@@ -132,11 +126,9 @@ def compile(**kwargs):
132126 choose one of: ``'nested'`` (default), ``'expanded'``,
133127 ``'compact'``, ``'compressed'``
134128 :type output_style: :class:`str`
135- :param source_comments: an optional source comments mode of the compiled
136- result. choose one of ``'none'`` (default) or
137- ``'line_numbers'``. ``'map'`` is unavailable for
138- ``dirname``
139- :type source_comments: :class:`str`
129+ :param source_comments: whether to add comments about source lines.
130+ :const:`False` by default
131+ :type source_comments: :class:`bool`
140132 :param include_paths: an optional list of paths to find ``@import``\ ed
141133 SASS/CSS source files
142134 :type include_paths: :class:`collections.Sequence`, :class:`str`
@@ -148,6 +140,14 @@ def compile(**kwargs):
148140 .. versionadded:: 0.4.0
149141 Added ``source_comments`` and ``source_map_filename`` parameters.
150142
143+ .. versionchanged:: 0.6.0
144+ The ``source_comments`` parameter becomes to take only :class:`bool`
145+ instead of :class:`str`.
146+
147+ .. deprecated:: 0.6.0
148+ Values like ``'none'``, ``'line_numbers'``, and ``'map'`` for
149+ the ``source_comments`` parameter are deprecated.
150+
151151 """
152152 modes = set ()
153153 for mode_name in MODES :
@@ -167,38 +167,45 @@ def compile(**kwargs):
167167 except KeyError :
168168 raise CompileError ('{0} is unsupported output_style; choose one of {1}'
169169 '' .format (output_style , and_join (OUTPUT_STYLES )))
170- source_comments = kwargs .pop ('source_comments' , 'none' )
171- if not isinstance (source_comments , string_types ):
172- raise TypeError ('source_comments must be a string, not ' +
170+ source_comments = kwargs .pop ('source_comments' , False )
171+ if source_comments in SOURCE_COMMENTS :
172+ if source_comments == 'none' :
173+ deprecation_message = ('you can simply pass False to '
174+ "source_comments instead of 'none'" )
175+ source_comments = False
176+ elif source_comments in ('line_numbers' , 'default' ):
177+ deprecation_message = ('you can simply pass True to '
178+ "source_comments instead of " +
179+ repr (source_comments ))
180+ source_comments = True
181+ else :
182+ deprecation_message = ("you don't have to pass 'map' to "
183+ 'source_comments but just need to '
184+ 'specify source_map_filename' )
185+ source_comments = False
186+ warnings .warn (
187+ "values like 'none', 'line_numbers', and 'map' for "
188+ 'the source_comments parameter are deprecated; ' +
189+ deprecation_message ,
190+ DeprecationWarning
191+ )
192+ if not isinstance (source_comments , bool ):
193+ raise TypeError ('source_comments must be bool, not ' +
173194 repr (source_comments ))
174- if 'filename' not in modes and source_comments == 'map' :
175- raise CompileError ('source_comments="map" is only available with '
195+ fs_encoding = sys .getfilesystemencoding () or sys .getdefaultencoding ()
196+ source_map_filename = kwargs .pop ('source_map_filename' , None )
197+ if not (source_map_filename is None or
198+ isinstance (source_map_filename , string_types )):
199+ raise TypeError ('source_map_filename must be a string, not ' +
200+ repr (source_map_filename ))
201+ elif isinstance (source_map_filename , text_type ):
202+ source_map_filename = source_map_filename .encode (fs_encoding )
203+ if not ('filename' in modes or source_map_filename is None ):
204+ raise CompileError ('source_map_filename is only available with '
176205 'filename= keyword argument since it has to be '
177206 'aware of it' )
178- try :
179- source_comments = SOURCE_COMMENTS [source_comments ]
180- except KeyError :
181- raise CompileError (
182- '{0} is unsupported source_comments; choose one of '
183- '{1}' .format (source_comments , and_join (SOURCE_COMMENTS ))
184- )
185- fs_encoding = sys .getfilesystemencoding () or sys .getdefaultencoding ()
186- try :
187- source_map_filename = kwargs .pop ('source_map_filename' ) or b''
188- except KeyError :
189- if source_comments == SOURCE_COMMENTS ['map' ]:
190- raise TypeError ('source_comments="map" requires '
191- 'source_map_filename argument' )
192- source_map_filename = b''
193- else :
194- if source_comments != SOURCE_COMMENTS ['map' ]:
195- raise TypeError ('source_map_filename is available only with '
196- 'source_comments="map"' )
197- elif not isinstance (source_map_filename , string_types ):
198- raise TypeError ('source_map_filename must be a string, not ' +
199- repr (source_map_filename ))
200- if isinstance (source_map_filename , text_type ):
201- source_map_filename = source_map_filename .encode (fs_encoding )
207+ if source_map_filename is not None :
208+ source_comments = True
202209 try :
203210 include_paths = kwargs .pop ('include_paths' ) or b''
204211 except KeyError :
0 commit comments