-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
168 lines (134 loc) · 6.11 KB
/
setup.py
File metadata and controls
168 lines (134 loc) · 6.11 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import os
import sys
from setuptools import setup,Extension
from numpy.distutils.misc_util import get_numpy_include_dirs
from distutils.sysconfig import get_python_lib;
'''
In order to create a source distribution run setup build_ext sdist, otherwise the pyisc.py will not be generated from
pyisc.i, which is not distributed in the source distribution, only the generated sources are distributed.
'''
######## import numpy.i ##########
# Import numpy.i from current version.
# See http://stackoverflow.com/questions/21855775/numpy-i-is-missing-what-is-the-recommended-way-to-install-it
np_file_name = 'numpy.i'
if not os.path.exists(np_file_name):
import re
import requests
import numpy
np_version = re.compile(r'(?P<MAJOR>[0-9]+)\.'
'(?P<MINOR>[0-9]+)') \
.search(numpy.__version__)
np_version_string = np_version.group()
np_version_info = {key: int(value)
for key, value in list(np_version.groupdict().items())}
np_file_url = 'https://raw.githubusercontent.com/numpy/numpy/maintenance/' + \
np_version_string + '.x/tools/swig/' + np_file_name
if(np_version_info['MAJOR'] == 1 and np_version_info['MINOR'] < 9):
np_file_url = np_file_url.replace('tools', 'doc')
chunk_size = 8196
with open(np_file_name, 'wb') as file:
for chunk in requests.get(np_file_url,
stream=True).iter_content(chunk_size):
file.write(chunk)
###### END numpy.i import #######
extra_flags = []
disc_dir = "."
arduinojson_dir = os.path.join("ArduinoJson","src")
dataframe_src_dir = os.path.join(disc_dir,'dataformat')
isc_src_dir = os.path.join(disc_dir, 'isc2')
pyisc_src_dir = "src"
pyisc_module_dir = "_pyisc_modules"
isclibraries = ["-Wall", "-O"]
numpyincdir = get_numpy_include_dirs()
py_modules = [
os.path.join(pyisc_module_dir, src) for src in
["__init__",
"BaseISC",
"AnomalyDetector",
"DataObject",
"SklearnOutlierDetector",
"SklearnClassifier",
"AnomalyClustering",
"OutlierClustering",
]
]\
+["pyisc"]
pylib = get_python_lib()
# Must be updated if file structure has changed
if "uninstall" in sys.argv:
from glob import glob
files = [os.path.join(pylib, mod)+".py" for mod in py_modules] + \
[os.path.join(pylib, mod)+".pyc" for mod in py_modules] + \
[os.path.join(pylib,pyisc_module_dir)] + \
[os.path.join(pylib, "pyisc-1.0-py2.7.egg-info")] + \
glob(os.path.os.path.join(pylib, "_pyisc.*"))
for file in files:
if os.path.exists(file):
if os.path.isdir(file):
os.removedirs(file)
else:
os.remove(file)
print("removing "+file)
sys.exit()
#add extra flags as needed, look in file our-g++
if sys.platform == 'darwin':
isclibraries += ["z"]
extra_flags = ["-DPLATFORM_MAC"]
elif sys.platform == "win32":
extra_flags = ["-DPLATFORM_MSW"]
else: # Default, works for Linux
isclibraries += ["z"]
extra_flags = ["-Wmissing-declarations","-DUSE_WCHAR -DPLATFORM_GTK"]
#extra_flags += ['-std=c++11']
dataframe_sources = [os.path.join(dataframe_src_dir, src)
for src in "readtokens.o table.o format.o formatdispatch.o formatbinary.o " \
"formatdiscr.o formatcont.o formatsymbol.o formattime.o formatunknown.o " \
"data.o datafile.o datadispatch.o".replace(".o", ".cc").split()]
isc_sources = [os.path.join(isc_src_dir, src)
for src in "anomalydetector.o isc_mixture.o isc_component.o isc_micromodel_poissongamma.o " \
"isc_micromodel_gaussian.o isc_micromodel_multigaussian.o " \
"isc_micromodel_markovgaussian.o " \
"hmatrix.o gamma.o hgf.o"
.replace(".o", ".cc").split()]
pyisc_sources = [os.path.join(pyisc_src_dir, src) for src in ["_Format.cc", "_DataObject.cc", "_AnomalyDetector.cc", "_JSonExporter.cc", "_JSonImporter.cc", "mystring.cc"]]
pyisc_headers = [s.replace(".cc", ".hh") for s in pyisc_sources]
# Only run when creating the distribution, not when installing it on someone else computer. Removes dependency on Swig
if os.path.exists('pyisc.i'):
setup(name="pyisc",
author="Tomas Olsson",
author_email="tomas.olsson@ri.se",
url="http://www.sics.se",
version="1.0",
ext_modules=[
Extension("_pyisc",
language='c++',
sources=["pyisc.i"]+dataframe_sources+isc_sources+pyisc_sources,
include_dirs=[disc_dir, isc_src_dir, dataframe_src_dir, pyisc_src_dir, arduinojson_dir]+numpyincdir,
extra_compile_args=extra_flags,
swig_opts=['-c++','-I'+str(disc_dir)])
],
license="LGPLv3",
classifiers=[
'License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)'
]
)
# The following overlapping setup is only run in order to inlcude pyisc.py when all *.py files are copied to the same folder.
setup(name="pyisc",
author="Tomas Olsson",
author_email="tomas.olsson@ri.se",
url="http://www.sics.se",
version="1.0",
ext_modules=[
Extension("_pyisc",
language='c++',
sources=["pyisc.i"]+dataframe_sources+isc_sources+pyisc_sources,
include_dirs=[disc_dir, isc_src_dir,dataframe_src_dir,pyisc_src_dir, arduinojson_dir]+numpyincdir,
extra_compile_args=extra_flags,
swig_opts=['-c++', '-I'+str(disc_dir)])
],
py_modules=py_modules,
license="LGPLv3+",
classifiers=[
'License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)'
]
)