Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses cython only if present. #8

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
51 changes: 20 additions & 31 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -68,4 +58,3 @@ def del_include_dirs(self):
],
cmdclass={'build_ext': custom_build_ext},
)