Skip to content

Commit

Permalink
Build from source if the ta-lib is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
mckelvin committed Feb 5, 2017
1 parent 78f8f2c commit dba4881
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 27 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ env:
TA_INCLUDE_PATH=$DEPS_DIR/include
LD_LIBRARY_PATH=$DEPS_DIR/lib
TA_LIBRARY_PATH=$DEPS_DIR/lib
- WITH_TA_LIBRARY=no
cache:
directories:
- $DEPS_DIR
Expand Down
13 changes: 13 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include README.md
include AUTHORS
include CHANGELOG
include COPYRIGHT
include DEVELOPMENT
include LICENSE
include requirements.txt
recursive-include vendor *
recursive-include talib *.py *.pyx *.pxi *.pxd *.c
prune vendor/ta-lib/temp
prune vendor/ta-lib/make
prune vendor/ta-lib/ide
prune vendor/ta-lib/src/tools
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ talib/_stream.pxi: tools/generate_stream.py
generate: talib/_func.pxi talib/_stream.pxi

clean:
rm -rf build talib/func*.so talib/abstract*.so talib/common*.so talib/stream*.so talib/*.pyc
rm -rf build talib/_ta_lib.so talib/*.pyc

perf:
python tools/perf_talib.py
Expand Down
91 changes: 65 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
#!/usr/bin/env python

import glob
import sys
import os
import warnings

from setuptools import setup, Extension
from distutils.dist import Distribution

display_option_names = Distribution.display_option_names + ['help', 'help-commands']
query_only = any('--' + opt in sys.argv for opt in display_option_names) or len(sys.argv) < 2 or sys.argv[1] == 'egg_info'

# Use setuptools for querying the package, normal builds use distutils
if query_only:
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
else:
from distutils.core import setup

from distutils.extension import Extension

lib_talib_name = 'ta_lib' # the underlying C library's name
sources = []

platform_supported = False
for prefix in ['darwin', 'linux', 'bsd', 'sunos']:
Expand Down Expand Up @@ -66,6 +58,7 @@
except ImportError:
has_cython = False

libraries = [lib_talib_name]
for lib_talib_dir in lib_talib_dirs:
try:
files = os.listdir(lib_talib_dir)
Expand All @@ -74,7 +67,52 @@
except OSError:
pass
else:
warnings.warn('Cannot find ta-lib library, installation may fail.')
libraries = []
warnings.warn(
'Cannot find ta-lib library, will try to build from source.'
)
# find vendor/ta-lib -name "*.h" -exec dirname {} \; | sort | uniq
vendor_dir = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"vendor",
)
vendor_include_dir = os.path.join(
vendor_dir,
"include",
)
vendor_talib_dir = os.path.join(
vendor_dir,
"ta-lib",
)
talib_include_dirs = [
("include", ),
("src", "ta_abstract"),
("src", "ta_abstract", "frames"),
("src", "ta_common"),
("src", "ta_func"),
]
include_dirs.append(os.path.join(vendor_include_dir))
include_dirs.extend((
os.path.join(vendor_talib_dir, *path_args)
for path_args in talib_include_dirs
))

talib_source_dirs = [
("ta_abstract", ),
("ta_abstract", "frames"),
("ta_abstract", "tables"),
("ta_common", ),
("ta_func", )
]
for path_args in talib_source_dirs:
source_dir = os.path.join(vendor_talib_dir, "src", *path_args)
sources.extend(glob.glob(os.path.join(source_dir, "*.c")))
sources.remove(
os.path.join(vendor_talib_dir, "src", "ta_abstract", "excel_glue.c")
)
libraries = []
lib_talib_dirs = []


cmdclass = {}
if has_cython:
Expand All @@ -83,22 +121,22 @@
ext_modules = [
Extension(
'talib._ta_lib',
['talib/_ta_lib.pyx' if has_cython else 'talib/_ta_lib.c'],
['talib/_ta_lib.pyx' if has_cython else 'talib/_ta_lib.c'] + sources,
include_dirs=include_dirs,
library_dirs=lib_talib_dirs,
libraries=[lib_talib_name]
libraries=libraries
)
]

setup(
name = 'TA-Lib',
version = '0.4.10',
description = 'Python wrapper for TA-Lib',
author = 'John Benediktsson',
author_email = '[email protected]',
url = 'http://github.com/mrjbq7/ta-lib',
download_url = 'https://github.com/mrjbq7/ta-lib/releases',
classifiers = [
name='TA-Lib',
version='0.4.10',
description='Python wrapper for TA-Lib',
author='John Benediktsson',
author_email='[email protected]',
url='http://github.com/mrjbq7/ta-lib',
download_url='https://github.com/mrjbq7/ta-lib/releases',
classifiers=[
"License :: OSI Approved :: BSD License",
"Development Status :: 4 - Beta",
"Operating System :: Unix",
Expand All @@ -117,8 +155,9 @@
"Intended Audience :: Science/Research",
"Intended Audience :: Financial and Insurance Industry",
],
packages = ['talib'],
ext_modules = ext_modules,
cmdclass = cmdclass,
requires = ['numpy'],
packages=['talib'],
ext_modules=ext_modules,
cmdclass=cmdclass,
setup_requires=['numpy'],
install_requires=['numpy'],
)
1 change: 1 addition & 0 deletions vendor/include/ta-lib

0 comments on commit dba4881

Please sign in to comment.