-
Notifications
You must be signed in to change notification settings - Fork 104
/
setup.py
201 lines (165 loc) · 5.87 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
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env python
import os
import shutil
import sys
from distutils.command.config import config as _config
from setuptools import Command, find_packages, setup
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.extension import Extension
import versioneer
class config(_config):
def run(self):
from bn_config import create_config_h
create_config_h(self)
class clean(Command):
user_options = [("all", "a", "")]
def initialize_options(self):
self.all = True
self.delete_dirs = []
self.delete_files = []
for root, dirs, files in os.walk("bottleneck"):
for d in dirs:
if d == "__pycache__":
self.delete_dirs.append(os.path.join(root, d))
if "__pycache__" in root:
continue
for f in files:
if f.endswith(".pyc") or f.endswith(".so"):
self.delete_files.append(os.path.join(root, f))
if f.endswith(".c") and "template" in f:
generated_file = os.path.join(root, f.replace("_template", ""))
if os.path.exists(generated_file):
self.delete_files.append(generated_file)
config_h = "bottleneck/src/bn_config.h"
if os.path.exists(config_h):
self.delete_files.append(config_h)
if os.path.exists("build"):
self.delete_dirs.append("build")
def finalize_options(self):
pass
def run(self):
for delete_dir in self.delete_dirs:
shutil.rmtree(delete_dir)
for delete_file in self.delete_files:
os.unlink(delete_file)
# workaround for installing bottleneck when numpy is not present
class build_ext(_build_ext):
# taken from: stackoverflow.com/questions/19919905/
# how-to-bootstrap-numpy-installation-in-setup-py#21621689
def finalize_options(self):
_build_ext.finalize_options(self)
# prevent numpy from thinking it is still in its setup process
if sys.version_info < (3,):
import __builtin__ as builtins
else:
import builtins
builtins.__NUMPY_SETUP__ = False
import numpy
# place numpy includes first, see gh #156
self.include_dirs.insert(0, numpy.get_include())
self.include_dirs.append("bottleneck/src")
def build_extensions(self):
from bn_template import make_c_files
self.run_command("config")
dirpath = "bottleneck/src"
modules = ["reduce", "move", "nonreduce", "nonreduce_axis"]
make_c_files(dirpath, modules)
_build_ext.build_extensions(self)
cmdclass = versioneer.get_cmdclass()
cmdclass["build_ext"] = build_ext
cmdclass["clean"] = clean
cmdclass["config"] = config
# Add our template path to the path so that we don't have a circular reference
# of working install to be able to re-compile
sys.path.append(os.path.join(os.path.dirname(__file__), "bottleneck/src"))
def prepare_modules():
base_includes = [
"bottleneck/src/bottleneck.h",
"bottleneck/src/bn_config.h",
"bottleneck/src/iterators.h",
]
ext = [
Extension(
"bottleneck.reduce",
sources=["bottleneck/src/reduce.c"],
depends=base_includes,
extra_compile_args=["-O2"],
)
]
ext += [
Extension(
"bottleneck.move",
sources=[
"bottleneck/src/move.c",
"bottleneck/src/move_median/move_median.c",
],
depends=base_includes + ["bottleneck/src/move_median/move_median.h"],
extra_compile_args=["-O2"],
)
]
ext += [
Extension(
"bottleneck.nonreduce",
sources=["bottleneck/src/nonreduce.c"],
depends=base_includes,
extra_compile_args=["-O2"],
)
]
ext += [
Extension(
"bottleneck.nonreduce_axis",
sources=["bottleneck/src/nonreduce_axis.c"],
depends=base_includes,
extra_compile_args=["-O2"],
)
]
return ext
def get_long_description():
with open("README.rst", "r") as fid:
long_description = fid.read()
idx = max(0, long_description.find("Bottleneck is a collection"))
long_description = long_description[idx:]
return long_description
CLASSIFIERS = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Science/Research",
"Intended Audience :: Financial and Insurance Industry",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: C",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"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",
"Topic :: Scientific/Engineering",
]
metadata = dict(
name="Bottleneck",
maintainer="Christopher Whelan",
maintainer_email="[email protected]",
description="Fast NumPy array functions written in C",
long_description=get_long_description(),
long_description_content_type="text/x-rst",
url="https://github.com/pydata/bottleneck",
download_url="http://pypi.python.org/pypi/Bottleneck",
license="Simplified BSD",
classifiers=CLASSIFIERS,
platforms="OS Independent",
version=versioneer.get_version(),
packages=find_packages(),
package_data={
"bottleneck": ["LICENSE"],
"bottleneck.tests": ["data/*/*"],
},
python_requires=">=3.9",
install_requires=["numpy"],
extras_require={"doc": ["numpydoc", "sphinx", "gitpython"]},
cmdclass=cmdclass,
ext_modules=prepare_modules(),
zip_safe=False,
)
setup(**metadata)