forked from pyspace/pyspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
212 lines (185 loc) · 7.51 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
202
203
204
205
206
207
208
209
210
211
212
""" Create pySPACE center, run basic tests
This file must be run with python
"""
from distutils.core import setup
import os
import sys
import shutil
import warnings
from os.path import expanduser
home = expanduser("~")
email = '[email protected]'
classifiers = ["Development Status :: 1 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"License :: None",
"Operating System :: Linux",
"Operating System :: OS X",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Topic :: Scientific/Engineering :: Information Analysis",
"Topic :: Scientific/Engineering :: Benchmark",
"Topic :: Scientific/Engineering :: Mathematics"]
def get_module_code():
# keep old python compatibility, so no context managers
init_file = open(os.path.join(os.getcwd(), 'pySPACE', '__init__.py'))
module_code = init_file.read()
init_file.close()
return module_code
def throw_bug():
raise ValueError('Can not get pySPACE parameters!\n'
'Please report a bug to ' + email)
try:
import ast
def get_extract_variable(tree, variable):
for node in ast.walk(tree):
if type(node) is ast.Assign:
try:
if node.targets[0].id == variable:
print node.targets
return node.value.s
except Exception,e:
raise
pass
throw_bug()
def get_ast_tree():
return ast.parse(get_module_code())
def get_version():
tree = get_ast_tree()
return get_extract_variable(tree, '__version__')
def get_short_description():
return "pySPACE is a **Signal Processing And Classification Environment** "
tree = get_ast_tree()
return get_extract_variable(tree, '__short_description__')
def get_long_description():
tree = get_ast_tree()
return ast.get_docstring(tree)
except ImportError:
import re
def get_variable(pattern):
m = re.search(pattern, get_module_code(), re.M + re.S + re.X)
if not m:
throw_bug()
return m.group(1)
def get_version():
return get_variable(r'^__version__\s*=\s*[\'"](.+?)[\'"]')
def get_short_description():
text = get_variable(r'''^__short_description__\s*=\s* # variable name and =
\\?\s*(?:"""|\'\'\')\\?\s* # opening quote with backslash
(.+?)
\s*(?:"""|\'\'\')''') # closing quote
return text.replace(' \\\n', ' ')
def get_long_description():
return get_variable(r'''^(?:"""|\'\'\')\\?\s* # opening quote with backslash
(.+?)
\s*(?:"""|\'\'\')''') # closing quote
def create_directory(path):
""" Create the given directory path recursively
Copy from pySPACE.tools.filesystem
"""
parts = path.split(os.sep)
subpath = ""
for part in parts[1:]:
subpath += os.sep + part
if not os.path.exists(subpath):
try:
os.mkdir(subpath)
except OSError as (err_no, strerr):
import errno
# os.path.exists isn't secure on gpfs!
if not err_no == errno.EEXIST:
raise
def save_copy(src,dest):
if not os.path.exists(dest):
shutil.copy2(src,dest)
elif dest.endswith(".yaml"):
import yaml
d=yaml.load(open(dest))
s=yaml.load(open(src))
if not d==s:
dest=dest[:-5]+"_new.yaml"
save_copy(src,dest)
elif dest.endswith(".csv") or dest.endswith(".rst"):
pass
else:
dest+=".new"
save_copy(src,dest)
def setup_package():
src_path = os.path.dirname(os.path.abspath(sys.argv[0]))
create_directory(os.path.join(home, "pySPACEcenter"))
#create_directory(os.path.join(home, "pySPACEcenter","examples"))
create_directory(os.path.join(home, "pySPACEcenter","specs"))
create_directory(os.path.join(home, "pySPACEcenter","storage"))
src_conf_file = os.path.join(src_path,"docs","examples","conf","example.yaml")
dest_conf_file = os.path.join(home, "pySPACEcenter","config.yaml")
save_copy(src_conf_file,dest_conf_file)
try:
os.symlink(os.path.join(src_path,"pySPACE", "run", "launch.py"),os.path.join(home, "pySPACEcenter", "launch.py"))
except:
pass
try:
os.symlink(os.path.join(src_path,"pySPACE", "run", "launch_live.py"),os.path.join(home, "pySPACEcenter", "launch_live.py"))
except:
pass
try:
os.symlink(os.path.join(src_path,"pySPACE", "run", "gui","performance_results_analysis.py"),os.path.join(home, "pySPACEcenter", "performance_results_analysis.py"))
except:
pass
examples=os.path.join(src_path,"docs","examples")
# copying examples folder
for folder, _, files in os.walk(examples):
new_folder=os.path.join(home, "pySPACEcenter","examples",folder[len(examples)+1:])
for file in files:
if not file.startswith("."):
create_directory(new_folder)
save_copy(os.path.join(src_path,folder,file),os.path.join(new_folder,file))
# copying important examples to normal structure to have a start
for folder, _, files in os.walk(examples):
new_folder=os.path.join(home, "pySPACEcenter",folder[len(examples)+1:])
for file in files:
if "conf" in folder[len(examples)+1:] or \
".rst" in file or \
file.startswith("."):
pass
#"example" in file or "example_summary" in folder:
elif "example" in file \
or "example_summary" in folder[len(examples)+1:] \
or file=="functions.yaml"\
or "template" in file\
or folder.endswith("templates") \
or folder.endswith("examples"):
create_directory(new_folder)
save_copy(os.path.join(src_path,folder,file),os.path.join(new_folder,file))
#
# try:
# shutil.copytree(os.path.join(src_path,"docs","examples"),os.path.join(home, "pySPACEcenter","examples"))
# except:
# pass
#
# # check that we have a version
# version = get_version()
# short_description = get_short_description()
# long_description = get_long_description()
# # Run build
# os.chdir(src_path)
# sys.path.insert(0, src_path)
#
# setup(name = 'pySPACE', version=version,
# author = 'pySPACE Developers',
# author_email = email,
# maintainer = 'pySPACE Developers',
# maintainer_email = email,
# license = "https://websrv.dfki.uni-bremen.de/IMMI/pySPACE/license.html",
# platforms = ["Linux, OSX"],
# url = 'https://websrv.dfki.uni-bremen.de/IMMI/pySPACE/',
# download_url = 'http://spacegit.dfki.uni-bremen.de/pyspace',
# description = short_description,
# long_description = long_description,
# classifiers = classifiers,
# packages = ['pySPACE', 'pySPACE.missions', 'pySPACE.resources', 'pySPACE.environments',
# 'pySPACE.tests', 'pySPACE.tools', 'pySPACE.run'],
# package_data = {}
# )
if __name__ == '__main__':
setup_package()