summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorINADA Naoki <inada-n@klab.com>2012-08-19 02:53:16 +0900
committerINADA Naoki <inada-n@klab.com>2012-08-19 02:53:16 +0900
commit670bb3ca154d5f86fe72fe34a73d0ca8b7bd315a (patch)
treebe14479bf61e9bf1f7944a6ba0f3d0d3b8bbdee8 /setup.py
parent7c03f322fa73901620b2cd188186003dd9e02841 (diff)
downloadmsgpack-python-670bb3ca154d5f86fe72fe34a73d0ca8b7bd315a.tar.gz
Use C++ compiler on win32.
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py69
1 files changed, 48 insertions, 21 deletions
diff --git a/setup.py b/setup.py
index 7d8a5d4..074700b 100644
--- a/setup.py
+++ b/setup.py
@@ -4,23 +4,62 @@ version = (0, 2, 1, 'dev1')
import os
import sys
+import shutil
from glob import glob
from distutils.command.sdist import sdist
from setuptools import setup, Extension
+from distutils.command.build_ext import build_ext
+
try:
- from Cython.Distutils import build_ext
import Cython.Compiler.Main as cython_compiler
have_cython = True
except ImportError:
- from distutils.command.build_ext import build_ext
have_cython = False
+
+def cythonize(src):
+ sys.stderr.write("cythonize: %r\n" % (src,))
+ cython_compiler.compile([src])
+
+def ensure_source(src):
+ pyx = os.path.splitext(src)[0] + '.pyx'
+
+ if not os.path.exists(src):
+ if not have_cython:
+ raise Exception("""\
+Cython is required for building extension from checkout.
+Install Cython >= 0.16 or install msgpack from PyPI.
+""")
+ cythonize(src)
+ elif (os.path.exists(pyx) and
+ os.stat(src).st_mtime < os.stat(pyx).st_mtime and
+ have_cython):
+ cythonize(src)
+
+ # Use C++ compiler on win32.
+ # MSVC9 doesn't provide stdint.h when using C Compiler.
+ if sys.platform == 'win32':
+ cpp = src + 'pp'
+ shutil.copy(src, cpp)
+ return cpp
+ else:
+ return src
+
+
+class BuildExt(build_ext):
+ def build_extension(self, ext):
+ ext.sources = map(ensure_source, ext.sources)
+ return build_ext.build_extension(self, ext)
+
+
# make msgpack/__verison__.py
f = open('msgpack/__version__.py', 'w')
-f.write("version = %r\n" % (version,))
-f.close()
-del f
+try:
+ f.write("version = %r\n" % (version,))
+finally:
+ f.close()
+ del f
version_str = '.'.join(str(x) for x in version[:3])
if len(version) > 3 and version[3] != 'final':
@@ -28,29 +67,18 @@ if len(version) > 3 and version[3] != 'final':
# take care of extension modules.
if have_cython:
- sources = ['msgpack/_msgpack.pyx']
-
class Sdist(sdist):
def __init__(self, *args, **kwargs):
- cy_opt = cython_compiler.default_options.copy()
- #cy_opt['cplus'] = True
for src in glob('msgpack/*.pyx'):
- cython_compiler.compile(glob('msgpack/*.pyx'), cy_opt)
+ cythonize(src)
sdist.__init__(self, *args, **kwargs)
else:
- sources = ['msgpack/_msgpack.c']
-
- for f in sources:
- if not os.path.exists(f):
- raise ImportError("Building msgpack from VCS needs Cython. Install Cython or use sdist package.")
-
Sdist = sdist
+sources = ['msgpack/_msgpack.c']
libraries = []
-language = 'c'
if sys.platform == 'win32':
libraries.append('ws2_32')
- language = 'c++'
if sys.byteorder == 'big':
macros = [('__BIG_ENDIAN__', '1')]
@@ -61,10 +89,9 @@ msgpack_mod = Extension('msgpack._msgpack',
sources=sources,
libraries=libraries,
include_dirs=['.'],
- language=language,
define_macros=macros,
)
-del sources, libraries, language, macros
+del sources, libraries, macros
desc = 'MessagePack (de)serializer.'
@@ -77,7 +104,7 @@ setup(name='msgpack-python',
author='INADA Naoki',
author_email='songofacandy@gmail.com',
version=version_str,
- cmdclass={'build_ext': build_ext, 'sdist': Sdist},
+ cmdclass={'build_ext': BuildExt, 'sdist': Sdist},
ext_modules=[msgpack_mod],
packages=['msgpack'],
description=desc,