This repository has been archived by the owner on Jun 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·248 lines (210 loc) · 6.63 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env python
# High-Level Reduction Functions
# A part of the SNS Analysis Software Suite.
#
# Spallation Neutron Source
# Oak Ridge National Laboratory, Oak Ridge TN.
#
#
# NOTICE
#
# For this software and its associated documentation, permission is granted
# to reproduce, prepare derivative works, and distribute copies to the public
# for any purpose and without fee.
#
# This material was prepared as an account of work sponsored by an agency of
# the United States Government. Neither the United States Government nor the
# United States Department of Energy, nor any of their employees, makes any
# warranty, express or implied, or assumes any legal liability or
# responsibility for the accuracy, completeness, or usefulness of any
# information, apparatus, product, or process disclosed, or represents that
# its use would not infringe privately owned rights.
#
###############################################################################
#
# Script for installing the HLRedux package modules and scripts
#
# $Id$
#
###############################################################################
from distutils.core import setup
from distutils.cmd import Command
import distutils.sysconfig
import getopt
import os
import sys
from HLR_version import version as __version__
# Package name and version information
PACKAGE = "HLRedux"
VERSION = __version__
package_list = ['', 'common_lib', 'dr_lib', 'drivers', 'drivers.DGS',
'drivers.GEN', 'drivers.IGS', 'drivers.REF', 'drivers.SAS',
'drplot', 'hlr_utils', 'hlr_test']
instrument_scripts = {
"ASG" : [
'memory_test',
'multi_read',
'multi_read_run',
'null_int_test',
'null_int_test2'
],
"DGS" : [
'dgs_norm',
'dgs_reduction'
],
"GEN" : [
'agg_dr_files',
'mask_generator',
'plot_file',
'plot_multi',
'plot_norm',
'stitch_dave',
'tof_slicer',
'two_file_math',
'xy_sum'
],
"IGS" : [
'amorphous_reduction',
'amorphous_reduction_sqe',
'bss_tof_spect_gen',
'bss_tof_sum_gen',
'calc_norm_eff',
'elastic_scan',
'find_ldb',
'find_tib',
'igs_diff_reduction'
],
"PD" : [
],
"REF" : [
'reflect_reduction',
'refred_lp',
'specmh_reduction'
],
"SAS" : [
'sas_background',
'sas_reduction',
'sas_transmission'
],
"SCD" : [
]
}
class build_doc(Command):
"""
This class is responsible for creating the API documentation via the
epydoc system.
"""
description = "Build the API documentation"
user_options = [("no-sourcecode", None, "Do not output source code")]
boolean_options = ["no-sourcecode"]
def initialize_options(self):
self.no_sourcecode = False
def finalize_options(self):
pass
def run(self):
try:
epydoc_conf = os.path.join('doc', 'config.epy')
from epydoc import cli
# Move __init__.py to init.py before making documentation
true_init = "__init__.py"
temp_init = "init.py"
# Take out __init__.pyc file since this causes build problems
try:
os.remove(true_init + "c")
except OSError:
# File is not found, do nothing
pass
os.rename(true_init, temp_init)
old_argv = sys.argv[1:]
cli_call = [
"--config=%s" % epydoc_conf,
"--verbose"
]
if self.no_sourcecode:
cli_call.append("--no-sourcecode")
else:
cli_call.append("--show-sourcecode")
sys.argv[1:] = cli_call
cli.cli()
sys.argv[1:] = old_argv
os.rename(temp_init, true_init)
except ImportError:
print "Epydoc is needed to create API documentation. Skipping.."
def pythonVersionCheck():
# Minimum version of Python
PYTHON_MAJOR = 2
PYTHON_MINOR = 3
if sys.version_info < (PYTHON_MAJOR, PYTHON_MINOR):
print >> sys.stderr, 'You need at least Python %d.%d for %s %s' \
% (PYTHON_MAJOR, PYTHON_MINOR, PACKAGE, VERSION)
sys.exit(-3)
def parseOptions(argv, keywords):
"""get values for input keywords
inputs like:
--keyword=value
transformed to a dictionary of
{keyword: value}
if nothing is given, value is set to default: True
"""
res = {}
for keyword in keywords:
for i, item in enumerate(argv):
if item.startswith(keyword):
value = item[ len(keyword) + 1: ]
if value == "": value = True
res[keyword] = value
del argv[i]
pass
continue
continue
return res
def parseCommandLine():
argv = sys.argv
keywords = ['--inst']
options = parseOptions(argv, keywords)
instruments = None
if options.get('--inst'):
instruments = options['--inst'].split(',')
try:
index = instruments.index("All")
instruments = ["All"]
except ValueError:
try:
index = instruments.index("GEN")
except ValueError:
instruments.append("GEN")
else:
instruments = ["All"]
return instruments
def getScripts(instruments):
scripts = []
if len(instruments) == 1:
if instruments[0].lower() == "all":
for key in instrument_scripts:
for script in instrument_scripts[key]:
scripts.append(os.path.join('drivers', key, script))
else:
if instruments[0] in instrument_scripts:
for script in instrument_scripts[instruments[0]]:
scripts.append(os.path.join('drivers', instruments[0],
script))
else:
print "No such instrument", instrument[0]
else:
for inst in instruments:
if inst in instrument_scripts:
for script in instrument_scripts[inst]:
scripts.append(os.path.join('drivers', inst, script))
else:
print "No such instrument", inst
return scripts
if __name__ == "__main__":
pythonVersionCheck()
instruments = parseCommandLine()
script_list = getScripts(instruments)
setup(name=PACKAGE,
version=VERSION,
extra_path=PACKAGE,
packages=package_list,
scripts=script_list,
cmdclass = {'build_doc': build_doc})