Skip to content

Commit d1eec27

Browse files
committed
Build from source if the ta-lib is not installed
1 parent 78f8f2c commit d1eec27

File tree

7 files changed

+83
-27
lines changed

7 files changed

+83
-27
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ env:
1515
TA_INCLUDE_PATH=$DEPS_DIR/include
1616
LD_LIBRARY_PATH=$DEPS_DIR/lib
1717
TA_LIBRARY_PATH=$DEPS_DIR/lib
18+
- WITH_TA_LIBRARY=no
1819
cache:
1920
directories:
2021
- $DEPS_DIR

MANIFEST.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
include README.md
2+
include AUTHORS
3+
include CHANGELOG
4+
include COPYRIGHT
5+
include DEVELOPMENT
6+
include LICENSE
7+
include requirements.txt
8+
recursive-include vendor *
9+
recursive-include talib *.py *.pyx *.pxi *.pxd *.c
10+
prune vendor/ta-lib/temp
11+
prune vendor/ta-lib/make
12+
prune vendor/ta-lib/ide
13+
prune vendor/ta-lib/src/tools

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ talib/_stream.pxi: tools/generate_stream.py
1515
generate: talib/_func.pxi talib/_stream.pxi
1616

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

2020
perf:
2121
python tools/perf_talib.py

setup.py

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
#!/usr/bin/env python
22

3+
import glob
34
import sys
45
import os
56
import warnings
67

8+
from setuptools import setup, Extension
79
from distutils.dist import Distribution
810

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

12-
# Use setuptools for querying the package, normal builds use distutils
13-
if query_only:
14-
try:
15-
from setuptools import setup
16-
except ImportError:
17-
from distutils.core import setup
18-
else:
19-
from distutils.core import setup
20-
21-
from distutils.extension import Extension
22-
2314
lib_talib_name = 'ta_lib' # the underlying C library's name
15+
sources = []
2416

2517
platform_supported = False
2618
for prefix in ['darwin', 'linux', 'bsd', 'sunos']:
@@ -66,6 +58,7 @@
6658
except ImportError:
6759
has_cython = False
6860

61+
libraries = [lib_talib_name]
6962
for lib_talib_dir in lib_talib_dirs:
7063
try:
7164
files = os.listdir(lib_talib_dir)
@@ -74,7 +67,52 @@
7467
except OSError:
7568
pass
7669
else:
77-
warnings.warn('Cannot find ta-lib library, installation may fail.')
70+
libraries = []
71+
warnings.warn(
72+
'Cannot find ta-lib library, will try to build from source.'
73+
)
74+
# find vendor/ta-lib -name "*.h" -exec dirname {} \; | sort | uniq
75+
vendor_dir = os.path.join(
76+
os.path.dirname(os.path.abspath(__file__)),
77+
"vendor",
78+
)
79+
vendor_include_dir = os.path.join(
80+
vendor_dir,
81+
"include",
82+
)
83+
vendor_talib_dir = os.path.join(
84+
vendor_dir,
85+
"ta-lib",
86+
)
87+
talib_include_dirs = [
88+
("include", ),
89+
("src", "ta_abstract"),
90+
("src", "ta_abstract", "frames"),
91+
("src", "ta_common"),
92+
("src", "ta_func"),
93+
]
94+
include_dirs.append(os.path.join(vendor_include_dir))
95+
include_dirs.extend((
96+
os.path.join(vendor_talib_dir, *path_args)
97+
for path_args in talib_include_dirs
98+
))
99+
100+
talib_source_dirs = [
101+
("ta_abstract", ),
102+
("ta_abstract", "frames"),
103+
("ta_abstract", "tables"),
104+
("ta_common", ),
105+
("ta_func", )
106+
]
107+
for path_args in talib_source_dirs:
108+
source_dir = os.path.join(vendor_talib_dir, "src", *path_args)
109+
sources.extend(glob.glob(os.path.join(source_dir, "*.c")))
110+
sources.remove(
111+
os.path.join(vendor_talib_dir, "src", "ta_abstract", "excel_glue.c")
112+
)
113+
libraries = []
114+
lib_talib_dirs = []
115+
78116

79117
cmdclass = {}
80118
if has_cython:
@@ -83,22 +121,22 @@
83121
ext_modules = [
84122
Extension(
85123
'talib._ta_lib',
86-
['talib/_ta_lib.pyx' if has_cython else 'talib/_ta_lib.c'],
124+
['talib/_ta_lib.pyx' if has_cython else 'talib/_ta_lib.c'] + sources,
87125
include_dirs=include_dirs,
88126
library_dirs=lib_talib_dirs,
89-
libraries=[lib_talib_name]
127+
libraries=libraries
90128
)
91129
]
92130

93131
setup(
94-
name = 'TA-Lib',
95-
version = '0.4.10',
96-
description = 'Python wrapper for TA-Lib',
97-
author = 'John Benediktsson',
98-
author_email = 'mrjbq7@gmail.com',
99-
url = 'http://github.com/mrjbq7/ta-lib',
100-
download_url = 'https://github.com/mrjbq7/ta-lib/releases',
101-
classifiers = [
132+
name='TA-Lib',
133+
version='0.4.10',
134+
description='Python wrapper for TA-Lib',
135+
author='John Benediktsson',
136+
author_email='mrjbq7@gmail.com',
137+
url='http://github.com/mrjbq7/ta-lib',
138+
download_url='https://github.com/mrjbq7/ta-lib/releases',
139+
classifiers=[
102140
"License :: OSI Approved :: BSD License",
103141
"Development Status :: 4 - Beta",
104142
"Operating System :: Unix",
@@ -117,8 +155,9 @@
117155
"Intended Audience :: Science/Research",
118156
"Intended Audience :: Financial and Insurance Industry",
119157
],
120-
packages = ['talib'],
121-
ext_modules = ext_modules,
122-
cmdclass = cmdclass,
123-
requires = ['numpy'],
158+
packages=['talib'],
159+
ext_modules=ext_modules,
160+
cmdclass=cmdclass,
161+
setup_requires=['numpy'],
162+
install_requires=['numpy'],
124163
)

tools/generate_func.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
include_paths = ['/usr/include', '/usr/local/include', '/opt/include', '/opt/local/include']
1515
if sys.platform == 'win32':
1616
include_paths = [r'c:\ta-lib\c\include']
17+
include_paths.append(os.path.join(os.path.dirname(os.path.dirname(__file__)), "vendor", "include"))
1718
header_found = False
1819
for path in include_paths:
1920
ta_func_header = os.path.join(path, 'ta-lib', 'ta_func.h')

tools/generate_stream.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
include_paths = ['/usr/include', '/usr/local/include', '/opt/include', '/opt/local/include']
1515
if sys.platform == 'win32':
1616
include_paths = [r'c:\ta-lib\c\include']
17+
include_paths.append(os.path.join(os.path.dirname(os.path.dirname(__file__)), "vendor", "include"))
1718
header_found = False
1819
for path in include_paths:
1920
ta_func_header = os.path.join(path, 'ta-lib', 'ta_func.h')

vendor/include/ta-lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../ta-lib/include

0 commit comments

Comments
 (0)