diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2017-10-07 15:35:44 +0200 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2017-10-07 15:35:44 +0200 |
| commit | 3e269c1c6369af3ffbae031d096c29cb9f0a1e76 (patch) | |
| tree | 7c3e09162e65e42bb151b2fb224ced5e184e7f2e | |
| parent | update submodule (diff) | |
| download | pygensvm-3e269c1c6369af3ffbae031d096c29cb9f0a1e76.tar.gz pygensvm-3e269c1c6369af3ffbae031d096c29cb9f0a1e76.zip | |
rearrange and update setup.py
| -rw-r--r-- | .gitmodules | 2 | ||||
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | setup.py | 56 | ||||
| m--------- | src/gensvm (renamed from gensvm/src/gensvm) | 0 | ||||
| -rw-r--r-- | src/pyx_gensvm.pxd (renamed from gensvm/pyx_gensvm.pxd) | 0 | ||||
| -rw-r--r-- | src/pyx_gensvm.pyx (renamed from gensvm/pyx_gensvm.pyx) | 0 |
6 files changed, 45 insertions, 15 deletions
diff --git a/.gitmodules b/.gitmodules index 130a83c..084eddf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "gensvm/src/gensvm"] - path = gensvm/src/gensvm + path = src/gensvm url = https://github.com/GjjvdBurg/GenSVM @@ -28,7 +28,7 @@ install2: ## Install for the current user using the python2 command python2 setup.py build_ext --inplace python2 setup.py install --user -test: develop ## Run nosetests using the default nosetests command +test: in ## Run nosetests using the default nosetests command nosetests -v test2: develop2 ## Run nosetests using the nosetests2 command @@ -7,41 +7,71 @@ import numpy from numpy.distutils.core import setup from numpy.distutils.misc_util import Configuration -from sklearn._build_utils import get_blas_info, maybe_cythonize_extensions +from sklearn._build_utils import get_blas_info +# Set this to True to enable building extensions using Cython. Set it to False· +# to build extensions from the C file (that was previously generated using· +# Cython). Set it to 'auto' to build with Cython if available, otherwise from· +# the C file. +USE_CYTHON = 'auto' -def configuration(parent_package='', top_path=None): - config = Configuration('gensvm', parent_package, top_path) +# If we are in a release, we always never use Cython directly +IS_RELEASE = os.path.exists('PKG-INFO') +if IS_RELEASE: + USE_CYTHON = False + +# If we do want to use Cython, we double check if it is available +if USE_CYTHON: + try: + from Cython.Build import cythonize + except ImportError: + if USE_CYTHON == 'auto': + USE_CYTHON = False + else: + raise + + +def configuration(): + config = Configuration('gensvm', '', None) - # gensvm module cblas_libs, blas_info = get_blas_info() if os.name == 'posix': cblas_libs.append('m') + # Wrapper code in Cython uses the .pyx extension if we want to USE_CYTHON, + # otherwise it ends in .c. If you have more Cython code, you may want to + # extend this a bit + wrapper = 'pyx_gensvm.pyx' if USE_CYTHON else 'pyx_gensvm.c' + + # Sources include the C/Cython code from the wrapper and the source code of + # the C library gensvm_sources = [ - os.path.join('gensvm', 'pyx_gensvm.pyx'), - os.path.join('gensvm', 'src', 'gensvm', 'src', '*.c'), + os.path.join('src', wrapper), + os.path.join('src', 'gensvm', 'src', '*.c'), ] + # Dependencies are the header files of the C library and any potential + # helper code between the library and the Cython code gensvm_depends = [ - os.path.join('gensvm', 'src', 'gensvm', 'include', '*.h'), - os.path.join('gensvm', 'src', 'gensvm', 'gensvm_helper.c') + os.path.join('src', 'gensvm', 'include', '*.h'), + os.path.join('src', 'gensvm', 'gensvm_helper.c') ] config.add_extension('pyx_gensvm', sources=gensvm_sources, libraries=cblas_libs, include_dirs=[ - os.path.join('gensvm', 'src', 'gensvm'), - os.path.join('gensvm', 'src', 'gensvm', 'include'), + os.path.join('src', 'gensvm'), + os.path.join('src', 'gensvm', 'include'), numpy.get_include(), blas_info.pop('include_dirs', [])], extra_compile_args=blas_info.pop('extra_compile_args', []), depends=gensvm_depends, **blas_info) - # end gensvm module - maybe_cythonize_extensions(top_path, config) + # Cythonize if necessary + if USE_CYTHON: + config.ext_modules = cythonize(config.ext_modules) return config @@ -55,7 +85,7 @@ if __name__ == '__main__': version = re.search("__version__ = '([^']+)'", open('gensvm/__init__.py').read()).group(1) - attr = configuration(top_path='').todict() + attr = configuration().todict() attr['description'] = 'Python package for the GenSVM classifier' attr['long_description'] = read('README.rst') diff --git a/gensvm/src/gensvm b/src/gensvm -Subproject 1f32ecf1d2414bf8e8107a95552c1164498a977 +Subproject 1f32ecf1d2414bf8e8107a95552c1164498a977 diff --git a/gensvm/pyx_gensvm.pxd b/src/pyx_gensvm.pxd index be4d5f5..be4d5f5 100644 --- a/gensvm/pyx_gensvm.pxd +++ b/src/pyx_gensvm.pxd diff --git a/gensvm/pyx_gensvm.pyx b/src/pyx_gensvm.pyx index 394d4ca..394d4ca 100644 --- a/gensvm/pyx_gensvm.pyx +++ b/src/pyx_gensvm.pyx |
