| 2196 |
jroman |
1 |
#!/usr/bin/env python
|
|
|
2 |
|
|
|
3 |
"""
|
|
|
4 |
SLEPc: Scalable Library for Eigenvalue Problem Computations
|
|
|
5 |
===========================================================
|
|
|
6 |
|
|
|
7 |
SLEPc is a software library for the solution of large scale sparse
|
|
|
8 |
eigenvalue problems on parallel computers. It is an extension of PETSc
|
|
|
9 |
and can be used for either standard or generalized eigenproblems, with
|
|
|
10 |
real or complex arithmetic. It can also be used for computing a
|
|
|
11 |
partial SVD of a large, sparse, rectangular matrix, and to solve
|
|
|
12 |
quadratic eigenvalue problems
|
| 2548 |
eromero |
13 |
|
|
|
14 |
.. tip::
|
|
|
15 |
|
|
|
16 |
You can also install `slepc-dev`_ with::
|
|
|
17 |
|
|
|
18 |
$ pip install slepc==dev petsc==dev
|
|
|
19 |
|
|
|
20 |
.. _petsc-dev: http://www.grycap.upv.es/slepc/
|
|
|
21 |
svn/trunk/#egg=slepc-dev
|
| 2196 |
jroman |
22 |
"""
|
|
|
23 |
|
|
|
24 |
import sys, os
|
|
|
25 |
from distutils.core import setup
|
|
|
26 |
from distutils.util import get_platform
|
|
|
27 |
from distutils.spawn import find_executable
|
|
|
28 |
from distutils.command.build import build as _build
|
|
|
29 |
if 'setuptools' in sys.modules:
|
|
|
30 |
from setuptools.command.install import install as _install
|
|
|
31 |
else:
|
|
|
32 |
from distutils.command.install import install as _install
|
|
|
33 |
from distutils.command.sdist import sdist as _sdist
|
|
|
34 |
from distutils import log
|
|
|
35 |
|
|
|
36 |
init_py = """\
|
|
|
37 |
# Author: SLEPc Team
|
|
|
38 |
# Contact: slepc-maint@grycap.upv.es
|
|
|
39 |
|
|
|
40 |
def get_slepc_dir():
|
|
|
41 |
import os
|
|
|
42 |
return os.path.dirname(__file__)
|
|
|
43 |
|
|
|
44 |
def get_config():
|
|
|
45 |
conf = {}
|
|
|
46 |
conf['SLEPC_DIR'] = get_slepc_dir()
|
|
|
47 |
return conf
|
|
|
48 |
"""
|
|
|
49 |
|
|
|
50 |
metadata = {
|
|
|
51 |
'provides' : ['slepc'],
|
|
|
52 |
'requires' : [],
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
def bootstrap():
|
| 2548 |
eromero |
56 |
from os.path import join, isdir, abspath
|
| 2196 |
jroman |
57 |
# Set SLEPC_DIR
|
| 2548 |
eromero |
58 |
SLEPC_DIR = abspath(os.getcwd())
|
| 2196 |
jroman |
59 |
os.environ['SLEPC_DIR'] = SLEPC_DIR
|
| 2548 |
eromero |
60 |
# Check PETSC_DIR/PETSC_ARCH
|
|
|
61 |
PETSC_DIR = os.environ.get('PETSC_DIR', "")
|
|
|
62 |
PETSC_ARCH = os.environ.get('PETSC_ARCH', "")
|
|
|
63 |
if not (PETSC_DIR and isdir(PETSC_DIR)):
|
|
|
64 |
PETSC_DIR = None
|
|
|
65 |
try: del os.environ['PETSC_DIR']
|
|
|
66 |
except KeyError: pass
|
|
|
67 |
PETSC_ARCH = None
|
| 2196 |
jroman |
68 |
try: del os.environ['PETSC_ARCH']
|
|
|
69 |
except KeyError: pass
|
| 2548 |
eromero |
70 |
elif not isdir(join(PETSC_DIR, PETSC_ARCH)):
|
|
|
71 |
PETSC_ARCH = None
|
|
|
72 |
try: del os.environ['PETSC_ARCH']
|
|
|
73 |
except KeyError: pass
|
| 2196 |
jroman |
74 |
# Generate package __init__.py file
|
|
|
75 |
from distutils.dir_util import mkpath
|
|
|
76 |
pkgdir = os.path.join('config', 'pypi')
|
|
|
77 |
pkgfile = os.path.join(pkgdir, '__init__.py')
|
| 2548 |
eromero |
78 |
if not os.path.exists(pkgdir): mkpath(pkgdir)
|
|
|
79 |
fh = open(pkgfile, 'wt')
|
|
|
80 |
fh.write(init_py)
|
|
|
81 |
fh.close()
|
|
|
82 |
if ('setuptools' in sys.modules):
|
| 2196 |
jroman |
83 |
metadata['zip_safe'] = False
|
| 2548 |
eromero |
84 |
if not PETSC_DIR:
|
|
|
85 |
metadata['install_requires']= ['petsc>=3.2,<3.3']
|
| 2196 |
jroman |
86 |
|
|
|
87 |
def get_petsc_dir():
|
|
|
88 |
PETSC_DIR = os.environ.get('PETSC_DIR')
|
| 2548 |
eromero |
89 |
if PETSC_DIR: return PETSC_DIR
|
|
|
90 |
try:
|
|
|
91 |
import petsc
|
|
|
92 |
PETSC_DIR = petsc.get_petsc_dir()
|
|
|
93 |
except ImportError:
|
|
|
94 |
log.warn("PETSC_DIR not specified")
|
|
|
95 |
PETSC_DIR = os.path.join(os.path.sep, 'usr', 'local', 'petsc')
|
| 2196 |
jroman |
96 |
return PETSC_DIR
|
|
|
97 |
|
|
|
98 |
def get_petsc_arch():
|
| 2548 |
eromero |
99 |
PETSC_ARCH = os.environ.get('PETSC_ARCH') or 'arch-installed-petsc'
|
| 2196 |
jroman |
100 |
return PETSC_ARCH
|
|
|
101 |
|
|
|
102 |
def config(dry_run=False):
|
|
|
103 |
log.info('SLEPc: configure')
|
|
|
104 |
if dry_run: return
|
|
|
105 |
# PETSc
|
|
|
106 |
# Run SLEPc configure
|
|
|
107 |
os.environ['PETSC_DIR'] = get_petsc_dir()
|
|
|
108 |
status = os.system(" ".join((
|
|
|
109 |
find_executable('python'),
|
|
|
110 |
os.path.join('config', 'configure.py'),
|
|
|
111 |
)))
|
|
|
112 |
if status != 0: raise RuntimeError(status)
|
|
|
113 |
|
|
|
114 |
def build(dry_run=False):
|
|
|
115 |
log.info('SLEPc: build')
|
|
|
116 |
if dry_run: return
|
|
|
117 |
# Run SLEPc build
|
|
|
118 |
status = os.system(" ".join((
|
|
|
119 |
find_executable('make'),
|
|
|
120 |
'PETSC_DIR='+get_petsc_dir(),
|
|
|
121 |
'PETSC_ARCH='+get_petsc_arch(),
|
|
|
122 |
'all',
|
|
|
123 |
)))
|
|
|
124 |
if status != 0: raise RuntimeError
|
|
|
125 |
|
|
|
126 |
def install(dest_dir, prefix=None, dry_run=False):
|
|
|
127 |
log.info('SLEPc: install')
|
|
|
128 |
if dry_run: return
|
|
|
129 |
if prefix is None:
|
|
|
130 |
prefix = dest_dir
|
|
|
131 |
PETSC_ARCH = get_petsc_arch()
|
|
|
132 |
# Run SLEPc install
|
|
|
133 |
status = os.system(" ".join((
|
|
|
134 |
find_executable('make'),
|
|
|
135 |
'PETSC_DIR='+get_petsc_dir(),
|
|
|
136 |
'PETSC_ARCH='+get_petsc_arch(),
|
| 2548 |
eromero |
137 |
'SLEPC_DESTDIR='+dest_dir,
|
| 2196 |
jroman |
138 |
'install',
|
|
|
139 |
)))
|
|
|
140 |
if status != 0: raise RuntimeError
|
|
|
141 |
slepcvariables = os.path.join(dest_dir, 'conf', 'slepcvariables')
|
| 2548 |
eromero |
142 |
fh = open(slepcvariables, 'a')
|
|
|
143 |
fh.write('SLEPC_DESTDIR=%s\n' % prefix)
|
|
|
144 |
fh.close()
|
| 2196 |
jroman |
145 |
|
|
|
146 |
class context:
|
|
|
147 |
def __init__(self):
|
|
|
148 |
self.sys_argv = sys.argv[:]
|
|
|
149 |
self.wdir = os.getcwd()
|
|
|
150 |
def enter(self):
|
|
|
151 |
del sys.argv[1:]
|
|
|
152 |
pdir = os.environ['SLEPC_DIR']
|
|
|
153 |
os.chdir(pdir)
|
|
|
154 |
return self
|
|
|
155 |
def exit(self):
|
|
|
156 |
sys.argv[:] = self.sys_argv
|
|
|
157 |
os.chdir(self.wdir)
|
|
|
158 |
|
|
|
159 |
class cmd_build(_build):
|
|
|
160 |
|
|
|
161 |
def initialize_options(self):
|
|
|
162 |
_build.initialize_options(self)
|
| 2548 |
eromero |
163 |
PETSC_ARCH = os.environ.get('PETSC_ARCH', 'arch-installed-petsc')
|
| 2196 |
jroman |
164 |
self.build_base = os.path.join(PETSC_ARCH, 'build-python')
|
|
|
165 |
|
|
|
166 |
def run(self):
|
|
|
167 |
_build.run(self)
|
|
|
168 |
ctx = context().enter()
|
|
|
169 |
try:
|
|
|
170 |
config(self.dry_run)
|
|
|
171 |
build(self.dry_run)
|
|
|
172 |
finally:
|
|
|
173 |
ctx.exit()
|
|
|
174 |
|
|
|
175 |
class cmd_install(_install):
|
|
|
176 |
|
|
|
177 |
def initialize_options(self):
|
|
|
178 |
_install.initialize_options(self)
|
|
|
179 |
self.optimize = 1
|
|
|
180 |
|
|
|
181 |
def run(self):
|
|
|
182 |
root_dir = self.install_platlib
|
|
|
183 |
dest_dir = os.path.join(root_dir, 'slepc')
|
|
|
184 |
bdist_base = self.get_finalized_command('bdist').bdist_base
|
|
|
185 |
if dest_dir.startswith(bdist_base):
|
|
|
186 |
prefix = dest_dir[len(bdist_base)+1:]
|
|
|
187 |
prefix = prefix[prefix.index(os.path.sep):]
|
|
|
188 |
else:
|
|
|
189 |
prefix = dest_dir
|
|
|
190 |
dest_dir = os.path.abspath(dest_dir)
|
|
|
191 |
prefix = os.path.abspath(prefix)
|
|
|
192 |
#
|
|
|
193 |
_install.run(self)
|
|
|
194 |
ctx = context().enter()
|
|
|
195 |
try:
|
|
|
196 |
install(dest_dir, prefix, self.dry_run)
|
|
|
197 |
finally:
|
|
|
198 |
ctx.exit()
|
|
|
199 |
|
|
|
200 |
class cmd_sdist(_sdist):
|
|
|
201 |
|
|
|
202 |
def initialize_options(self):
|
|
|
203 |
_sdist.initialize_options(self)
|
|
|
204 |
self.force_manifest = 1
|
|
|
205 |
self.template = os.path.join('config', 'manifest.in')
|
|
|
206 |
|
|
|
207 |
def version():
|
|
|
208 |
import re
|
|
|
209 |
version_re = {
|
|
|
210 |
'major' : re.compile(r"#define\s+SLEPC_VERSION_MAJOR\s+(\d+)"),
|
|
|
211 |
'minor' : re.compile(r"#define\s+SLEPC_VERSION_MINOR\s+(\d+)"),
|
|
|
212 |
'micro' : re.compile(r"#define\s+SLEPC_VERSION_SUBMINOR\s+(\d+)"),
|
|
|
213 |
'patch' : re.compile(r"#define\s+SLEPC_VERSION_PATCH\s+(\d+)"),
|
|
|
214 |
'release': re.compile(r"#define\s+SLEPC_VERSION_RELEASE\s+(\d+)"),
|
|
|
215 |
}
|
|
|
216 |
slepcversion_h = os.path.join('include','slepcversion.h')
|
|
|
217 |
data = open(slepcversion_h, 'rt').read()
|
|
|
218 |
major = int(version_re['major'].search(data).groups()[0])
|
|
|
219 |
minor = int(version_re['minor'].search(data).groups()[0])
|
|
|
220 |
micro = int(version_re['micro'].search(data).groups()[0])
|
|
|
221 |
patch = int(version_re['patch'].search(data).groups()[0])
|
|
|
222 |
release = int(version_re['release'].search(data).groups()[0])
|
|
|
223 |
if release:
|
|
|
224 |
v = "%d.%d" % (major, minor)
|
|
|
225 |
if micro > 0:
|
|
|
226 |
v += ".%d" % micro
|
|
|
227 |
if patch > 0:
|
| 2669 |
jroman |
228 |
v += ".%d" % patch
|
| 2196 |
jroman |
229 |
else:
|
|
|
230 |
v = "%d.%d.dev%d" % (major, minor+1, 0)
|
|
|
231 |
return v
|
|
|
232 |
|
|
|
233 |
def tarball():
|
|
|
234 |
VERSION = version()
|
|
|
235 |
if '.dev' in VERSION:
|
|
|
236 |
return None
|
| 2669 |
jroman |
237 |
bits = VERSION.split('.')
|
|
|
238 |
if len(bits) == 2: bits.append('0')
|
|
|
239 |
VERSION = '.'.join(bits[:-1]) + '-p' + bits[-1]
|
| 2196 |
jroman |
240 |
return ('http://www.grycap.upv.es/slepc/download/distrib/' +
|
| 2548 |
eromero |
241 |
'slepc-%s.tar.gz' % VERSION)
|
| 2196 |
jroman |
242 |
|
|
|
243 |
description = __doc__.split('\n')[1:-1]; del description[1:3]
|
|
|
244 |
classifiers = """
|
|
|
245 |
License :: Public Domain
|
|
|
246 |
Operating System :: POSIX
|
|
|
247 |
Intended Audience :: Developers
|
|
|
248 |
Intended Audience :: Science/Research
|
|
|
249 |
Programming Language :: C
|
|
|
250 |
Programming Language :: C++
|
|
|
251 |
Programming Language :: Fortran
|
|
|
252 |
Programming Language :: Python
|
|
|
253 |
Topic :: Scientific/Engineering
|
|
|
254 |
Topic :: Software Development :: Libraries
|
|
|
255 |
"""
|
|
|
256 |
|
|
|
257 |
bootstrap()
|
|
|
258 |
setup(name='slepc',
|
|
|
259 |
version=version(),
|
|
|
260 |
description=description.pop(0),
|
|
|
261 |
long_description='\n'.join(description),
|
|
|
262 |
classifiers= classifiers.split('\n')[1:-1],
|
|
|
263 |
keywords = ['SLEPc','PETSc', 'MPI'],
|
|
|
264 |
platforms=['POSIX'],
|
|
|
265 |
license='LGPL',
|
|
|
266 |
|
|
|
267 |
url='http://www.grycap.upv.es/slepc/',
|
|
|
268 |
download_url=tarball(),
|
|
|
269 |
|
|
|
270 |
author='SLEPc Team',
|
|
|
271 |
author_email='slepc-maint@grycap.upv.es',
|
|
|
272 |
maintainer='Lisandro Dalcin',
|
|
|
273 |
maintainer_email='dalcinl@gmail.com',
|
|
|
274 |
|
|
|
275 |
packages = ['slepc'],
|
|
|
276 |
package_dir = {'slepc': 'config/pypi'},
|
|
|
277 |
cmdclass={
|
|
|
278 |
'build': cmd_build,
|
|
|
279 |
'install': cmd_install,
|
|
|
280 |
'sdist': cmd_sdist,
|
|
|
281 |
},
|
|
|
282 |
**metadata)
|