9
9
import os
10
10
import os .path
11
11
import re
12
+ import warnings
12
13
13
14
from six import string_types
14
15
@@ -86,7 +87,8 @@ class Manifest(object):
86
87
:param css_path: the path of the directory to store compiled CSS
87
88
files
88
89
:type css_path: :class:`str`, :class:`basestring`
89
-
90
+ :param strip_extension: whether to remove the original file extension
91
+ :type strip_extension: :class:`bool`
90
92
"""
91
93
92
94
@classmethod
@@ -106,6 +108,8 @@ def normalize_manifests(cls, manifests):
106
108
continue
107
109
elif isinstance (manifest , tuple ):
108
110
manifest = Manifest (* manifest )
111
+ elif isinstance (manifest , collections .Mapping ):
112
+ manifest = Manifest (** manifest )
109
113
elif isinstance (manifest , string_types ):
110
114
manifest = Manifest (manifest )
111
115
else :
@@ -117,7 +121,13 @@ def normalize_manifests(cls, manifests):
117
121
manifests [package_name ] = manifest
118
122
return manifests
119
123
120
- def __init__ (self , sass_path , css_path = None , wsgi_path = None ):
124
+ def __init__ (
125
+ self ,
126
+ sass_path ,
127
+ css_path = None ,
128
+ wsgi_path = None ,
129
+ strip_extension = None ,
130
+ ):
121
131
if not isinstance (sass_path , string_types ):
122
132
raise TypeError ('sass_path must be a string, not ' +
123
133
repr (sass_path ))
@@ -131,9 +141,23 @@ def __init__(self, sass_path, css_path=None, wsgi_path=None):
131
141
elif not isinstance (wsgi_path , string_types ):
132
142
raise TypeError ('wsgi_path must be a string, not ' +
133
143
repr (wsgi_path ))
144
+ if strip_extension is None :
145
+ warnings .warn (
146
+ '`strip_extension` was not specified, defaulting to `False`.\n '
147
+ 'In the future, `strip_extension` will default to `True`.' ,
148
+ DeprecationWarning ,
149
+ )
150
+ strip_extension = False
151
+ elif not isinstance (strip_extension , bool ):
152
+ raise TypeError (
153
+ 'strip_extension must be bool not {!r}' .format (
154
+ strip_extension ,
155
+ ),
156
+ )
134
157
self .sass_path = sass_path
135
158
self .css_path = css_path
136
159
self .wsgi_path = wsgi_path
160
+ self .strip_extension = strip_extension
137
161
138
162
def resolve_filename (self , package_dir , filename ):
139
163
"""Gets a proper full relative path of Sass source and
@@ -149,6 +173,8 @@ def resolve_filename(self, package_dir, filename):
149
173
150
174
"""
151
175
sass_path = os .path .join (package_dir , self .sass_path , filename )
176
+ if self .strip_extension :
177
+ filename , _ = os .path .splitext (filename )
152
178
css_filename = filename + '.css'
153
179
css_path = os .path .join (package_dir , self .css_path , css_filename )
154
180
return sass_path , css_path
0 commit comments