Skip to content

Commit

Permalink
Make proper sdist and make setup.py able to boostrap numpy and cython
Browse files Browse the repository at this point in the history
  • Loading branch information
nvictus committed Sep 20, 2018
1 parent f63d9aa commit 0687908
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 38 deletions.
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
include LICENSE
include README.md
include Makefile
graft tests
graft include
graft src

global-include *.pyx
global-include *.pxd

global-exclude __pycache__/*
global-exclude *.o
global-exclude *.a
Expand Down
111 changes: 73 additions & 38 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,51 @@
# -*- coding: utf-8 -*-
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as _build_ext
from Cython.Build import cythonize
from subprocess import check_call
import os.path as op
import numpy as np
import sys
import os
import re
import io


thisdir = op.dirname(op.realpath(__file__))


def read(*parts, **kwargs):
encoding = kwargs.pop('encoding', 'utf-8')
filepath = op.join(op.dirname(__file__), *parts)
return io.open(filepath, encoding=encoding).read()


def get_version(pkg):
version = re.search(
r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
read(pkg, '__init__.py'),
re.MULTILINE).group(1)
return version


class lazy_list(list):
'''
Used to delay cython import until all setup_requires have been installed.
'''
def __init__(self, callback):
self._list, self.callback = None, callback
def c_list(self):
if self._list is None:
self._list = self.callback()
return self._list
def __iter__(self):
for e in self.c_list():
yield e
def __getitem__(self, i):
return self.c_list()[i]
def __len__(self):
return len(self.c_list())


# Paths to propagate to make to build libkent
extra_library_dirs = []
extra_include_dirs = []
Expand Down Expand Up @@ -45,43 +78,40 @@ def run(self):
print("LIBRARY_PATH: " + os.environ.get("LIBRARY_PATH", ""), file=sys.stderr)
print("C_INCLUDE_PATH: " + os.environ.get("C_INCLUDE_PATH", ""), file=sys.stderr)
check_call(['make', 'build-c'])

# Now, proceed to build extension modules
_build_ext.run(self)


ext_modules = [
Extension(
name='bbi.cbbi',
sources=[
op.join(thisdir, 'bbi/cbbi.pyx')
],
library_dirs=[
op.join(thisdir, 'src/x86_64'),
] + extra_library_dirs,
libraries=[
'c', 'z', 'pthread', 'kent',
],
include_dirs=[
np.get_include(),
op.join(thisdir, 'include'),
] + extra_include_dirs,
),
]


def read(*parts, **kwargs):
encoding = kwargs.pop('encoding', 'utf-8')
filepath = op.join(op.dirname(__file__), *parts)
return io.open(filepath, encoding=encoding).read()


def get_version(pkg):
version = re.search(
r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
read(pkg, '__init__.py'),
re.MULTILINE).group(1)
return version
def finalize_options(self):
_build_ext.finalize_options(self)
# Fix to work with bootstrapped numpy installation
# http://stackoverflow.com/a/21621689/579416
# Prevent numpy from thinking it is still in its setup process:
__builtins__.__NUMPY_SETUP__ = False
import numpy
self.include_dirs.append(numpy.get_include())


def get_ext_modules():
from Cython.Build import cythonize
ext_modules = [
Extension(
name='bbi.cbbi',
sources=[
op.join(thisdir, 'bbi/cbbi.pyx')
],
library_dirs=[
op.join(thisdir, 'src/x86_64'),
] + extra_library_dirs,
libraries=[
'c', 'z', 'pthread', 'kent',
],
include_dirs=[
#np.get_include(),
op.join(thisdir, 'include'),
] + extra_include_dirs,
),
]
return cythonize(ext_modules)


setup(
Expand All @@ -90,9 +120,14 @@ def get_version(pkg):
version=get_version('bbi'),
packages=['bbi'],
zip_safe=False,
install_requires=['numpy', 'cython'],
setup_requires=[
'setuptools>=18.0',
'cython',
'numpy',
],
install_requires=['six', 'numpy'],
tests_require=['pytest'],
ext_modules=cythonize(ext_modules),
ext_modules=lazy_list(get_ext_modules),
cmdclass={
'build_ext': build_ext
}
Expand Down

0 comments on commit 0687908

Please sign in to comment.