From 8724bc9f043ef30c9b6adf934c3f2bbec8937107 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 29 Jul 2013 01:38:01 +0000 Subject: [PATCH] [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. --- interfaces/cython/setup.py.in | 36 +++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/interfaces/cython/setup.py.in b/interfaces/cython/setup.py.in index 6c76cde8b..2a0c84535 100644 --- a/interfaces/cython/setup.py.in +++ b/interfaces/cython/setup.py.in @@ -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")