20
20
headers = []
21
21
version_define = ''
22
22
23
+
24
+ def _maybe_clang (flags ):
25
+ if platform .system () not in ('Darwin' , 'FreeBSD' ):
26
+ return
27
+
28
+ os .environ .setdefault ('CC' , 'clang' )
29
+ os .environ .setdefault ('CXX' , 'clang++' )
30
+ orig_customize_compiler = distutils .sysconfig .customize_compiler
31
+
32
+ def customize_compiler (compiler ):
33
+ orig_customize_compiler (compiler )
34
+ compiler .compiler [0 ] = os .environ ['CC' ]
35
+ compiler .compiler_so [0 ] = os .environ ['CXX' ]
36
+ compiler .compiler_cxx [0 ] = os .environ ['CXX' ]
37
+ compiler .linker_so [0 ] = os .environ ['CXX' ]
38
+ return compiler
39
+ distutils .sysconfig .customize_compiler = customize_compiler
40
+ flags [:] = ['-c' , '-O3' ] + flags + ['stdlib=libc++' ]
41
+
42
+
43
+ def _maybe_macos (flags ):
44
+ if platform .system () != 'Darwin' :
45
+ return
46
+ flags .append ('-mmacosx-version-min=10.7' ,)
47
+ macver = tuple (map (int , platform .mac_ver ()[0 ].split ('.' )))
48
+ if macver >= (10 , 9 ):
49
+ flags .append (
50
+ '-Wno-error=unused-command-line-argument-hard-error-in-future' ,
51
+ )
52
+
53
+
23
54
if system_sass :
24
55
flags = [
25
56
'-fPIC' , '-std=gnu++0x' , '-Wall' , '-Wno-parentheses' , '-Werror=switch' ,
26
57
]
27
- platform .mac_ver ()
28
- if platform .system () in ['Darwin' , 'FreeBSD' ]:
29
- os .environ .setdefault ('CC' , 'clang' )
30
- os .environ .setdefault ('CXX' , 'clang++' )
31
- orig_customize_compiler = distutils .sysconfig .customize_compiler
32
-
33
- def customize_compiler (compiler ):
34
- orig_customize_compiler (compiler )
35
- compiler .compiler [0 ] = os .environ ['CC' ]
36
- compiler .compiler_so [0 ] = os .environ ['CXX' ]
37
- compiler .compiler_cxx [0 ] = os .environ ['CXX' ]
38
- compiler .linker_so [0 ] = os .environ ['CXX' ]
39
- return compiler
40
- distutils .sysconfig .customize_compiler = customize_compiler
41
- flags .append ('-stdlib=libc++' )
42
- if platform .system () == 'Darwin' :
43
- flags .append ('-mmacosx-version-min=10.7' ,)
44
- macver = tuple (map (int , platform .mac_ver ()[0 ].split ('.' )))
45
- if macver >= (10 , 9 ):
46
- flags .append (
47
- '-Wno-error=unused-command-line-' +
48
- 'argument-hard-error-in-future' , # noqa
49
- )
50
-
51
- flags = ['-c' , '-O3' ] + flags
58
+ _maybe_clang (flags )
59
+ _maybe_macos (flags )
52
60
53
61
if platform .system () == 'FreeBSD' :
54
62
link_flags = ['-fPIC' , '-lc++' ]
@@ -90,10 +98,10 @@ def customize_compiler(compiler):
90
98
libsass_version = libsass_version_file .read ().decode ('UTF-8' ).strip ()
91
99
if sys .platform == 'win32' :
92
100
# This looks wrong, but is required for some reason :(
93
- version_define = r'/DLIBSASS_VERSION="\"{0 }\""' .format (
101
+ version_define = r'/DLIBSASS_VERSION="\"{}\""' .format (
94
102
libsass_version )
95
103
else :
96
- version_define = '-DLIBSASS_VERSION="{0 }"' .format (libsass_version )
104
+ version_define = '-DLIBSASS_VERSION="{}"' .format (libsass_version )
97
105
98
106
for directory in (
99
107
os .path .join ('libsass' , 'src' ),
@@ -109,7 +117,7 @@ def customize_compiler(compiler):
109
117
110
118
if sys .platform == 'win32' :
111
119
from distutils .msvc9compiler import get_build_version
112
- vscomntools_env = 'VS{0}{1 }COMNTOOLS' .format (
120
+ vscomntools_env = 'VS{}{ }COMNTOOLS' .format (
113
121
int (get_build_version ()),
114
122
int (get_build_version () * 10 ) % 10
115
123
)
@@ -131,29 +139,10 @@ def customize_compiler(compiler):
131
139
'-fPIC' , '-std=gnu++0x' , '-Wall' ,
132
140
'-Wno-parentheses' , '-Werror=switch' ,
133
141
]
134
- platform .mac_ver ()
135
- if platform .system () in ['Darwin' , 'FreeBSD' ]:
136
- os .environ .setdefault ('CC' , 'clang' )
137
- os .environ .setdefault ('CXX' , 'clang++' )
138
- orig_customize_compiler = distutils .sysconfig .customize_compiler
139
-
140
- def customize_compiler (compiler ):
141
- orig_customize_compiler (compiler )
142
- compiler .compiler [0 ] = os .environ ['CC' ]
143
- compiler .compiler_so [0 ] = os .environ ['CXX' ]
144
- compiler .compiler_cxx [0 ] = os .environ ['CXX' ]
145
- compiler .linker_so [0 ] = os .environ ['CXX' ]
146
- return compiler
147
- distutils .sysconfig .customize_compiler = customize_compiler
148
- flags .append ('-stdlib=libc++' )
149
- if platform .system () == 'Darwin' :
150
- flags .append ('-mmacosx-version-min=10.7' ,)
151
- macver = tuple (map (int , platform .mac_ver ()[0 ].split ('.' )))
152
- if macver >= (10 , 9 ):
153
- flags .append (
154
- '-Wno-error=unused-command-line-' +
155
- 'argument-hard-error-in-future' , # noqa
156
- )
142
+ _maybe_clang (flags )
143
+ _maybe_macos (flags )
144
+
145
+ if platform .system () in ('Darwin' , 'FreeBSD' ):
157
146
# Dirty workaround to avoid link error...
158
147
# Python distutils doesn't provide any way
159
148
# to configure different flags for each cc and c++.
@@ -162,26 +151,24 @@ def customize_compiler(compiler):
162
151
with open (cencode_path ) as f :
163
152
cencode_body = f .read ()
164
153
with open (cencode_path , 'w' ) as f :
165
- f .write ('''
166
- #ifdef __cplusplus
167
- extern "C" {
168
- #endif
169
- ''' )
154
+ f .write (
155
+ ' #ifdef __cplusplus\n '
156
+ ' extern "C" {\n '
157
+ ' #endif\n '
158
+ )
170
159
f .write (cencode_body )
171
- f .write ('''
172
- #ifdef __cplusplus
173
- }
174
- #endif
175
- ''' )
160
+ f .write (
161
+ ' #ifdef __cplusplus\n '
162
+ '} \n '
163
+ ' #endif\n '
164
+ )
176
165
177
166
@atexit .register
178
167
def restore_cencode ():
179
168
if os .path .isfile (cencode_path ):
180
169
with open (cencode_path , 'w' ) as f :
181
170
f .write (cencode_body )
182
171
183
- flags = ['-c' , '-O3' ] + flags
184
-
185
172
if platform .system () == 'FreeBSD' :
186
173
link_flags = ['-fPIC' , '-lc++' ]
187
174
else :
@@ -192,19 +179,16 @@ def restore_cencode():
192
179
extra_compile_args = flags + [version_define ]
193
180
extra_link_args = link_flags
194
181
195
- sources .sort ()
196
182
sass_extension = Extension (
197
183
'_sass' ,
198
- sources ,
184
+ sorted ( sources ) ,
199
185
include_dirs = include_dirs ,
200
186
depends = headers ,
201
187
extra_compile_args = extra_compile_args ,
202
188
extra_link_args = link_flags ,
203
189
libraries = libraries
204
190
)
205
191
206
- install_requires = ['six' ]
207
-
208
192
209
193
def version (sass_filename = 'sass.py' ):
210
194
with open (sass_filename ) as f :
@@ -287,12 +271,8 @@ def run(self):
287
271
['sassc = sassc:main' ],
288
272
]
289
273
},
290
- install_requires = install_requires ,
291
- extras_require = {
292
- 'upload_appveyor_builds' : [
293
- 'twine == 1.5.0' ,
294
- ],
295
- },
274
+ install_requires = ['six' ],
275
+ extras_require = {'upload_appveyor_builds' : ['twine == 1.5.0' ]},
296
276
classifiers = [
297
277
'Development Status :: 5 - Production/Stable' ,
298
278
'Environment :: Web Environment' ,
0 commit comments