| 
									
										
										
										
											2009-06-24 14:33:36 +09:00
										 |  |  | #!/usr/bin/env python | 
					
						
							|  |  |  | # coding: utf-8 | 
					
						
							| 
									
										
										
										
											2009-06-10 10:45:07 +09:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2010-11-03 03:35:52 +09:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2010-01-25 20:52:48 +09:00
										 |  |  | from glob import glob | 
					
						
							|  |  |  | from distutils.command.sdist import sdist | 
					
						
							| 
									
										
										
										
											2012-06-27 18:16:59 +09:00
										 |  |  | from setuptools import setup, Extension | 
					
						
							| 
									
										
										
										
											2010-01-25 20:52:48 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 02:53:16 +09:00
										 |  |  | from distutils.command.build_ext import build_ext | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 12:27:46 +01:00
										 |  |  | class NoCython(Exception): | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-25 20:52:48 +09:00
										 |  |  | try: | 
					
						
							|  |  |  |     import Cython.Compiler.Main as cython_compiler | 
					
						
							|  |  |  |     have_cython = True | 
					
						
							|  |  |  | except ImportError: | 
					
						
							|  |  |  |     have_cython = False | 
					
						
							| 
									
										
										
										
											2009-06-08 01:43:50 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 02:53:16 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | def cythonize(src): | 
					
						
							|  |  |  |     sys.stderr.write("cythonize: %r\n" % (src,)) | 
					
						
							| 
									
										
										
										
											2012-10-01 01:31:58 +09:00
										 |  |  |     cython_compiler.compile([src], cplus=True, emit_linenums=True) | 
					
						
							| 
									
										
										
										
											2012-08-19 02:53:16 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | def ensure_source(src): | 
					
						
							|  |  |  |     pyx = os.path.splitext(src)[0] + '.pyx' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if not os.path.exists(src): | 
					
						
							|  |  |  |         if not have_cython: | 
					
						
							| 
									
										
										
										
											2013-01-28 12:27:46 +01:00
										 |  |  |             raise NoCython | 
					
						
							| 
									
										
										
										
											2012-08-21 14:56:32 +09:00
										 |  |  |         cythonize(pyx) | 
					
						
							| 
									
										
										
										
											2012-08-19 02:53:16 +09:00
										 |  |  |     elif (os.path.exists(pyx) and | 
					
						
							|  |  |  |           os.stat(src).st_mtime < os.stat(pyx).st_mtime and | 
					
						
							|  |  |  |           have_cython): | 
					
						
							| 
									
										
										
										
											2012-08-21 14:56:32 +09:00
										 |  |  |         cythonize(pyx) | 
					
						
							| 
									
										
										
										
											2012-11-06 09:37:55 +09:00
										 |  |  |     return src | 
					
						
							| 
									
										
										
										
											2012-08-19 02:53:16 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BuildExt(build_ext): | 
					
						
							|  |  |  |     def build_extension(self, ext): | 
					
						
							| 
									
										
										
										
											2013-01-28 12:27:46 +01:00
										 |  |  |         try: | 
					
						
							|  |  |  |             ext.sources = list(map(ensure_source, ext.sources)) | 
					
						
							|  |  |  |         except NoCython: | 
					
						
							| 
									
										
										
										
											2013-01-28 14:32:01 +01:00
										 |  |  |             print("WARNING") | 
					
						
							|  |  |  |             print("Cython is required for building extension from checkout.") | 
					
						
							|  |  |  |             print("Install Cython >= 0.16 or install msgpack from PyPI.") | 
					
						
							|  |  |  |             print("Falling back to pure Python implementation.") | 
					
						
							| 
									
										
										
										
											2013-01-28 12:27:46 +01:00
										 |  |  |             return | 
					
						
							| 
									
										
										
										
											2013-02-03 00:52:05 +09:00
										 |  |  |         try: | 
					
						
							|  |  |  |             return build_ext.build_extension(self, ext) | 
					
						
							|  |  |  |         except Exception as e: | 
					
						
							|  |  |  |             print("WARNING: Failed to compile extensiom modules.") | 
					
						
							|  |  |  |             print("msgpack uses fallback pure python implementation.") | 
					
						
							|  |  |  |             print(e) | 
					
						
							| 
									
										
										
										
											2012-08-19 02:53:16 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 04:17:56 +09:00
										 |  |  | exec(open('msgpack/_version.py').read()) | 
					
						
							| 
									
										
										
										
											2011-01-09 23:58:26 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-02 10:10:34 +09:00
										 |  |  | version_str = '.'.join(str(x) for x in version[:3]) | 
					
						
							|  |  |  | if len(version) > 3 and version[3] != 'final': | 
					
						
							|  |  |  |     version_str += version[3] | 
					
						
							| 
									
										
										
										
											2009-06-08 01:43:50 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-25 20:52:48 +09:00
										 |  |  | # take care of extension modules. | 
					
						
							|  |  |  | if have_cython: | 
					
						
							|  |  |  |     class Sdist(sdist): | 
					
						
							|  |  |  |         def __init__(self, *args, **kwargs): | 
					
						
							|  |  |  |             for src in glob('msgpack/*.pyx'): | 
					
						
							| 
									
										
										
										
											2012-08-19 02:53:16 +09:00
										 |  |  |                 cythonize(src) | 
					
						
							| 
									
										
										
										
											2010-01-25 20:52:48 +09:00
										 |  |  |             sdist.__init__(self, *args, **kwargs) | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  |     Sdist = sdist | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-18 19:02:11 +01:00
										 |  |  | libraries = [] | 
					
						
							|  |  |  | if sys.platform == 'win32': | 
					
						
							|  |  |  |     libraries.append('ws2_32') | 
					
						
							| 
									
										
										
										
											2012-08-19 01:05:41 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | if sys.byteorder == 'big': | 
					
						
							|  |  |  |     macros = [('__BIG_ENDIAN__', '1')] | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  |     macros = [('__LITTLE_ENDIAN__', '1')] | 
					
						
							| 
									
										
										
										
											2010-11-03 03:35:52 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 22:15:21 +09:00
										 |  |  | ext_modules = [] | 
					
						
							| 
									
										
										
										
											2013-02-03 00:11:26 +09:00
										 |  |  | if not hasattr(sys, 'pypy_version_info'): | 
					
						
							|  |  |  |     ext_modules.append(Extension('msgpack._packer', | 
					
						
							|  |  |  |                                  sources=['msgpack/_packer.cpp'], | 
					
						
							|  |  |  |                                  libraries=libraries, | 
					
						
							|  |  |  |                                  include_dirs=['.'], | 
					
						
							|  |  |  |                                  define_macros=macros, | 
					
						
							|  |  |  |                                  )) | 
					
						
							|  |  |  |     ext_modules.append(Extension('msgpack._unpacker', | 
					
						
							|  |  |  |                                  sources=['msgpack/_unpacker.cpp'], | 
					
						
							|  |  |  |                                  libraries=libraries, | 
					
						
							|  |  |  |                                  include_dirs=['.'], | 
					
						
							|  |  |  |                                  define_macros=macros, | 
					
						
							| 
									
										
										
										
											2013-10-19 17:27:16 +02:00
										 |  |  |                                  extra_compile_args=['-O0'], | 
					
						
							| 
									
										
										
										
											2013-02-03 00:11:26 +09:00
										 |  |  |                                  )) | 
					
						
							| 
									
										
										
										
											2012-12-11 22:15:21 +09:00
										 |  |  | del libraries, macros | 
					
						
							| 
									
										
										
										
											2010-01-25 20:52:48 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-08 01:43:50 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-12 09:29:11 +09:00
										 |  |  | desc = 'MessagePack (de)serializer.' | 
					
						
							| 
									
										
										
										
											2012-06-27 18:05:35 +09:00
										 |  |  | f = open('README.rst') | 
					
						
							|  |  |  | long_desc = f.read() | 
					
						
							|  |  |  | f.close() | 
					
						
							|  |  |  | del f | 
					
						
							| 
									
										
										
										
											2009-06-08 01:43:50 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-29 07:52:32 +09:00
										 |  |  | setup(name='msgpack-python', | 
					
						
							| 
									
										
										
										
											2010-01-25 20:52:48 +09:00
										 |  |  |       author='INADA Naoki', | 
					
						
							| 
									
										
										
										
											2009-06-08 01:43:50 +09:00
										 |  |  |       author_email='songofacandy@gmail.com', | 
					
						
							| 
									
										
										
										
											2010-09-02 10:10:34 +09:00
										 |  |  |       version=version_str, | 
					
						
							| 
									
										
										
										
											2012-08-19 02:53:16 +09:00
										 |  |  |       cmdclass={'build_ext': BuildExt, 'sdist': Sdist}, | 
					
						
							| 
									
										
										
										
											2012-12-11 22:15:21 +09:00
										 |  |  |       ext_modules=ext_modules, | 
					
						
							| 
									
										
										
										
											2009-06-24 01:13:22 +09:00
										 |  |  |       packages=['msgpack'], | 
					
						
							| 
									
										
										
										
											2009-06-08 13:21:38 +09:00
										 |  |  |       description=desc, | 
					
						
							| 
									
										
										
										
											2009-06-08 01:43:50 +09:00
										 |  |  |       long_description=long_desc, | 
					
						
							| 
									
										
										
										
											2011-01-10 00:10:29 +09:00
										 |  |  |       url='http://msgpack.org/', | 
					
						
							| 
									
										
										
										
											2010-04-29 07:08:41 +09:00
										 |  |  |       download_url='http://pypi.python.org/pypi/msgpack/', | 
					
						
							| 
									
										
										
										
											2009-07-12 09:29:11 +09:00
										 |  |  |       classifiers=[ | 
					
						
							| 
									
										
										
										
											2010-11-03 03:35:52 +09:00
										 |  |  |           'Programming Language :: Python :: 2', | 
					
						
							| 
									
										
										
										
											2010-09-02 10:13:49 +09:00
										 |  |  |           'Programming Language :: Python :: 3', | 
					
						
							| 
									
										
										
										
											2009-07-12 09:29:11 +09:00
										 |  |  |           'Intended Audience :: Developers', | 
					
						
							|  |  |  |           'License :: OSI Approved :: Apache Software License', | 
					
						
							|  |  |  |           ] | 
					
						
							| 
									
										
										
										
											2009-06-08 01:43:50 +09:00
										 |  |  |       ) |