From 8e522a5363349e6cf98daf1c5ae95e6915ba0c72 Mon Sep 17 00:00:00 2001 From: Paul McCarthy Date: Sun, 16 Oct 2016 12:42:10 +0100 Subject: [PATCH] Reworked setup.py a bit so it does not depend on cython or numpy. Version bump. --- MANIFEST.in | 9 ++++ setup.py | 127 ++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 113 insertions(+), 23 deletions(-) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..18d99613 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,9 @@ +include *.c +include *.h +include *.pyx +include *.pxd +recursive-include tests *.py +recursive-include tests *.pyx +recursive-include tests *.c +exclude bench_plot.py +exclude benchmark_indexed_gzip.py diff --git a/setup.py b/setup.py index aaaaddbd..1c229644 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,111 @@ #!/usr/bin/env python -from setuptools import setup -from setuptools import Extension -from Cython.Build import cythonize +import os +import os.path as op +import shutil -import numpy as np +from setuptools import setup +from setuptools import Extension +from setuptools import Command + + +# Custom 'clean' command +class Clean(Command): + + user_options = [] + + def initialize_options(self): pass + def finalize_options( self): pass + + def run(self): + + shutil.rmtree('build', ignore_errors=True) + shutil.rmtree('dist', ignore_errors=True) + shutil.rmtree('indexed_gzip.egg-info', ignore_errors=True) + shutil.rmtree('.eggs', ignore_errors=True) + + files = [ + 'indexed_gzip.c', + 'setup.pyc', + op.join('tests', 'ctest_zran.c'), + op.join('tests', 'ctest_indexed_gzip.c'), + op.join('tests', '__init__.pyc'), + op.join('tests', 'conftest.pyc'), + op.join('tests', 'test_zran.pyc'), + op.join('tests', 'test_indexed_gzip.pyc')] + + for f in files: + try: os.remove(f) + except OSError: pass + + +# If cython is present, we'll compile +# the pyx files from scratch. Otherwise, +# we'll compile the pre-generated c +# files (which are assumed to be present). + +# We only need numpy to +# compile the test modules +have_cython = True +have_numpy = True + + +try: from Cython.Build import cythonize +except: have_cython = False + +try: import numpy as np +except: have_numpy = False + + +# If numpy is present, we need +# to include the headers +include_dirs = ['.'] +if have_numpy: + include_dirs.append(np.get_include()) + + +# Compile from cython files if +# possible, or compile from c. +if have_cython: pyx_extension = 'pyx' +else: pyx_extension = 'c' + + +# The indexed_gzip module +igzip_ext = Extension( + 'indexed_gzip', + ['indexed_gzip.{}'.format(pyx_extension), 'zran.c'], + libraries=['z'], + extra_compile_args=['-Wno-unused-function']) + +# Optional test modules +test_exts = [ + Extension( + 'tests.ctest_zran', + ['tests/ctest_zran.{}'.format(pyx_extension), 'zran.c'], + libraries=['z'], + include_dirs=include_dirs, + extra_compile_args=['-Wno-unused-function']), + Extension( + 'tests.ctest_indexed_gzip', + ['tests/ctest_indexed_gzip.{}'.format(pyx_extension)], + libraries=['z'], + include_dirs=include_dirs, + extra_compile_args=['-Wno-unused-function'])] + + +# If we have numpy, we can compile the tests +if have_numpy: extensions = [igzip_ext] + test_exts +else: extensions = [igzip_ext] + + +# Cythonize if we can +if have_cython: + extensions = cythonize(extensions) setup( name='indexed_gzip', - version='0.2', + version='0.3', author='Paul McCarthy', author_email='pauldmccarthy@gmail.com', description='Fast random access of gzip files in Python', @@ -26,25 +122,10 @@ 'Programming Language :: Python :: 3', 'Topic :: System :: Archiving :: Compression', ], + + cmdclass={'clean' : Clean}, - ext_modules=cythonize([ - Extension('indexed_gzip', - ['indexed_gzip.pyx', 'zran.c'], - libraries=['z'], - extra_compile_args=['-Wno-unused-function']), - - Extension('tests.ctest_zran', - ['tests/ctest_zran.pyx', 'zran.c'], - libraries=['z'], - include_dirs=['.', np.get_include()], - extra_compile_args=['-Wno-unused-function']), - - Extension('tests.ctest_indexed_gzip', - ['tests/ctest_indexed_gzip.pyx'], - libraries=['z'], - include_dirs=['.'], - extra_compile_args=['-Wno-unused-function']) - ]), + ext_modules=extensions, setup_requires=['pytest-runner'], tests_require=['pytest', 'numpy'],