diff --git a/.travis.yml b/.travis.yml index 5f6f052..7ebbb8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,15 +15,21 @@ matrix: - python: 2.7 - os: osx language: generic + before_install: + - brew update + - brew upgrade python + - brew install python2 + - pip install virtualenv + - python2 -m virtualenv env + - source env/bin/activate - os: osx language: generic before_install: - - brew update - - brew install python3 - - virtualenv env -p python3 - - source env/bin/activate - - sudo: required - services: + - brew update + - brew upgrade python + - python3 -m venv env + - source env/bin/activate + - services: - docker env: DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64 install: @@ -34,8 +40,7 @@ matrix: - if [[ $TRAVIS_TAG ]]; then pip install twine && twine upload -u datamade.wheelbuilder -p $PYPIPASSWORD --skip-existing wheelhouse/*; fi - exit 0 - - sudo: required - services: + - services: - docker env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686 install: @@ -48,9 +53,7 @@ matrix: - exit 0 install: - pip install --upgrade pip -- pip install numpy -- pip freeze -- pip install --upgrade -r requirements.txt +- pip install -r requirements.txt - cython lbfgs/_lowlevel.pyx - pip install -e . script: diff --git a/setup.py b/setup.py index bf71909..eae0220 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,15 @@ from setuptools import setup, Extension from setuptools.command.build_ext import build_ext from distutils.ccompiler import get_default_compiler +import numpy + +try: + from Cython.Build import cythonize + + use_cython = True +except ImportError: + use_cython = False + class custom_build_ext(build_ext): def finalize_options(self): @@ -16,34 +25,17 @@ def finalize_options(self): include_dirs.append('compat/win32') +include_dirs = ['liblbfgs'] + [numpy.get_include()] -# from Michael Hoffman's http://www.ebi.ac.uk/~hoffman/software/sunflower/ -class NumpyExtension(Extension): - - def __init__(self, *args, **kwargs): - Extension.__init__(self, *args, **kwargs) - - self._include_dirs = self.include_dirs - del self.include_dirs # restore overwritten property - - # warning: Extension is a classic class so it's not really read-only - - def get_include_dirs(self): - from numpy import get_include - - return self._include_dirs + [get_include()] - - def set_include_dirs(self, value): - self._include_dirs = value - - def del_include_dirs(self): - pass - - include_dirs = property(get_include_dirs, - set_include_dirs, - del_include_dirs) - -include_dirs = ['liblbfgs'] +if use_cython: + ext_modules = cythonize( + [Extension('lbfgs._lowlevel', + ['lbfgs/_lowlevel.pyx', 'liblbfgs/lbfgs.c'], + include_dirs=include_dirs)]) +else: + ext_modules = [Extension('lbfgs._lowlevel', + ['lbfgs/_lowlevel.c', 'liblbfgs/lbfgs.c'], + include_dirs=include_dirs)] setup( name="PyLBFGS", @@ -53,9 +45,7 @@ def del_include_dirs(self): author_email="fgregg@gmail.com", packages=['lbfgs'], install_requires=['numpy>=1.12.1'], - ext_modules=[NumpyExtension('lbfgs._lowlevel', - ['lbfgs/_lowlevel.c', 'liblbfgs/lbfgs.c'], - include_dirs=include_dirs)], + ext_modules=ext_modules, classifiers=[ "Intended Audience :: Developers", "Intended Audience :: Science/Research", @@ -68,4 +58,3 @@ def del_include_dirs(self): ], cmdclass={'build_ext': custom_build_ext}, ) -