forked from usnistgov/fipy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
344 lines (285 loc) · 12.6 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/usr/bin/env python
## -*-Pyth-*-
# ###################################################################
# FiPy - a finite volume PDE solver in Python
#
# FILE: "setup.py"
#
# Author: Jonathan Guyer <[email protected]>
# Author: Daniel Wheeler <[email protected]>
# Author: James Warren <[email protected]>
# Author: Andrew Acquaviva <[email protected]>
# mail: NIST
# www: http://www.ctcms.nist.gov/fipy/
#
# ========================================================================
# This software was developed by employees of the National Institute
# of Standards and Technology, an agency of the Federal Government.
# Pursuant to title 17 section 105 of the United States Code,
# works of NIST employees are not subject to copyright
# protection, and this software is considered to be in the public domain.
# FiPy is an experimental system. NIST assumes no responsibility whatsoever
# for its use by other parties, and makes no guarantees, expressed
# or implied, about its quality, reliability, or any other characteristic.
# We would appreciate acknowledgement if the document is used.
#
# To the extent that NIST may hold copyright in countries other than the
# United States, you are hereby granted the non-exclusive irrevocable and
# unconditional right to print, publish, prepare derivative works and
# distribute this software, in any medium, or authorize others to do so on
# your behalf, on a royalty-free basis throughout the world.
#
# You may improve, modify, and create derivative works of the software or
# any portion of the software, and you may copy and distribute such
# modifications or works. Modified works should carry a notice stating
# that you changed the software and should note the date and nature of any
# such change. Please explicitly acknowledge the National Institute of
# Standards and Technology as the original source.
#
# This software can be redistributed and/or modified freely provided that
# any derivative works bear some notice that they are derived from it, and
# any modified versions bear some notice that they have been modified.
# ========================================================================
#
# ###################################################################
##
import os
from distutils.core import Command
from fipy.tools.performance.efficiency_test import Efficiency_test
from fipy.tools.copy_script import Copy_script
from fipy.tests.testClass import _TestClass
# bootstrap setuptools for users that don't already have it
import ez_setup
ez_setup.use_setuptools()
from setuptools import setup, find_packages
# from fipy.tests.testRunner import test, unittest
from setuptools.command.test import test as _test
test = _TestClass(_test)
try:
# we only need "unittest" if bitten is installed
# (and we're running as a bitten.slave)
from bitten.util.testrunner import unittest as _unittest
unittest = _TestClass(_unittest)
except ImportError, e:
unittest = test
class build_docs(Command):
description = "build the FiPy documentation"
# List of option tuples: long name, short name (None if no short
# name), and help string.
user_options = [('pdf', None, "compile the PDF variant of the documentation"),
('html', None, "compile the HTML variant of the documentation"),
('cathartic', None, "rewrite all the files (default is to only rewrite changed files)"),
]
def initialize_options (self):
self.pdf = 0
self.html = 0
self.cathartic = 0
def finalize_options (self):
pass
def run (self):
import sphinx
from sphinx import apidoc
sphinx_args = ['-P', '-n', '-c', 'documentation/', '.']
apidoc_args = []
if self.cathartic:
sphinx_args = ['-a', '-E'] + sphinx_args
apidoc_args = ['--force'] + apidoc_args
apidoc.main(['sphinx-apidoc', '--output-dir=fipy/generated', '--suffix=rst']
+ apidoc_args + ['fipy'])
apidoc.main(['sphinx-apidoc', '--output-dir=documentation/tutorial/package/generated', '--suffix=rst']
+ apidoc_args + ['documentation/tutorial/package'])
if self.html:
sphinx.main(['sphinx-build', '-b', 'redirecting_html'] + sphinx_args + ['documentation/_build/html/'])
if self.pdf:
try:
sphinx.main(['sphinx-build', '-b', 'latex'] + sphinx_args + ['documentation/_build/latex/'])
except SystemExit:
pass
outdir = os.path.join('documentation', '_build', 'latex')
from docutils.core import publish_file
for xtra in ("LICENSE", "DISCLAIMER"):
publish_file(source_path="%s.rst" % xtra,
destination_path=os.path.join(outdir, "%s.tex" % xtra),
reader_name='standalone',
parser_name='restructuredtext',
writer_name='latex',
settings_overrides= {
'template': 'documentation/_templates/empty.tex'
})
savedir = os.getcwd()
os.chdir(outdir)
os.system("pdflatex fipy")
os.system("pdflatex fipy")
os.system("pdflatex fipy")
os.system("makeindex -s python.ist fipy")
os.system("makeindex -s python.ist modfipy")
os.system("pdflatex fipy")
os.system("pdflatex fipy")
os.chdir(savedir)
class upload_products(Command):
description = "upload FiPy compressed archives to website(s)"
user_options = [('pdf', None, "upload the PDF variant of the documentation"),
('html', None, "upload the HTML variant of the documentation"),
('tarball', None, "upload the .tar.gz source distribution"),
('winzip', None, "upload the .win32.zip distribution"),
]
def initialize_options (self):
self.pdf = 0
self.html = 0
self.tarball = 0
self.winzip = 0
def finalize_options (self):
pass
def run(self):
if self.pdf:
print "setting permissions of manual..."
os.system('chmod -R g+w documentation/_build/latex/fipy.pdf')
print "linking manual to `dist/`..."
os.system('mkdir dist/')
os.system('ln -f documentation/_build/latex/fipy.pdf dist/fipy-%s.pdf'%self.distribution.metadata.get_version())
if self.html:
print "setting group and ownership of web pages..."
os.system('chmod -R g+w documentation/_build/html/')
print "uploading web pages..."
# The -t flag (implicit in -a) is suddenly causing problems
# os.system('rsync -aLC -e ssh %s %s'%('documentation/www/', os.environ['FIPY_WWWHOST']))
os.system('rsync -rlpgoDLC -e ssh %s %s' % ('documentation/_build/html/', os.environ['FIPY_WWWHOST']))
if self.tarball:
file = 'dist/FiPy-%s.tar.gz' % self.distribution.metadata.get_version()
print "setting permissions for %s ..." % file
os.system('chmod -R g+w %s' % file)
print "uploading tarball..."
os.system('rsync -pgoDLC -e ssh %s %s/download/' % (file, os.environ['FIPY_WWWHOST']))
if self.winzip:
file = 'dist/FiPy-%s.win32.zip' % self.distribution.metadata.get_version()
print "setting permissions for %s ..." % file
os.system('chmod -R g+w %s' % file)
print "uploading winzip..."
os.system('rsync -pgoDLC -e ssh %s %s/download/' % (file, os.environ['FIPY_WWWHOST']))
if self.pdf or self.tarball or self.winzip:
print "activating web pages..."
os.system(os.environ['FIPY_WWWACTIVATE'])
try:
f = open('README.rst', 'r')
long_description = '\n' + f.read() + '\n'
f.close()
except IOError, e:
long_description = ''
try:
f = open('LICENSE.rst', 'r')
license = '\n' + ''.join([' '*8 + l for l in f])
f.close()
except IOError, e:
license = ''
# The following doesn't work reliably, because it requires fipy
# to already be installed (or at least egged), which is kind of
# obnoxious. We use cmdclass instead.
#
# entry_points = {
# 'distutils.commands': [
# 'test = fipy.tests.testRunner:test',
# 'unittest = fipy.tests.testRunner:unittest',
# ],
# },
##Hacked from numpy
def getVersion():
import subprocess
import warnings
def _minimal_ext_cmd(cmd):
# construct minimal environment
env = {}
for k in ['SYSTEMROOT', 'PATH']:
v = os.environ.get(k)
if v is not None:
env[k] = v
# LANGUAGE is used on win32
env['LANGUAGE'] = 'C'
env['LANG'] = 'C'
env['LC_ALL'] = 'C'
out = subprocess.check_output(cmd, env=env)
# ticket:475 - fix for bytecode received in Py3k
# http://jeetworks.org/node/67
out = out.decode("utf-8")
return out
version = 'unknown'
if os.path.exists('.git'):
try:
out = _minimal_ext_cmd(['git', 'describe', '--tags', '--match', 'version-*'])
# convert git long-form version string, e.g., "version-3_1_1-127-g413ed61",
# into PEP 440 version, e.g., "3.1.1.dev127+g413ed61"
version = out.strip().split("-")
suffix = version[2:]
version = ".".join(version[1].split("_"))
if suffix:
dev, sha = suffix
version = "%s.dev%s+%s" % (version, dev, sha)
except OSError:
import warnings
warnings.warn("Could not run ``git describe``")
except subprocess.CalledProcessError:
warnings.warn("Could not read git tags")
version = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
version = version.strip()
if (version == 'unknown') and os.path.exists('FiPy.egg-info'):
from fipy import _getVersion
version = _getVersion()
return version
dist = setup( name = "FiPy",
version = getVersion(),
author = "Jonathan Guyer, Daniel Wheeler, & Jim Warren",
author_email = "[email protected]",
url = "http://www.ctcms.nist.gov/fipy/",
license = license,
description = "A finite volume PDE solver in Python",
long_description = long_description,
cmdclass = {
'build_docs':build_docs,
'upload_products':upload_products,
'test':test,
'unittest':unittest,
'copy_script': Copy_script,
'efficiency_test': Efficiency_test
},
test_suite="fipy.testFiPy._suite",
packages = find_packages(exclude=["examples", "examples.*", "utils", "utils.*"]),
entry_points="""
[fipy.viewers]
matplotlib = fipy.viewers.matplotlibViewer:MatplotlibViewer
mayavi = fipy.viewers.mayaviViewer:MayaviClient
""",
classifiers = [
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Environment :: X11 Applications',
'Intended Audience :: Science/Research',
'License :: Public Domain',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Scientific/Engineering :: Physics',
'Topic :: Scientific/Engineering :: Visualization',
'Topic :: Software Development :: Libraries :: Python Modules'
],
)
if 'install' in dist.commands:
req = []
for pkg in ['numpy', 'pysparse']:
try:
__import__(pkg)
except ImportError, exc:
req.append(pkg)
if len(req) > 0:
print "!!!!!!"
print "The required module(s) " + str(req) + " cannot be loaded."
print "FiPy will not work properly until these modules are installed."
opt = []
for pkg in ['scipy', 'matplotlib', 'mayavi']:
try:
__import__(pkg)
except ImportError, exc:
opt.append(pkg)
if len(opt) > 0:
print "------"
print "The optional module(s) " + str(opt) + " cannot be loaded."
print "FiPy will have improved capabilities if these modules are installed."