14
14
15
15
from setuptools import Extension , setup
16
16
17
- system_sass = os .environ .get ('SYSTEM_SASS' , False )
17
+ MACOS_FLAG = ['-mmacosx-version-min=10.7' ]
18
+ FLAGS_POSIX = [
19
+ '-fPIC' , '-std=gnu++0x' , '-Wall' , '-Wno-parentheses' , '-Werror=switch' ,
20
+ ]
21
+ FLAGS_CLANG = ['-c' , '-O3' ] + FLAGS_POSIX + ['-stdlib=libc++' ]
22
+ LFLAGS_POSIX = ['-fPIC' , '-lstdc++' ]
23
+ LFLAGS_CLANG = ['-fPIC' , '-stdlib=libc++' ]
18
24
19
25
sources = ['pysass.cpp' ]
20
26
headers = []
21
- version_define = ''
22
27
28
+ if sys .platform == 'win32' :
29
+ extra_compile_args = ['/Od' , '/EHsc' , '/MT' ]
30
+ extra_link_args = []
31
+ elif platform .system () == 'Darwin' :
32
+ extra_compile_args = FLAGS_CLANG + MACOS_FLAG
33
+ extra_link_args = LFLAGS_CLANG + MACOS_FLAG
34
+ elif platform .system () == 'FreeBSD' :
35
+ extra_compile_args = FLAGS_CLANG
36
+ extra_link_args = LFLAGS_CLANG
37
+ else :
38
+ extra_compile_args = FLAGS_POSIX
39
+ extra_link_args = LFLAGS_POSIX
23
40
24
- def _maybe_clang (flags ):
25
- if platform .system () not in ('Darwin' , 'FreeBSD' ):
26
- return
27
-
41
+ if platform .system () in {'Darwin' , 'FreeBSD' }:
28
42
os .environ .setdefault ('CC' , 'clang' )
29
43
os .environ .setdefault ('CXX' , 'clang++' )
30
44
orig_customize_compiler = distutils .sysconfig .customize_compiler
@@ -37,37 +51,10 @@ def customize_compiler(compiler):
37
51
compiler .linker_so [0 ] = os .environ ['CXX' ]
38
52
return compiler
39
53
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
-
54
- if sys .platform == 'win32' :
55
- extra_link_args = []
56
- elif platform .system () in {'Darwin' , 'FreeBSD' }:
57
- extra_link_args = ['-fPIC' , '-lc++' ]
58
- else :
59
- extra_link_args = ['-fPIC' , '-lstdc++' ]
60
-
61
- if system_sass :
62
- flags = [
63
- '-fPIC' , '-std=gnu++0x' , '-Wall' , '-Wno-parentheses' , '-Werror=switch' ,
64
- ]
65
- _maybe_clang (flags )
66
- _maybe_macos (flags )
67
54
55
+ if os .environ .get ('SYSTEM_SASS' , False ):
68
56
libraries = ['sass' ]
69
57
include_dirs = []
70
- extra_compile_args = flags
71
58
else :
72
59
LIBSASS_SOURCE_DIR = os .path .join ('libsass' , 'src' )
73
60
@@ -83,15 +70,10 @@ def _maybe_macos(flags):
83
70
84
71
# Determine the libsass version from the git checkout
85
72
if os .path .exists (os .path .join ('libsass' , '.git' )):
86
- proc = subprocess .Popen (
87
- (
88
- 'git' , '-C' , 'libsass' , 'describe' ,
89
- '--abbrev=4' , '--dirty' , '--always' , '--tags' ,
90
- ),
91
- stdout = subprocess .PIPE ,
92
- )
93
- out , _ = proc .communicate ()
94
- assert not proc .returncode , proc .returncode
73
+ out = subprocess .check_output ((
74
+ 'git' , '-C' , 'libsass' , 'describe' ,
75
+ '--abbrev=4' , '--dirty' , '--always' , '--tags' ,
76
+ ))
95
77
with open ('.libsass-upstream-version' , 'wb' ) as libsass_version_file :
96
78
libsass_version_file .write (out )
97
79
@@ -100,11 +82,9 @@ def _maybe_macos(flags):
100
82
libsass_version = libsass_version_file .read ().decode ('UTF-8' ).strip ()
101
83
if sys .platform == 'win32' :
102
84
# This looks wrong, but is required for some reason :(
103
- version_define = r'/DLIBSASS_VERSION="\"{}\""' .format (
104
- libsass_version ,
105
- )
85
+ define = r'/DLIBSASS_VERSION="\"{}\""' .format (libsass_version )
106
86
else :
107
- version_define = '-DLIBSASS_VERSION="{}"' .format (libsass_version )
87
+ define = '-DLIBSASS_VERSION="{}"' .format (libsass_version )
108
88
109
89
for directory in (
110
90
os .path .join ('libsass' , 'src' ),
@@ -137,45 +117,36 @@ def _maybe_macos(flags):
137
117
if get_build_version () < 14.0 :
138
118
msvc9compiler .get_build_version = lambda : 14.0
139
119
msvc9compiler .VERSION = 14.0
140
- flags = ['/Od' , '/EHsc' , '/MT' ]
141
- else :
142
- flags = [
143
- '-fPIC' , '-std=gnu++0x' , '-Wall' ,
144
- '-Wno-parentheses' , '-Werror=switch' ,
145
- ]
146
- _maybe_clang (flags )
147
- _maybe_macos (flags )
148
-
149
- if platform .system () in ('Darwin' , 'FreeBSD' ):
150
- # Dirty workaround to avoid link error...
151
- # Python distutils doesn't provide any way
152
- # to configure different flags for each cc and c++.
153
- cencode_path = os .path .join (LIBSASS_SOURCE_DIR , 'cencode.c' )
154
- cencode_body = ''
155
- with open (cencode_path ) as f :
156
- cencode_body = f .read ()
157
- with open (cencode_path , 'w' ) as f :
158
- f .write (
159
- '#ifdef __cplusplus\n '
160
- 'extern "C" {\n '
161
- '#endif\n ' ,
162
- )
163
- f .write (cencode_body )
164
- f .write (
165
- '#ifdef __cplusplus\n '
166
- '}\n '
167
- '#endif\n ' ,
168
- )
120
+ elif platform .system () in ('Darwin' , 'FreeBSD' ):
121
+ # Dirty workaround to avoid link error...
122
+ # Python distutils doesn't provide any way
123
+ # to configure different flags for each cc and c++.
124
+ cencode_path = os .path .join (LIBSASS_SOURCE_DIR , 'cencode.c' )
125
+ cencode_body = ''
126
+ with open (cencode_path ) as f :
127
+ cencode_body = f .read ()
128
+ with open (cencode_path , 'w' ) as f :
129
+ f .write (
130
+ '#ifdef __cplusplus\n '
131
+ 'extern "C" {\n '
132
+ '#endif\n ' ,
133
+ )
134
+ f .write (cencode_body )
135
+ f .write (
136
+ '#ifdef __cplusplus\n '
137
+ '}\n '
138
+ '#endif\n ' ,
139
+ )
169
140
170
- @atexit .register
171
- def restore_cencode ():
172
- if os .path .isfile (cencode_path ):
173
- with open (cencode_path , 'w' ) as f :
174
- f .write (cencode_body )
141
+ @atexit .register
142
+ def restore_cencode ():
143
+ if os .path .isfile (cencode_path ):
144
+ with open (cencode_path , 'w' ) as f :
145
+ f .write (cencode_body )
175
146
176
147
libraries = []
177
148
include_dirs = [os .path .join ('.' , 'libsass' , 'include' )]
178
- extra_compile_args = flags + [ version_define ]
149
+ extra_compile_args . append ( define )
179
150
180
151
sass_extension = Extension (
181
152
'_sass' ,
@@ -192,8 +163,7 @@ def version(sass_filename='sass.py'):
192
163
with open (sass_filename ) as f :
193
164
tree = ast .parse (f .read (), sass_filename )
194
165
for node in tree .body :
195
- if isinstance (node , ast .Assign ) and \
196
- len (node .targets ) == 1 :
166
+ if isinstance (node , ast .Assign ) and len (node .targets ) == 1 :
197
167
target , = node .targets
198
168
if isinstance (target , ast .Name ) and target .id == '__version__' :
199
169
return node .value .s
0 commit comments