Skip to content

Commit d4d01e5

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

File tree

7 files changed

+85
-16
lines changed

7 files changed

+85
-16
lines changed

.travis.yml

+1
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

+13
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

+1-1
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

+67-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22

3+
import glob
34
import sys
45
import os
56
import warnings
@@ -21,6 +22,7 @@
2122
from distutils.extension import Extension
2223

2324
lib_talib_name = 'ta_lib' # the underlying C library's name
25+
sources = []
2426

2527
platform_supported = False
2628
for prefix in ['darwin', 'linux', 'bsd', 'sunos']:
@@ -66,6 +68,7 @@
6668
except ImportError:
6769
has_cython = False
6870

71+
libraries = [lib_talib_name]
6972
for lib_talib_dir in lib_talib_dirs:
7073
try:
7174
files = os.listdir(lib_talib_dir)
@@ -74,7 +77,56 @@
7477
except OSError:
7578
pass
7679
else:
77-
warnings.warn('Cannot find ta-lib library, installation may fail.')
80+
libraries = []
81+
warnings.warn(
82+
'Cannot find ta-lib library, will try to build from source.'
83+
)
84+
# find vendor/ta-lib -name "*.h" -exec dirname {} \; | sort | uniq
85+
vendor_dir = os.path.join(
86+
os.path.dirname(os.path.abspath(__file__)),
87+
"vendor",
88+
)
89+
vendor_include_dir = os.path.join(
90+
vendor_dir,
91+
"include",
92+
)
93+
vendor_talib_dir = os.path.join(
94+
vendor_dir,
95+
"ta-lib",
96+
)
97+
talib_include_dirs = [
98+
("include", ),
99+
("src", "ta_abstract"),
100+
("src", "ta_abstract", "frames"),
101+
("src", "ta_common"),
102+
("src", "ta_func"),
103+
]
104+
include_dirs.append(os.path.join(vendor_include_dir))
105+
include_dirs.extend((
106+
os.path.join(vendor_talib_dir, *path_args)
107+
for path_args in talib_include_dirs
108+
))
109+
110+
talib_source_dirs = [
111+
("ta_abstract", ),
112+
("ta_abstract", "frames"),
113+
("ta_abstract", "tables"),
114+
("ta_common", ),
115+
("ta_func", )
116+
]
117+
for path_args in talib_source_dirs:
118+
source_dir = os.path.join(vendor_talib_dir, "src", *path_args)
119+
sources.extend(glob.glob(os.path.join(source_dir, "*.c")))
120+
excel_glue_c_file = os.path.join(
121+
vendor_talib_dir, "src", "ta_abstract", "excel_glue.c"
122+
)
123+
try:
124+
sources.remove(excel_glue_c_file)
125+
except ValueError:
126+
pass
127+
libraries = []
128+
lib_talib_dirs = []
129+
78130

79131
cmdclass = {}
80132
if has_cython:
@@ -83,22 +135,22 @@
83135
ext_modules = [
84136
Extension(
85137
'talib._ta_lib',
86-
['talib/_ta_lib.pyx' if has_cython else 'talib/_ta_lib.c'],
138+
['talib/_ta_lib.pyx' if has_cython else 'talib/_ta_lib.c'] + sources,
87139
include_dirs=include_dirs,
88140
library_dirs=lib_talib_dirs,
89-
libraries=[lib_talib_name]
141+
libraries=libraries
90142
)
91143
]
92144

93145
setup(
94-
name = 'TA-Lib',
95-
version = '0.4.10',
96-
description = 'Python wrapper for TA-Lib',
97-
author = 'John Benediktsson',
98-
author_email = '[email protected]',
99-
url = 'http://github.com/mrjbq7/ta-lib',
100-
download_url = 'https://github.com/mrjbq7/ta-lib/releases',
101-
classifiers = [
146+
name='TA-Lib',
147+
version='0.4.10',
148+
description='Python wrapper for TA-Lib',
149+
author='John Benediktsson',
150+
author_email='[email protected]',
151+
url='http://github.com/mrjbq7/ta-lib',
152+
download_url='https://github.com/mrjbq7/ta-lib/releases',
153+
classifiers=[
102154
"License :: OSI Approved :: BSD License",
103155
"Development Status :: 4 - Beta",
104156
"Operating System :: Unix",
@@ -117,8 +169,8 @@
117169
"Intended Audience :: Science/Research",
118170
"Intended Audience :: Financial and Insurance Industry",
119171
],
120-
packages = ['talib'],
121-
ext_modules = ext_modules,
122-
cmdclass = cmdclass,
123-
requires = ['numpy'],
172+
packages=['talib'],
173+
ext_modules=ext_modules,
174+
cmdclass=cmdclass,
175+
requires=['numpy'],
124176
)

tools/generate_func.py

+1
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

+1
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

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../ta-lib/include

0 commit comments

Comments
 (0)