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 2
/
Copy pathsetup.py
executable file
·206 lines (162 loc) · 5.95 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
#!/usr/bin/env python
# Data Object Model
# 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.
#
# $Id$
from distutils.cmd import Command
from distutils.core import setup, Extension
import os
import sys
from DOM_version import version as __version__
# Package name and version information
PACKAGE = "DOM"
VERSION = __version__
# Package list
package_list = ['', 'DST', 'SOM']
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 = ['--with-nexus']
options = parseOptions(argv, keywords)
file_locations = None
if options.get('--with-nexus'):
file_locations = options['--with-nexus'].split(',')
return file_locations
def setupSnsNapiExt(locations):
if locations is None:
nexus_incdir = '/usr/local/include'
nexus_libdir = '/usr/local/lib'
else:
if len(locations) == 1:
nexus_incdir = locations[0]+'/include'
nexus_libdir = locations[0]+'/lib'
else:
nexus_incdir = locations[0]
nexus_libdir = locations[1]
incdir_list = [nexus_incdir]
libdir_list = [nexus_libdir]
nexus_lib = "NeXus"
lib_list_all = [nexus_lib]
if os.uname()[0] == 'Linux':
lib_list_all.append('stdc++')
return [Extension("sns_napi",
[os.path.join('nexus', 'sns_napi.cpp')],
include_dirs = incdir_list,
library_dirs = libdir_list,
libraries = lib_list_all)]
class build_doc(Command):
"""
This class is responsible for creating the API documentation via the
epydoc system.
"""
description = "Build the Python 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.."
# Make SNS NAPI documentation via doxygen
if self.no_sourcecode:
doxygen_conf = os.path.join('doc', 'config_ns.dox')
else:
doxygen_conf = os.path.join('doc', 'config.dox')
doxygen_cmd = "doxygen " + doxygen_conf
fout = os.popen(doxygen_cmd)
output = fout.readlines()
status = fout.close()
if status is not None:
status = status >> 8
if status == 127:
print "Doxygen is needed to create SNAPI docmentation. "\
+"Skipping.."
else:
print "Doxygen execution failed with code %d" % status
else:
# Everything went fine with doxygen, show the output
print "Running doxygen....."
print "".join(output)
if __name__ == "__main__":
pythonVersionCheck()
file_locations = parseCommandLine()
sns_napi_ext = setupSnsNapiExt(file_locations)
setup(name=PACKAGE,
version=VERSION,
extra_path=PACKAGE,
packages=package_list,
ext_modules=sns_napi_ext,
cmdclass = {'build_doc': build_doc})