xref: /petsc/setup.py (revision a32381aeb5effcbafcbf6d73fdf8ff1528782d97)
1#!/usr/bin/env python
2
3"""
4PETSc: Portable, Extensible Toolkit for Scientific Computation
5==============================================================
6
7The Portable, Extensible Toolkit for Scientific Computation (PETSc),
8is a suite of data structures and routines for the scalable (parallel)
9solution of scientific applications modeled by partial differential
10equations. It employs the Message Passing Interface (MPI) standard for
11all message-passing communication.
12"""
13
14import sys, os
15from distutils.core import setup
16from distutils.util import get_platform
17from distutils.command.build import build as _build
18if 'setuptools' in sys.modules:
19    from setuptools.command.install import install as _install
20else:
21    from distutils.command.install import install as _install
22from distutils.command.sdist import sdist as _sdist
23from distutils import log
24
25init_py = """\
26# Author:  PETSc Team
27# Contact: petsc-users@mcs.anl.gov
28
29def get_petsc_dir():
30    import os
31    return os.path.dirname(__file__)
32
33def get_petsc_arch():
34    return ''
35
36def get_config():
37    conf = {}
38    conf['petsc_dir'] = get_petsc_dir()
39    return conf
40"""
41
42def bootstrap():
43    PETSC_DIR  = os.path.abspath(os.getcwd())
44    PETSC_ARCH = get_platform() + '-python'
45    os.environ['PETSC_DIR']  = PETSC_DIR
46    os.environ['PETSC_ARCH'] = PETSC_ARCH
47    sys.path.insert(0, os.path.join(PETSC_DIR, 'config'))
48    try:
49        if not os.path.exists(PETSC_ARCH):
50            os.mkdir(PETSC_ARCH)
51        pkgfile = os.path.join(PETSC_ARCH, '__init__.py')
52        if not os.path.exists(pkgfile):
53            open(pkgfile, 'wt').write(init_py)
54    except:
55        pass
56
57def config(dry_run=False):
58    log.info('PETSc: configure')
59    if dry_run: return
60    options = [
61        'PETSC_ARCH='+os.environ['PETSC_ARCH'],
62        '--with-shared-libraries',
63        '--with-fc=0',
64        '--with-mpi=0',
65        '--with-cmake=0',
66        ]
67    import configure
68    configure.petsc_configure(options)
69    import logger
70    logger.Logger.defaultLog = None
71
72def build(dry_run=False):
73    log.info('PETSc: build')
74    if dry_run: return
75    import builder
76    builder.PETScMaker().run()
77    import logger
78    logger.Logger.defaultLog = None
79
80def install(dest_dir, prefix=None, dry_run=False):
81    log.info('PETSc: install')
82    if dry_run: return
83    if prefix is None:
84        prefix = dest_dir
85    options = [
86        '--destDir=' + dest_dir,
87        '--prefix='  + prefix
88        ]
89    import install
90    install.Installer(options).run()
91    import logger
92    logger.Logger.defaultLog = None
93    # temporary hack - delete log files created by BuildSystem
94    delfiles=['RDict.db','RDict.log',
95              'build.log','default.log',
96              'build.log.bkp','default.log.bkp']
97    for delfile in delfiles:
98        try:
99            if (os.path.exists(delfile) and
100                os.stat(delfile).st_uid==0):
101                os.remove(delfile)
102        except:
103            pass
104
105class cmd_build(_build):
106
107    def finalize_options(self):
108        if self.build_base is None:
109            self.build_base= 'build'
110        self.build_base = os.path.join(
111            os.environ['PETSC_ARCH'], self.build_base)
112        _build.finalize_options(self)
113
114    def run(self):
115        _build.run(self)
116        wdir = os.getcwd()
117        pdir = os.environ['PETSC_DIR']
118        try:
119            os.chdir(pdir)
120            config(self.dry_run)
121            build(self.dry_run)
122        finally:
123            os.chdir(wdir)
124
125class cmd_install(_install):
126
127    def run(self):
128        _install.run(self)
129        root_dir = self.install_platlib
130        dest_dir = os.path.join(root_dir, 'petsc')
131        bdist_base = self.get_finalized_command('bdist').bdist_base
132        if dest_dir.startswith(bdist_base):
133            prefix = dest_dir[len(bdist_base)+1:]
134            prefix = prefix[prefix.index(os.path.sep):]
135        else:
136            prefix = dest_dir
137        dest_dir = os.path.abspath(dest_dir)
138        prefix = os.path.abspath(prefix)
139        wdir = os.getcwd()
140        pdir = os.environ['PETSC_DIR']
141        try:
142            os.chdir(pdir)
143            install(dest_dir, prefix, self.dry_run)
144        finally:
145            os.chdir(wdir)
146
147class cmd_sdist(_sdist):
148
149    def initialize_options(self):
150        _sdist.initialize_options(self)
151        self.force_manifest = 1
152        self.template = os.path.join('config', 'MANIFEST.in')
153
154    def run(self):
155        _sdist.run(self)
156        try:
157            os.remove(self.manifest)
158        except Exception:
159            pass
160
161def version():
162    return '3.2.dev1'
163def tarball():
164    return None
165    return ('http://ftp.mcs.anl.gov/pub/petsc/<XXX>/' # XXX fix this line
166            'petsc-lite-%s.tar.gz' % version() )
167
168description = __doc__.split('\n')[1:-1]; del description[1:3]
169classifiers = """
170License :: Public Domain
171Operating System :: POSIX
172Intended Audience :: Developers
173Intended Audience :: Science/Research
174Programming Language :: C
175Programming Language :: C++
176Programming Language :: Fortran
177Programming Language :: Python
178Topic :: Scientific/Engineering
179Topic :: Software Development :: Libraries
180"""
181
182bootstrap()
183setup(name='petsc',
184      version=version(),
185      description=description.pop(0),
186      long_description='\n'.join(description),
187      classifiers= classifiers.split('\n')[1:-1],
188      keywords = ['PETSc', 'MPI'],
189      platforms=['POSIX'],
190      license='PETSc',
191
192      provides=['petsc'],
193      requires=[],
194
195      url='http://www.mcs.anl.gov/petsc/',
196      download_url=tarball(),
197
198      author='PETSc Team',
199      author_email='petsc-users@mcs.anl.gov',
200      maintainer='Lisandro Dalcin',
201      maintainer_email='dalcinl@gmail.com',
202
203      packages = ['petsc'],
204      package_dir = {'petsc': os.environ['PETSC_ARCH']},
205      cmdclass={
206        'build': cmd_build,
207        'install': cmd_install,
208        'sdist': cmd_sdist,
209        },
210      )
211