diff --git a/MANIFEST.in b/MANIFEST.in index 6485e4c..ba72bed 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ recursive-include cystatsd *.hpp recursive-include cystatsd *.pyx recursive-include cystatsd *.pxd +recursive-include cystatsd *.cpp diff --git a/Makefile b/Makefile index d9260c2..42fceac 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ clean: rm -rf build dist - rm -f cystatsd/collector/collector.cpp MANIFEST *.egg-info *.tar.gz + rm -f cystatsd/collector/collector.cpp MANIFEST *.egg-info *.tar.gz test: clean python setup.py install diff --git a/setup.py b/setup.py index 57c40b8..ab6e5de 100644 --- a/setup.py +++ b/setup.py @@ -1,18 +1,49 @@ -from Cython.Build import cythonize from distutils.core import setup, Extension +from distutils.command.sdist import sdist as _sdist +import copy + +try: + from Cython.Build import cythonize +except ImportError: + use_cython = False +else: + use_cython = True OPTIMIZED = '-O2' UNOPTIMIZED = '-O0' OPTIMIZATION = OPTIMIZED -STATS_EXT = cythonize(Extension("cystatsd.collector.collector", sources=[ - "cystatsd/collector/collector.pyx", - "cystatsd/collector/statsd_proto.cpp" - ], - language="c++", - include_dirs=["cystatsd/collector"], - extra_compile_args=[OPTIMIZATION, "--std=c++11"] -)) + +extension = Extension( + "cystatsd.collector.collector", + sources = [ + "cystatsd/collector/collector.pyx", + "cystatsd/collector/statsd_proto.cpp", + ], + language="c++", + include_dirs=["cystatsd/collector"], + extra_compile_args=[OPTIMIZATION, "--std=c++11"] +) + + +if use_cython: + STATS_EXT = cythonize(extension) +else: + extension_copy = copy.deepcopy(extension) + extension_copy.sources = [ + "cystatsd/collector/statsd_proto.cpp", + "cystatsd/collector/collector.cpp", + ] + STATS_EXT = [extension_copy] + + +class sdist(_sdist): + def run(self): + # Make sure the compiled Cython files in the distribution are up-to-date + from Cython.Build import cythonize + cythonize(extension) + _sdist.run(self) + setup( name='cystatsd', @@ -27,11 +58,14 @@ author_email='scott.ivey@gmail.com', license='MIT', package_data={ - 'cystatsd': ['*.pyx', '*.pxd', '*.hpp', '*.pxd', '*.py'] + 'cystatsd': ['*.pyx', '*.pxd', '*.hpp', '*.pxd', '*.py', '*.cpp'] }, packages=[ 'cystatsd', 'cystatsd.collector' ], ext_modules=STATS_EXT, - provides=['cystatsd'] + provides=['cystatsd'], + cmdclass={ + 'sdist': sdist + }, )