-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
setup.py
188 lines (162 loc) · 5.97 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python
import sys
import os
import os.path
import warnings
try:
from setuptools import setup, Extension
from setuptools.dist import Distribution
requires = {
"install_requires": ["numpy"],
"setup_requires": ["numpy"]
}
except ImportError:
from distutils.core import setup
from distutils.dist import Distribution
from distutils.extension import Extension
requires = {"requires": ["numpy"]}
lib_talib_name = 'ta_lib' # the underlying C library's name
platform_supported = False
if any(s in sys.platform for s in ['darwin', 'linux', 'bsd', 'sunos']):
platform_supported = True
include_dirs = [
'/usr/include',
'/usr/local/include',
'/opt/include',
'/opt/local/include',
'/opt/homebrew/include',
'/opt/homebrew/opt/ta-lib/include',
]
library_dirs = [
'/usr/lib',
'/usr/local/lib',
'/usr/lib64',
'/usr/local/lib64',
'/opt/lib',
'/opt/local/lib',
'/opt/homebrew/lib',
'/opt/homebrew/opt/ta-lib/lib',
]
elif sys.platform == "win32":
platform_supported = True
lib_talib_name = 'ta_libc_cdr'
include_dirs = [r"c:\ta-lib\c\include"]
library_dirs = [r"c:\ta-lib\c\lib"]
if 'TA_INCLUDE_PATH' in os.environ:
include_dirs = os.environ['TA_INCLUDE_PATH'].split(os.pathsep)
if 'TA_LIBRARY_PATH' in os.environ:
library_dirs = os.environ['TA_LIBRARY_PATH'].split(os.pathsep)
if not platform_supported:
raise NotImplementedError(sys.platform)
try:
from Cython.Distutils import build_ext as cython_build_ext
has_cython = True
except ImportError:
has_cython = False
for path in library_dirs:
try:
files = os.listdir(path)
if any(lib_talib_name in f for f in files):
break
except OSError:
pass
else:
warnings.warn('Cannot find ta-lib library, installation may fail.')
class LazyBuildExtCommandClass(dict):
"""
Lazy command class that defers operations requiring Cython and numpy until
they've actually been downloaded and installed by setup_requires.
"""
def __contains__(self, key):
return (key == 'build_ext' or
super(LazyBuildExtCommandClass, self).__contains__(key))
def __setitem__(self, key, value):
if key == 'build_ext':
raise AssertionError("build_ext overridden!")
super(LazyBuildExtCommandClass, self).__setitem__(key, value)
def __getitem__(self, key):
global include_dirs
if key != 'build_ext':
return super(LazyBuildExtCommandClass, self).__getitem__(key)
import numpy
if has_cython:
org_build_ext = cython_build_ext
else:
from setuptools.command.build_ext import build_ext as org_build_ext
# Cython_build_ext isn't a new-style class in Py2.
class build_ext(org_build_ext, object):
"""
Custom build_ext command that lazily adds numpy's include_dir to
extensions.
"""
def build_extensions(self):
"""
Lazily append numpy's include directory to Extension includes.
This is done here rather than at module scope because setup.py
may be run before numpy has been installed, in which case
importing numpy and calling `numpy.get_include()` will fail.
"""
numpy_incl = numpy.get_include()
for ext in self.extensions:
ext.include_dirs.append(numpy_incl)
super(build_ext, self).build_extensions()
return build_ext
cmdclass = LazyBuildExtCommandClass()
ext_modules = [
Extension(
'talib._ta_lib',
['talib/_ta_lib.pyx' if has_cython else 'talib/_ta_lib.c'],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=[lib_talib_name],
runtime_library_dirs=[] if sys.platform == 'win32' else library_dirs)
]
from os import path
this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
setup(
name='TA-Lib',
version='0.5.2',
description='Python wrapper for TA-Lib',
long_description=long_description,
long_description_content_type='text/markdown',
author='John Benediktsson',
author_email='[email protected]',
url='http://github.com/ta-lib/ta-lib-python',
download_url='https://github.com/ta-lib/ta-lib-python/releases',
license='BSD',
classifiers=[
"License :: OSI Approved :: BSD License",
"Development Status :: 5 - Production/Stable",
"Operating System :: Unix",
"Operating System :: POSIX",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Cython",
"Topic :: Office/Business :: Financial",
"Topic :: Scientific/Engineering :: Mathematics",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Intended Audience :: Financial and Insurance Industry",
],
packages=['talib'],
ext_modules=ext_modules,
package_data={ 'talib': ['_ta_lib.pyi', 'py.typed'], },
cmdclass=cmdclass,
**requires)