1717CONFIG = "Release" # Release or Debug
1818DEVTOOLS = "MsDev" if sys .platform == "win32" else "Mono"
1919VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic
20+ PLATFORM = "x64" if architecture ()[0 ] == "64bit" else "x86"
2021
21- def FindMsBuildPath ():
22+
23+ def _find_msbuild_path ():
24+ """Return full path to msbuild.exe"""
2225 import _winreg
2326
24- aReg = _winreg .ConnectRegistry (None ,_winreg .HKEY_LOCAL_MACHINE )
27+ hreg = _winreg .ConnectRegistry (None , _winreg .HKEY_LOCAL_MACHINE )
2528 try :
26- keysToCheck = [r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\12.0" , r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0" , r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\3.5" , r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\2.0" ]
27- aKey = None
28- for key in keysToCheck :
29+ keys_to_check = [
30+ r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\12.0" ,
31+ r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0" ,
32+ r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\3.5" ,
33+ r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\2.0"
34+ ]
35+ hkey = None
36+ for key in keys_to_check :
2937 try :
30- aKey = _winreg .OpenKey (aReg , key )
38+ hkey = _winreg .OpenKey (hreg , key )
3139 break
3240 except WindowsError :
3341 pass
3442
35- if aKey == None :
36- raise RuntimeError ("MSBUILD .exe could not be found" )
43+ if hkey is None :
44+ raise RuntimeError ("msbuild .exe could not be found" )
3745
3846 try :
39- val , type = _winreg .QueryValueEx (aKey , "MSBuildToolsPath" )
40-
41- if type != _winreg .REG_SZ :
42- raise RuntimeError ("MSBUILD.exe could not be found" )
47+ val , type_ = _winreg .QueryValueEx (hkey , "MSBuildToolsPath" )
48+ if type_ != _winreg .REG_SZ :
49+ raise RuntimeError ("msbuild.exe could not be found" )
4350 finally :
44- aKey .Close ()
51+ hkey .Close ()
4552 finally :
46- aReg .Close ()
53+ hreg .Close ()
4754
4855 msbuildpath = os .path .join (val , "msbuild.exe" )
4956 return msbuildpath
5057
5158
5259if DEVTOOLS == "MsDev" :
53- _xbuild = "\" %s\" " % FindMsBuildPath ()
60+ _xbuild = "\" %s\" " % _find_msbuild_path ()
5461 _defines_sep = ";"
5562 _config = "%sWin" % CONFIG
5663 _npython_exe = "nPython.exe"
@@ -64,7 +71,6 @@ def FindMsBuildPath():
6471else :
6572 raise NotImplementedError ("DevTools %s not supported (use MsDev or Mono)" % DEVTOOLS )
6673
67- _platform = "x64" if architecture ()[0 ] == "64bit" else "x86"
6874
6975class PythonNET_BuildExt (build_ext ):
7076
@@ -75,6 +81,9 @@ def build_extension(self, ext):
7581 if ext .name != "clr" :
7682 return build_ext .build_extension (self , ext )
7783
84+ # install packages using nuget
85+ self ._install_packages ()
86+
7887 dest_file = self .get_ext_fullpath (ext .name )
7988 dest_dir = os .path .dirname (dest_file )
8089 if not os .path .exists (dest_dir ):
@@ -92,15 +101,16 @@ def build_extension(self, ext):
92101 _xbuild ,
93102 "pythonnet.sln" ,
94103 "/p:Configuration=%s" % _config ,
95- "/p:Platform=%s" % _platform ,
104+ "/p:Platform=%s" % PLATFORM ,
96105 "/p:DefineConstants=\" %s\" " % _defines_sep .join (defines ),
97106 "/p:PythonBuildDir=%s" % os .path .abspath (dest_dir ),
98107 "/verbosity:%s" % VERBOSITY ,
99108 ]
100109
101110 self .announce ("Building: %s" % " " .join (cmd ))
102- check_call (" " .join (cmd + ["/t:Clean" ]), shell = (True if DEVTOOLS == "Mono" else False ))
103- check_call (" " .join (cmd + ["/t:Build" ]), shell = (True if DEVTOOLS == "Mono" else False ))
111+ use_shell = True if DEVTOOLS == "Mono" else False
112+ check_call (" " .join (cmd + ["/t:Clean" ]), shell = use_shell )
113+ check_call (" " .join (cmd + ["/t:Build" ]), shell = use_shell )
104114
105115 if DEVTOOLS == "Mono" :
106116 self ._build_monoclr (ext )
@@ -157,6 +167,29 @@ def _build_monoclr(self, ext):
157167 debug = self .debug )
158168
159169
170+ def _install_packages (self ):
171+ """install packages using nuget"""
172+ nuget = os .path .join ("tools" , "nuget" , "nuget.exe" )
173+ use_shell = False
174+ if DEVTOOLS == "Mono" :
175+ nuget = "mono %s" % nuget
176+ use_shell = True
177+
178+ for dir in os .listdir ("src" ):
179+ if DEVTOOLS == "Mono" and dir == "clrmodule" :
180+ continue
181+ if DEVTOOLS != "Mono" and dir == "monoclr" :
182+ continue
183+
184+ packages_cfg = os .path .join ("src" , dir , "packages.config" )
185+ if not os .path .exists (packages_cfg ):
186+ continue
187+
188+ cmd = "%s install %s -o packages" % (nuget , packages_cfg )
189+ self .announce ("Installng packages for %s: %s" % (dir , cmd ))
190+ check_call (cmd , shell = use_shell )
191+
192+
160193class PythonNET_InstallLib (install_lib ):
161194
162195 def install (self ):
0 commit comments