24
24
25
25
DEVTOOLS = "MsDev" if sys .platform == "win32" else "Mono"
26
26
ARCH = "x64" if platform .architecture ()[0 ] == "64bit" else "x86"
27
+ PY_MAJOR = sys .version_info [0 ]
28
+ PY_MINOR = sys .version_info [1 ]
27
29
28
30
###############################################################################
29
31
# Windows Keys Constants for MSBUILD tools
@@ -144,9 +146,9 @@ def build_extension(self, ext):
144
146
unicode_width = ctypes .sizeof (ctypes .c_wchar )
145
147
146
148
defines = [
147
- "PYTHON%d%d" % ( sys . version_info [: 2 ] ),
148
- "PYTHON%d" % ( sys . version_info [: 1 ] ), # Python Major Version
149
- "UCS%d" % unicode_width ,
149
+ "PYTHON{0}{1}" . format ( PY_MAJOR , PY_MINOR ),
150
+ "PYTHON{0}" . format ( PY_MAJOR ), # Python Major Version
151
+ "UCS{0}" . format ( unicode_width ) ,
150
152
]
151
153
152
154
if CONFIG == "Debug" :
@@ -185,51 +187,49 @@ def build_extension(self, ext):
185
187
186
188
if DEVTOOLS == "MsDev" :
187
189
_xbuild = '"{0}"' .format (_find_msbuild_tool ("msbuild.exe" ))
188
- _defines_sep = ";"
189
190
_config = "{0}Win" .format (CONFIG )
190
191
191
192
elif DEVTOOLS == "Mono" :
192
193
_xbuild = "xbuild"
193
- _defines_sep = ","
194
194
_config = "{0}Mono" .format (CONFIG )
195
195
else :
196
196
raise NotImplementedError (
197
197
"DevTool {0} not supported (use MsDev/Mono)" .format (DEVTOOLS ))
198
198
199
199
cmd = [
200
200
_xbuild ,
201
- " pythonnet.sln" ,
202
- " /p:Configuration=%s" % _config ,
203
- " /p:Platform=%s" % ARCH ,
204
- " /p:DefineConstants=\" %s \" " % _defines_sep . join (defines ),
205
- " /p:PythonBuildDir=\" %s \" " % os .path .abspath (dest_dir ),
206
- " /p:PythonInteropFile=\" %s \" " % os .path .basename (interop_file ),
207
- " /verbosity:%s" % VERBOSITY ,
201
+ ' pythonnet.sln' ,
202
+ ' /p:Configuration={}' . format ( _config ) ,
203
+ ' /p:Platform={}' . format ( ARCH ) ,
204
+ ' /p:DefineConstants="{}"' . format ( ',' . join (defines ) ),
205
+ ' /p:PythonBuildDir="{}"' . format ( os .path .abspath (dest_dir ) ),
206
+ ' /p:PythonInteropFile="{}"' . format ( os .path .basename (interop_file ) ),
207
+ ' /verbosity:{}' . format ( VERBOSITY ) ,
208
208
]
209
209
210
210
manifest = self ._get_manifest (dest_dir )
211
211
if manifest :
212
- cmd .append (" /p:PythonManifest=\" %s \" " % manifest )
212
+ cmd .append (' /p:PythonManifest="{0}"' . format ( manifest ) )
213
213
214
- self .announce ("Building: %s" % " " .join (cmd ))
214
+ self .announce ("Building: {0}" . format ( " " .join (cmd ) ))
215
215
use_shell = True if DEVTOOLS == "Mono" else False
216
216
subprocess .check_call (" " .join (cmd + ["/t:Clean" ]), shell = use_shell )
217
217
subprocess .check_call (" " .join (cmd + ["/t:Build" ]), shell = use_shell )
218
218
219
219
if DEVTOOLS == "Mono" :
220
- self ._build_monoclr (ext )
220
+ self ._build_monoclr ()
221
221
222
222
def _get_manifest (self , build_dir ):
223
223
if DEVTOOLS == "MsDev" and sys .version_info [:2 ] > (2 , 5 ):
224
224
mt = _find_msbuild_tool ("mt.exe" , use_windows_sdk = True )
225
225
manifest = os .path .abspath (os .path .join (build_dir , "app.manifest" ))
226
- cmd = [mt , '-inputresource:"%s"' % sys .executable ,
227
- '-out:"%s"' % manifest ]
228
- self .announce ("Extracting manifest from %s" % sys .executable )
226
+ cmd = [mt , '-inputresource:"{0}"' . format ( sys .executable ) ,
227
+ '-out:"{0}"' . format ( manifest ) ]
228
+ self .announce ("Extracting manifest from {}" . format ( sys .executable ) )
229
229
subprocess .check_call (" " .join (cmd ), shell = False )
230
230
return manifest
231
231
232
- def _build_monoclr (self , ext ):
232
+ def _build_monoclr (self ):
233
233
mono_libs = _check_output ("pkg-config --libs mono-2" , shell = True )
234
234
mono_cflags = _check_output ("pkg-config --cflags mono-2" , shell = True )
235
235
glib_libs = _check_output ("pkg-config --libs glib-2.0" , shell = True )
@@ -238,13 +238,15 @@ def _build_monoclr(self, ext):
238
238
libs = mono_libs .strip () + " " + glib_libs .strip ()
239
239
240
240
# build the clr python module
241
- clr_ext = Extension ("clr" ,
242
- sources = [
243
- "src/monoclr/pynetinit.c" ,
244
- "src/monoclr/clrmod.c"
245
- ],
246
- extra_compile_args = cflags .split (" " ),
247
- extra_link_args = libs .split (" " ))
241
+ clr_ext = Extension (
242
+ "clr" ,
243
+ sources = [
244
+ "src/monoclr/pynetinit.c" ,
245
+ "src/monoclr/clrmod.c"
246
+ ],
247
+ extra_compile_args = cflags .split (" " ),
248
+ extra_link_args = libs .split (" " )
249
+ )
248
250
249
251
build_ext .build_ext .build_extension (self , clr_ext )
250
252
@@ -253,23 +255,23 @@ def _install_packages(self):
253
255
nuget = os .path .join ("tools" , "nuget" , "nuget.exe" )
254
256
use_shell = False
255
257
if DEVTOOLS == "Mono" :
256
- nuget = "mono %s" % nuget
258
+ nuget = "mono {0}" . format ( nuget )
257
259
use_shell = True
258
260
259
- cmd = "%s update -self" % nuget
260
- self .announce ("Updating NuGet: %s" % cmd )
261
+ cmd = "{0} update -self" . format ( nuget )
262
+ self .announce ("Updating NuGet: {0}" . format ( cmd ) )
261
263
subprocess .check_call (cmd , shell = use_shell )
262
264
263
- cmd = "%s restore pythonnet.sln -o packages" % nuget
264
- self .announce ("Installing packages: %s" % cmd )
265
+ cmd = "{0} restore pythonnet.sln -o packages" . format ( nuget )
266
+ self .announce ("Installing packages: {0}" . format ( cmd ) )
265
267
subprocess .check_call (cmd , shell = use_shell )
266
268
267
269
268
270
class InstallLibPythonnet (install_lib .install_lib ):
269
271
def install (self ):
270
272
if not os .path .isdir (self .build_dir ):
271
- self .warn ("'%s ' does not exist -- no Python modules to install" %
272
- self .build_dir )
273
+ self .warn ("'{0} ' does not exist -- no Python modules"
274
+ " to install" . format ( self .build_dir ) )
273
275
return
274
276
275
277
if not os .path .exists (self .install_dir ):
@@ -305,9 +307,9 @@ def run(self):
305
307
def _check_output (* args , ** kwargs ):
306
308
"""Check output wrapper for py2/py3 compatibility"""
307
309
output = subprocess .check_output (* args , ** kwargs )
308
- if sys . version_info [ 0 ] > 2 :
309
- return output . decode ( "ascii" )
310
- return output
310
+ if PY_MAJOR == 2 :
311
+ return output
312
+ return output . decode ( "ascii" )
311
313
312
314
313
315
def _get_interop_filename ():
@@ -316,8 +318,9 @@ def _get_interop_filename():
316
318
as most windows users won't have Clang installed, which is
317
319
required to generate the file.
318
320
"""
319
- interop_file = "interop%d%d%s.cs" % (sys .version_info [0 ], sys .version_info [1 ], getattr (sys , "abiflags" , "" ))
320
- return os .path .join ("src" , "runtime" , interop_file )
321
+ interop_filename = "interop{0}{1}{2}.cs" .format (
322
+ PY_MAJOR , PY_MINOR , getattr (sys , "abiflags" , "" ))
323
+ return os .path .join ("src" , "runtime" , interop_filename )
321
324
322
325
323
326
if __name__ == "__main__" :
@@ -382,5 +385,5 @@ def _get_interop_filename():
382
385
"install_lib" : InstallLibPythonnet ,
383
386
"install_data" : InstallDataPythonnet ,
384
387
},
385
- setup_requires = setup_requires
388
+ setup_requires = setup_requires ,
386
389
)
0 commit comments