[Cython] Fix generation of MSI installer when using Python 2.x

The old patch to distutils only worked on Python 3.x, since distutils
uses old-style classes which do not support property objects.
This commit is contained in:
Ray Speth 2013-07-29 01:38:01 +00:00
parent f320290c51
commit 8724bc9f04

View file

@ -2,19 +2,35 @@ import os
from distutils.core import setup
from Cython.Build import cythonize
from distutils.command.build import build
def get_build_lib(self):
return self._build_lib
def set_build_lib(self, val):
if val is None or self._build_lib is None:
self._build_lib = val
# Monkey patch to prevent bdist_msi from incorrectly overwriting the value of
# build-lib specified on the command line.
# See http://bugs.python.org/issue1109963
build.build_lib = property(get_build_lib, set_build_lib)
# This patch works by returning False the first time that the
# 'has_ext_modules' method is called in bdist_msi.run, which is where the
# replacement of build_lib happens. Subsequent calls to 'has_ext_modules'
# should use the correct value so that the resulting installer is specific to
# this Python version. Known to affect Python versions 2.6 through 3.3. If
# this bug is ever fixed, this patch should be made conditional on the Python
# version.
if os.name == 'nt':
from distutils.command.bdist_msi import bdist_msi
bdist_run_orig = bdist_msi.run
def bdist_run_new(self):
has_ext_modules_orig = self.distribution.has_ext_modules
self._first_call = True
def has_ext_modules():
if self._first_call:
self._first_call = False
return False
else:
return has_ext_modules_orig()
self.distribution.has_ext_modules = has_ext_modules
return bdist_run_orig(self)
bdist_msi.run = bdist_run_new
exts = cythonize("cantera/_cantera.pyx")