|
15 | 15 | import sysconfig
|
16 | 16 | from distutils import spawn
|
17 | 17 | from distutils.command import install, build, build_ext, install_data, install_lib
|
| 18 | +from wheel import bdist_wheel |
18 | 19 |
|
19 | 20 | from setuptools import Extension, setup
|
20 | 21 |
|
@@ -139,14 +140,14 @@ def _update_xlat_devtools():
|
139 | 140 | DEVTOOLS = "dotnet"
|
140 | 141 |
|
141 | 142 | class BuildExtPythonnet(build_ext.build_ext):
|
142 |
| - user_options = build_ext.build_ext.user_options + [ |
143 |
| - ('xplat', None, None) |
| 143 | + user_options = build_ext.build_ext.user_options + [ |
| 144 | + ('xplat', None, None) |
144 | 145 | ]
|
145 |
| - def initialize_options(self): |
146 |
| - build_ext.build_ext.initialize_options(self) |
147 |
| - self.xplat = None |
148 |
| - |
149 |
| - def finalize_options(self): |
| 146 | + def initialize_options(self): |
| 147 | + build_ext.build_ext.initialize_options(self) |
| 148 | + self.xplat = None |
| 149 | + |
| 150 | + def finalize_options(self): |
150 | 151 | build_ext.build_ext.finalize_options(self)
|
151 | 152 |
|
152 | 153 | def build_extension(self, ext):
|
@@ -218,8 +219,7 @@ def build_extension(self, ext):
|
218 | 219 | _solution_file = 'pythonnet.sln'
|
219 | 220 | _custom_define_constants = False
|
220 | 221 | elif DEVTOOLS == "MsDev15":
|
221 |
| - # Improve this with self._find_msbuild_tool_15 to find good >15.3 msbuild, currently only works under VS 15.3 developer environment. |
222 |
| - _xbuild = '"{0}"'.format(self._find_msbuild_tool("msbuild.exe")) |
| 222 | + _xbuild = '"{0}"'.format(self._find_msbuild_tool_15()) |
223 | 223 | _config = "{0}Win".format(CONFIG)
|
224 | 224 | _solution_file = 'pythonnet.15.sln'
|
225 | 225 | _custom_define_constants = True
|
@@ -364,6 +364,20 @@ def _find_msbuild_tool(self, tool="msbuild.exe", use_windows_sdk=False):
|
364 | 364 |
|
365 | 365 | raise RuntimeError("{0} could not be found".format(tool))
|
366 | 366 |
|
| 367 | + def _find_msbuild_tool_15(self): |
| 368 | + """Return full path to one of the Microsoft build tools""" |
| 369 | + try: |
| 370 | + basePathes = subprocess.check_output( |
| 371 | + ["vswhere", "-latest", |
| 372 | + "-version", "[15.0, 16.0)", |
| 373 | + "-requires", "Microsoft.Component.MSBuild", |
| 374 | + "-property", "InstallationPath"]).splitlines() |
| 375 | + if len(basePathes): |
| 376 | + return os.path.join(basePathes[0].decode(sys.stdout.encoding or "utf-8"), "MSBuild", "15.0", "Bin", "MSBuild.exe") |
| 377 | + else: |
| 378 | + raise RuntimeError("MSBuild >=15.0 could not be found.") |
| 379 | + except subprocess.CalledProcessError as e: |
| 380 | + raise RuntimeError("MSBuild >=15.0 could not be found. {0}".format(e.output)) |
367 | 381 |
|
368 | 382 | class InstallLibPythonnet(install_lib.install_lib):
|
369 | 383 | def install(self):
|
@@ -417,7 +431,23 @@ def run(self):
|
417 | 431 | _update_xlat_devtools()
|
418 | 432 | return install.install.run(self)
|
419 | 433 |
|
420 |
| -############################################################################### |
| 434 | +class BDistWheelPythonnet(bdist_wheel.bdist_wheel): |
| 435 | + user_options = bdist_wheel.bdist_wheel.user_options + [ |
| 436 | + ('xplat', None, None) |
| 437 | + ] |
| 438 | + def initialize_options(self): |
| 439 | + bdist_wheel.bdist_wheel.initialize_options(self) |
| 440 | + self.xplat = None |
| 441 | + |
| 442 | + def finalize_options(self): |
| 443 | + bdist_wheel.bdist_wheel.finalize_options(self) |
| 444 | + |
| 445 | + def run(self): |
| 446 | + if self.xplat: |
| 447 | + _update_xlat_devtools() |
| 448 | + return bdist_wheel.bdist_wheel.run(self) |
| 449 | + |
| 450 | + ############################################################################### |
421 | 451 | setupdir = os.path.dirname(__file__)
|
422 | 452 | if setupdir:
|
423 | 453 | os.chdir(setupdir)
|
@@ -449,6 +479,7 @@ def run(self):
|
449 | 479 | "build_ext": BuildExtPythonnet,
|
450 | 480 | "install_lib": InstallLibPythonnet,
|
451 | 481 | "install_data": InstallDataPythonnet,
|
| 482 | + "bdist_wheel": BDistWheelPythonnet |
452 | 483 | },
|
453 | 484 | classifiers=[
|
454 | 485 | 'Development Status :: 5 - Production/Stable',
|
|
0 commit comments