| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,53 +4,81 @@ | |||
| 4 | 4 | ||
| 5 | 5 | import os | |
| 6 | 6 | import sys | |
| 7 | + import shutil | ||
| 7 | 8 | from glob import glob | |
| 8 | 9 | from distutils.command.sdist import sdist | |
| 9 | 10 | from setuptools import setup, Extension | |
| 10 | 11 | ||
| 12 | + from distutils.command.build_ext import build_ext | ||
| 13 | + | ||
| 11 | 14 | try: | |
| 12 | - from Cython.Distutils import build_ext | ||
| 13 | 15 | import Cython.Compiler.Main as cython_compiler | |
| 14 | 16 | have_cython = True | |
| 15 | 17 | except ImportError: | |
| 16 | - from distutils.command.build_ext import build_ext | ||
| 17 | 18 | have_cython = False | |
| 18 | 19 | ||
| 20 | + | ||
| 21 | + def cythonize(src): | ||
| 22 | + sys.stderr.write("cythonize: %r\n" % (src,)) | ||
| 23 | + cython_compiler.compile([src]) | ||
| 24 | + | ||
| 25 | + def ensure_source(src): | ||
| 26 | + pyx = os.path.splitext(src)[0] + '.pyx' | ||
| 27 | + | ||
| 28 | + if not os.path.exists(src): | ||
| 29 | + if not have_cython: | ||
| 30 | + raise Exception("""\ | ||
| 31 | + Cython is required for building extension from checkout. | ||
| 32 | + Install Cython >= 0.16 or install msgpack from PyPI. | ||
| 33 | + """) | ||
| 34 | + cythonize(src) | ||
| 35 | + elif (os.path.exists(pyx) and | ||
| 36 | + os.stat(src).st_mtime < os.stat(pyx).st_mtime and | ||
| 37 | + have_cython): | ||
| 38 | + cythonize(src) | ||
| 39 | + | ||
| 40 | + # Use C++ compiler on win32. | ||
| 41 | + # MSVC9 doesn't provide stdint.h when using C Compiler. | ||
| 42 | + if sys.platform == 'win32': | ||
| 43 | + cpp = src + 'pp' | ||
| 44 | + shutil.copy(src, cpp) | ||
| 45 | + return cpp | ||
| 46 | + else: | ||
| 47 | + return src | ||
| 48 | + | ||
| 49 | + | ||
| 50 | + class BuildExt(build_ext): | ||
| 51 | + def build_extension(self, ext): | ||
| 52 | + ext.sources = map(ensure_source, ext.sources) | ||
| 53 | + return build_ext.build_extension(self, ext) | ||
| 54 | + | ||
| 55 | + | ||
| 19 | 56 | # make msgpack/__verison__.py | |
| 20 | 57 | f = open('msgpack/__version__.py', 'w') | |
| 21 | - f.write("version = %r\n" % (version,)) | ||
| 22 | - f.close() | ||
| 23 | - del f | ||
| 58 | + try: | ||
| 59 | + f.write("version = %r\n" % (version,)) | ||
| 60 | + finally: | ||
| 61 | + f.close() | ||
| 62 | + del f | ||
| 24 | 63 | ||
| 25 | 64 | version_str = '.'.join(str(x) for x in version[:3]) | |
| 26 | 65 | if len(version) > 3 and version[3] != 'final': | |
| 27 | 66 | version_str += version[3] | |
| 28 | 67 | ||
| 29 | 68 | # take care of extension modules. | |
| 30 | 69 | if have_cython: | |
| 31 | - sources = ['msgpack/_msgpack.pyx'] | ||
| 32 | - | ||
| 33 | 70 | class Sdist(sdist): | |
| 34 | 71 | def __init__(self, *args, **kwargs): | |
| 35 | - cy_opt = cython_compiler.default_options.copy() | ||
| 36 | - #cy_opt['cplus'] = True | ||
| 37 | 72 | for src in glob('msgpack/*.pyx'): | |
| 38 | - cython_compiler.compile(glob('msgpack/*.pyx'), cy_opt) | ||
| 73 | + cythonize(src) | ||
| 39 | 74 | sdist.__init__(self, *args, **kwargs) | |
| 40 | 75 | else: | |
| 41 | - sources = ['msgpack/_msgpack.c'] | ||
| 42 | - | ||
| 43 | - for f in sources: | ||
| 44 | - if not os.path.exists(f): | ||
| 45 | - raise ImportError("Building msgpack from VCS needs Cython. Install Cython or use sdist package.") | ||
| 46 | - | ||
| 47 | 76 | Sdist = sdist | |
| 48 | 77 | ||
| 78 | + sources = ['msgpack/_msgpack.c'] | ||
| 49 | 79 | libraries = [] | |
| 50 | - language = 'c' | ||
| 51 | 80 | if sys.platform == 'win32': | |
| 52 | 81 | libraries.append('ws2_32') | |
| 53 | - language = 'c++' | ||
| 54 | 82 | ||
| 55 | 83 | if sys.byteorder == 'big': | |
| 56 | 84 | macros = [('__BIG_ENDIAN__', '1')] | |
@@ -61,10 +89,9 @@ def __init__(self, *args, **kwargs): | |||
| 61 | 89 | sources=sources, | |
| 62 | 90 | libraries=libraries, | |
| 63 | 91 | include_dirs=['.'], | |
| 64 | - language=language, | ||
| 65 | 92 | define_macros=macros, | |
| 66 | 93 | ) | |
| 67 | - del sources, libraries, language, macros | ||
| 94 | + del sources, libraries, macros | ||
| 68 | 95 | ||
| 69 | 96 | ||
| 70 | 97 | desc = 'MessagePack (de)serializer.' | |
@@ -77,7 +104,7 @@ def __init__(self, *args, **kwargs): | |||
| 77 | 104 | author='INADA Naoki', | |
| 78 | 105 | author_email='songofacandy@gmail.com', | |
| 79 | 106 | version=version_str, | |
| 80 | - cmdclass={'build_ext': build_ext, 'sdist': Sdist}, | ||
| 107 | + cmdclass={'build_ext': BuildExt, 'sdist': Sdist}, | ||
| 81 | 108 | ext_modules=[msgpack_mod], | |
| 82 | 109 | packages=['msgpack'], | |
| 83 | 110 | description=desc, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments