-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked setup.py a bit so it does not depend on cython or
numpy. Version bump.
- Loading branch information
1 parent
c4173e9
commit 8e522a5
Showing
2 changed files
with
113 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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='[email protected]', | ||
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'], | ||
|