|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
| 3 | +import glob |
3 | 4 | import sys
|
4 | 5 | import os
|
5 | 6 | import warnings
|
6 | 7 |
|
| 8 | +from setuptools import setup, Extension |
7 | 9 | from distutils.dist import Distribution
|
8 | 10 |
|
9 | 11 | display_option_names = Distribution.display_option_names + ['help', 'help-commands']
|
10 | 12 | query_only = any('--' + opt in sys.argv for opt in display_option_names) or len(sys.argv) < 2 or sys.argv[1] == 'egg_info'
|
11 | 13 |
|
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 |
| - |
23 | 14 | lib_talib_name = 'ta_lib' # the underlying C library's name
|
| 15 | +sources = [] |
24 | 16 |
|
25 | 17 | platform_supported = False
|
26 | 18 | for prefix in ['darwin', 'linux', 'bsd', 'sunos']:
|
|
66 | 58 | except ImportError:
|
67 | 59 | has_cython = False
|
68 | 60 |
|
| 61 | +libraries = [lib_talib_name] |
69 | 62 | for lib_talib_dir in lib_talib_dirs:
|
70 | 63 | try:
|
71 | 64 | files = os.listdir(lib_talib_dir)
|
|
74 | 67 | except OSError:
|
75 | 68 | pass
|
76 | 69 | 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 | + |
78 | 116 |
|
79 | 117 | cmdclass = {}
|
80 | 118 | if has_cython:
|
|
83 | 121 | ext_modules = [
|
84 | 122 | Extension(
|
85 | 123 | '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, |
87 | 125 | include_dirs=include_dirs,
|
88 | 126 | library_dirs=lib_talib_dirs,
|
89 |
| - libraries=[lib_talib_name] |
| 127 | + libraries=libraries |
90 | 128 | )
|
91 | 129 | ]
|
92 | 130 |
|
93 | 131 | 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=[ |
102 | 140 | "License :: OSI Approved :: BSD License",
|
103 | 141 | "Development Status :: 4 - Beta",
|
104 | 142 | "Operating System :: Unix",
|
|
117 | 155 | "Intended Audience :: Science/Research",
|
118 | 156 | "Intended Audience :: Financial and Insurance Industry",
|
119 | 157 | ],
|
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'], |
124 | 163 | )
|
0 commit comments