6
6
7
7
from distutils .dist import Distribution
8
8
9
- # display_option_names = Distribution.display_option_names + ['help', 'help-commands']
10
- # 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
-
12
9
try :
13
10
from setuptools import setup , Extension
14
- requires = {
15
- "install_requires" : ["numpy" , 'cython' ],
16
- "setup_requires" : ['numpy' , 'cython' ]
17
- }
11
+ requires = {"install_requires" : ["numpy" ], "setup_requires" : ["numpy" ]}
18
12
except :
19
13
from distutils .core import setup
20
14
from distutils .extension import Extension
60
54
if not platform_supported :
61
55
raise NotImplementedError (sys .platform )
62
56
63
- # # Do not require numpy or cython for just querying the package
64
- # if not query_only:
65
- # import numpy
66
- # include_dirs.insert(0, numpy.get_include())
67
- #
68
- # try:
69
- # from Cython.Distutils import build_ext
70
- # has_cython = True
71
- # except ImportError:
72
- # has_cython = False
57
+ try :
58
+ from Cython .Distutils import build_ext as cython_build_ext
59
+ has_cython = True
60
+ except ImportError :
61
+ has_cython = False
73
62
74
63
for lib_talib_dir in lib_talib_dirs :
75
64
try :
81
70
else :
82
71
warnings .warn ('Cannot find ta-lib library, installation may fail.' )
83
72
84
- # cmdclass = {}
85
- # if has_cython:
86
- # cmdclass['build_ext'] = build_ext
87
-
88
73
89
74
class LazyBuildExtCommandClass (dict ):
90
75
"""
@@ -106,11 +91,14 @@ def __getitem__(self, key):
106
91
if key != 'build_ext' :
107
92
return super (LazyBuildExtCommandClass , self ).__getitem__ (key )
108
93
109
- from Cython .Distutils import build_ext as cython_build_ext
110
94
import numpy
95
+ if has_cython :
96
+ org_build_ext = cython_build_ext
97
+ else :
98
+ from setuptools .command .build_ext import build_ext as org_build_ext
111
99
112
100
# Cython_build_ext isn't a new-style class in Py2.
113
- class build_ext (cython_build_ext , object ):
101
+ class build_ext (org_build_ext , object ):
114
102
"""
115
103
Custom build_ext command that lazily adds numpy's include_dir to
116
104
extensions.
@@ -137,7 +125,7 @@ def build_extensions(self):
137
125
ext_modules = [
138
126
Extension (
139
127
'talib._ta_lib' ,
140
- ['talib/_ta_lib.pyx' ], # if has_cython else 'talib/_ta_lib.c'],
128
+ ['talib/_ta_lib.pyx' if has_cython else 'talib/_ta_lib.c' ],
141
129
include_dirs = include_dirs ,
142
130
library_dirs = lib_talib_dirs ,
143
131
libraries = [lib_talib_name ],
0 commit comments