-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathsetup.py
More file actions
152 lines (121 loc) · 4.17 KB
/
setup.py
File metadata and controls
152 lines (121 loc) · 4.17 KB
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
#!/usr/bin/env python
import os
import shutil
import sys
from distutils.command.config import config as _config
from setuptools import Command, 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
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
setup(
version=versioneer.get_version(),
package_data={
"bottleneck.tests": ["data/*/*"],
},
cmdclass=cmdclass,
ext_modules=prepare_modules(),
)