|
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' |
| 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 | 11 |
|
12 | 12 | try: |
13 | 13 | from setuptools import setup, Extension |
14 | | - requires = {"install_requires": ["numpy"]} |
| 14 | + requires = { |
| 15 | + "install_requires": ["numpy", 'cython'], |
| 16 | + "setup_requires": ['numpy', 'cython'] |
| 17 | + } |
15 | 18 | except: |
16 | 19 | from distutils.core import setup |
17 | 20 | from distutils.extension import Extension |
|
57 | 60 | if not platform_supported: |
58 | 61 | raise NotImplementedError(sys.platform) |
59 | 62 |
|
60 | | -# Do not require numpy or cython for just querying the package |
61 | | -if not query_only: |
62 | | - import numpy |
63 | | - include_dirs.insert(0, numpy.get_include()) |
64 | | - |
65 | | -try: |
66 | | - from Cython.Distutils import build_ext |
67 | | - has_cython = True |
68 | | -except ImportError: |
69 | | - has_cython = False |
| 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 |
70 | 73 |
|
71 | 74 | for lib_talib_dir in lib_talib_dirs: |
72 | 75 | try: |
|
78 | 81 | else: |
79 | 82 | warnings.warn('Cannot find ta-lib library, installation may fail.') |
80 | 83 |
|
81 | | -cmdclass = {} |
82 | | -if has_cython: |
83 | | - cmdclass['build_ext'] = build_ext |
| 84 | +# cmdclass = {} |
| 85 | +# if has_cython: |
| 86 | +# cmdclass['build_ext'] = build_ext |
| 87 | + |
| 88 | + |
| 89 | +class LazyBuildExtCommandClass(dict): |
| 90 | + """ |
| 91 | + Lazy command class that defers operations requiring Cython and numpy until |
| 92 | + they've actually been downloaded and installed by setup_requires. |
| 93 | + """ |
| 94 | + |
| 95 | + def __contains__(self, key): |
| 96 | + return (key == 'build_ext' or |
| 97 | + super(LazyBuildExtCommandClass, self).__contains__(key)) |
| 98 | + |
| 99 | + def __setitem__(self, key, value): |
| 100 | + if key == 'build_ext': |
| 101 | + raise AssertionError("build_ext overridden!") |
| 102 | + super(LazyBuildExtCommandClass, self).__setitem__(key, value) |
| 103 | + |
| 104 | + def __getitem__(self, key): |
| 105 | + global include_dirs |
| 106 | + if key != 'build_ext': |
| 107 | + return super(LazyBuildExtCommandClass, self).__getitem__(key) |
| 108 | + |
| 109 | + from Cython.Distutils import build_ext as cython_build_ext |
| 110 | + import numpy |
| 111 | + |
| 112 | + # Cython_build_ext isn't a new-style class in Py2. |
| 113 | + class build_ext(cython_build_ext, object): |
| 114 | + """ |
| 115 | + Custom build_ext command that lazily adds numpy's include_dir to |
| 116 | + extensions. |
| 117 | + """ |
| 118 | + |
| 119 | + def build_extensions(self): |
| 120 | + """ |
| 121 | + Lazily append numpy's include directory to Extension includes. |
| 122 | + This is done here rather than at module scope because setup.py |
| 123 | + may be run before numpy has been installed, in which case |
| 124 | + importing numpy and calling `numpy.get_include()` will fail. |
| 125 | + """ |
| 126 | + numpy_incl = numpy.get_include() |
| 127 | + for ext in self.extensions: |
| 128 | + ext.include_dirs.append(numpy_incl) |
| 129 | + |
| 130 | + super(build_ext, self).build_extensions() |
| 131 | + |
| 132 | + return build_ext |
| 133 | + |
| 134 | + |
| 135 | +cmdclass = LazyBuildExtCommandClass() |
84 | 136 |
|
85 | 137 | ext_modules = [ |
86 | 138 | Extension( |
87 | 139 | 'talib._ta_lib', |
88 | | - ['talib/_ta_lib.pyx' if has_cython else 'talib/_ta_lib.c'], |
| 140 | + ['talib/_ta_lib.pyx'], # if has_cython else 'talib/_ta_lib.c'], |
89 | 141 | include_dirs=include_dirs, |
90 | 142 | library_dirs=lib_talib_dirs, |
91 | 143 | libraries=[lib_talib_name], |
92 | | - runtime_library_dirs=runtime_lib_dirs |
93 | | - ) |
| 144 | + runtime_library_dirs=runtime_lib_dirs) |
94 | 145 | ] |
95 | | - |
96 | 146 | setup( |
97 | | - name = 'TA-Lib', |
98 | | - version = '0.4.18', |
99 | | - description = 'Python wrapper for TA-Lib', |
100 | | - author = 'John Benediktsson', |
101 | | - author_email = 'mrjbq7@gmail.com', |
102 | | - url = 'https://github.com/mrjbq7/ta-lib', |
103 | | - download_url = 'https://github.com/mrjbq7/ta-lib/releases', |
104 | | - classifiers = [ |
| 147 | + name='TA-Lib', |
| 148 | + version='0.4.18', |
| 149 | + description='Python wrapper for TA-Lib', |
| 150 | + author='John Benediktsson', |
| 151 | + author_email='mrjbq7@gmail.com', |
| 152 | + url='https://github.com/mrjbq7/ta-lib', |
| 153 | + download_url='https://github.com/mrjbq7/ta-lib/releases', |
| 154 | + classifiers=[ |
105 | 155 | "License :: OSI Approved :: BSD License", |
106 | 156 | "Development Status :: 4 - Beta", |
107 | 157 | "Operating System :: Unix", |
|
122 | 172 | "Intended Audience :: Science/Research", |
123 | 173 | "Intended Audience :: Financial and Insurance Industry", |
124 | 174 | ], |
125 | | - packages = ['talib'], |
126 | | - ext_modules = ext_modules, |
127 | | - cmdclass = cmdclass, |
128 | | - **requires |
129 | | -) |
| 175 | + packages=['talib'], |
| 176 | + ext_modules=ext_modules, |
| 177 | + cmdclass=cmdclass, |
| 178 | + **requires) |
0 commit comments