6
6
an egg or wheel.
7
7
"""
8
8
9
- from setuptools import setup , Extension
10
- from distutils .command .build_ext import build_ext
11
- from distutils .command .install_lib import install_lib
12
- from distutils .command .install_data import install_data
13
- from distutils .sysconfig import get_config_var
14
- from distutils .spawn import find_executable
15
- from distutils import log
16
- from platform import architecture
17
- from subprocess import check_output , check_call
18
- from glob import glob
19
9
import fnmatch
20
- import sys
10
+ import glob
21
11
import os
12
+ import platform
13
+ import subprocess
14
+ import sys
15
+ import sysconfig
16
+ from distutils import log , spawn
17
+ from distutils .command import build_ext , install_data , install_lib
18
+
19
+ from setuptools import Extension , setup
22
20
23
21
CONFIG = "Release" # Release or Debug
24
- DEVTOOLS = "MsDev" if sys .platform == "win32" else "Mono"
25
22
VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic
26
- ARCH = "x64" if architecture ()[0 ] == "64bit" else "x86"
23
+
24
+ DEVTOOLS = "MsDev" if sys .platform == "win32" else "Mono"
25
+ ARCH = "x64" if platform .architecture ()[0 ] == "64bit" else "x86"
27
26
28
27
29
28
def _find_msbuild_tool (tool = "msbuild.exe" , use_windows_sdk = False ):
30
29
"""Return full path to one of the Microsoft build tools"""
31
- path = find_executable (tool )
30
+ path = spawn . find_executable (tool )
32
31
if path :
33
32
return path
34
33
35
- try :
36
- import _winreg
37
- except ImportError :
38
- import winreg as _winreg
34
+ try : # PY2
35
+ import _winreg as winreg
36
+ except ImportError : # PY3
37
+ import winreg
39
38
40
39
keys_to_check = []
41
40
if use_windows_sdk :
@@ -64,16 +63,16 @@ def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
64
63
65
64
# read the possible tools paths from the various registry locations
66
65
paths_to_check = []
67
- hreg = _winreg .ConnectRegistry (None , _winreg .HKEY_LOCAL_MACHINE )
66
+ hreg = winreg .ConnectRegistry (None , winreg .HKEY_LOCAL_MACHINE )
68
67
try :
69
68
for key_to_check in keys_to_check :
70
69
sdk_name , key , value_name = key_to_check [:3 ]
71
70
suffix = key_to_check [3 ] if len (key_to_check ) > 3 else None
72
71
hkey = None
73
72
try :
74
- hkey = _winreg .OpenKey (hreg , key )
75
- val , type_ = _winreg .QueryValueEx (hkey , value_name )
76
- if type_ != _winreg .REG_SZ :
73
+ hkey = winreg .OpenKey (hreg , key )
74
+ val , type_ = winreg .QueryValueEx (hkey , value_name )
75
+ if type_ != winreg .REG_SZ :
77
76
continue
78
77
if suffix :
79
78
val = os .path .join (val , suffix )
@@ -119,11 +118,11 @@ def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
119
118
"DevTools %s not supported (use MsDev or Mono)" % DEVTOOLS )
120
119
121
120
122
- class BuildExtPythonnet (build_ext ):
121
+ class BuildExtPythonnet (build_ext . build_ext ):
123
122
def build_extension (self , ext ):
124
123
"""Builds the .pyd file using msbuild or xbuild"""
125
124
if ext .name != "clr" :
126
- return build_ext .build_extension (self , ext )
125
+ return build_ext .build_ext . build_extension (self , ext )
127
126
128
127
# install packages using nuget
129
128
self ._install_packages ()
@@ -157,7 +156,7 @@ def build_extension(self, ext):
157
156
defines .append ("MONO_LINUX" )
158
157
159
158
# Check if --enable-shared was set when Python was built
160
- enable_shared = get_config_var ("Py_ENABLE_SHARED" )
159
+ enable_shared = sysconfig . get_config_var ("Py_ENABLE_SHARED" )
161
160
if enable_shared :
162
161
# Double-check if libpython is linked dynamically with python
163
162
lddout = _check_output (["ldd" , sys .executable ])
@@ -179,7 +178,7 @@ def build_extension(self, ext):
179
178
interop_file = _get_interop_filename ()
180
179
if not os .path .exists (interop_file ):
181
180
geninterop = os .path .join ("tools" , "geninterop" , "geninterop.py" )
182
- check_call ([sys .executable , geninterop , interop_file ])
181
+ subprocess . check_call ([sys .executable , geninterop , interop_file ])
183
182
184
183
cmd = [
185
184
_xbuild ,
@@ -198,8 +197,8 @@ def build_extension(self, ext):
198
197
199
198
self .announce ("Building: %s" % " " .join (cmd ))
200
199
use_shell = True if DEVTOOLS == "Mono" else False
201
- check_call (" " .join (cmd + ["/t:Clean" ]), shell = use_shell )
202
- check_call (" " .join (cmd + ["/t:Build" ]), shell = use_shell )
200
+ subprocess . check_call (" " .join (cmd + ["/t:Clean" ]), shell = use_shell )
201
+ subprocess . check_call (" " .join (cmd + ["/t:Build" ]), shell = use_shell )
203
202
204
203
if DEVTOOLS == "Mono" :
205
204
self ._build_monoclr (ext )
@@ -211,7 +210,7 @@ def _get_manifest(self, build_dir):
211
210
cmd = [mt , '-inputresource:"%s"' % sys .executable ,
212
211
'-out:"%s"' % manifest ]
213
212
self .announce ("Extracting manifest from %s" % sys .executable )
214
- check_call (" " .join (cmd ), shell = False )
213
+ subprocess . check_call (" " .join (cmd ), shell = False )
215
214
return manifest
216
215
217
216
def _build_monoclr (self , ext ):
@@ -231,7 +230,7 @@ def _build_monoclr(self, ext):
231
230
extra_compile_args = cflags .split (" " ),
232
231
extra_link_args = libs .split (" " ))
233
232
234
- build_ext .build_extension (self , clr_ext )
233
+ build_ext .build_ext . build_extension (self , clr_ext )
235
234
236
235
def _install_packages (self ):
237
236
"""install packages using nuget"""
@@ -243,14 +242,14 @@ def _install_packages(self):
243
242
244
243
cmd = "%s update -self" % nuget
245
244
self .announce ("Updating NuGet: %s" % cmd )
246
- check_call (cmd , shell = use_shell )
245
+ subprocess . check_call (cmd , shell = use_shell )
247
246
248
247
cmd = "%s restore pythonnet.sln -o packages" % nuget
249
248
self .announce ("Installing packages: %s" % cmd )
250
- check_call (cmd , shell = use_shell )
249
+ subprocess . check_call (cmd , shell = use_shell )
251
250
252
251
253
- class InstallLibPythonnet (install_lib ):
252
+ class InstallLibPythonnet (install_lib . install_lib ):
254
253
def install (self ):
255
254
if not os .path .isdir (self .build_dir ):
256
255
self .warn ("'%s' does not exist -- no Python modules to install" %
@@ -261,13 +260,13 @@ def install(self):
261
260
self .mkpath (self .install_dir )
262
261
263
262
# only copy clr.pyd/.so
264
- for srcfile in glob (os .path .join (self .build_dir , "clr.*" )):
263
+ for srcfile in glob . glob (os .path .join (self .build_dir , "clr.*" )):
265
264
destfile = os .path .join (
266
265
self .install_dir , os .path .basename (srcfile ))
267
266
self .copy_file (srcfile , destfile )
268
267
269
268
270
- class InstallDataPythonnet (install_data ):
269
+ class InstallDataPythonnet (install_data . install_data ):
271
270
def run (self ):
272
271
build_cmd = self .get_finalized_command ("build_ext" )
273
272
install_cmd = self .get_finalized_command ("install" )
@@ -284,12 +283,12 @@ def run(self):
284
283
dest = data_files [0 ].format (install_platlib = install_platlib )
285
284
self .data_files [i ] = dest , data_files [1 ]
286
285
287
- return install_data .run (self )
286
+ return install_data .install_data . run (self )
288
287
289
288
290
289
def _check_output (* args , ** kwargs ):
291
290
"""Check output wrapper for py2/py3 compatibility"""
292
- output = check_output (* args , ** kwargs )
291
+ output = subprocess . check_output (* args , ** kwargs )
293
292
if sys .version_info [0 ] > 2 :
294
293
return output .decode ("ascii" )
295
294
return output
@@ -312,7 +311,7 @@ def _get_interop_filename():
312
311
313
312
sources = []
314
313
for ext in (".sln" , ".snk" , ".config" ):
315
- sources .extend (glob ("*" + ext ))
314
+ sources .extend (glob . glob ("*" + ext ))
316
315
317
316
for root , dirnames , filenames in os .walk ("src" ):
318
317
for ext in (".cs" , ".csproj" , ".sln" , ".snk" , ".config" , ".il" ,
0 commit comments