xref: /petsc/setup.py (revision 65a891e713130eb242d09a225ca12d6830e292b3)
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 import log
23
24init_py = """\
25# Author:  Lisandro Dalcin
26# Contact: dalcinl@gmail.com
27
28def get_petsc_dir():
29    import os
30    return os.path.dirname(__file__)
31
32def get_petsc_arch():
33    return ''
34"""
35
36def bootstrap():
37    PETSC_DIR  = os.path.abspath(os.getcwd())
38    PETSC_ARCH = get_platform() + '-python'
39    os.environ['PETSC_DIR']  = PETSC_DIR
40    os.environ['PETSC_ARCH'] = PETSC_ARCH
41    sys.path.insert(0, os.path.join(PETSC_DIR, 'config'))
42    try:
43        if not os.path.exists(PETSC_ARCH):
44            os.mkdir(PETSC_ARCH)
45        pkgfile = os.path.join(PETSC_ARCH, '__init__.py')
46        if not os.path.exists(pkgfile):
47            open(pkgfile, 'wt').write(init_py)
48    except:
49        pass
50
51def config(dry_run=False):
52    log.info('PETSc: configure')
53    if dry_run: return
54    options = [
55        'PETSC_ARCH='+os.environ['PETSC_ARCH'],
56        '--with-shared-libraries',
57        '--with-fc=0',
58        '--with-mpi=0',
59        ]
60    import configure
61    configure.petsc_configure(options)
62    import logger
63    logger.Logger.defaultLog = None
64
65def build(dry_run=False):
66    log.info('PETSc: build')
67    if dry_run: return
68    import builder
69    builder.PETScMaker().run()
70    import logger
71    logger.Logger.defaultLog = None
72
73def install(dest_dir, prefix=None, dry_run=False):
74    log.info('PETSc: install')
75    if dry_run: return
76    if prefix is None:
77        prefix = dest_dir
78    options = [
79        '--destDir=' + dest_dir,
80        '--prefix='  + prefix
81        ]
82    import install
83    install.Installer(options).run()
84    import logger
85    logger.Logger.defaultLog = None
86    # temporary hack - delete log files created by BuildSystem
87    delfiles=['RDict.db','RDict.log',
88              'build.log','default.log',
89              'build.log.bkp','default.log.bkp']
90    for delfile in delfiles:
91        try:
92            if (os.path.exists(delfile) and
93                os.stat(delfile).st_uid==0):
94                os.remove(delfile)
95        except:
96            pass
97
98class cmd_build(_build):
99
100    def finalize_options(self):
101        if self.build_base is None:
102            self.build_base= 'build'
103        self.build_base = os.path.join(
104            os.environ['PETSC_ARCH'], self.build_base)
105        _build.finalize_options(self)
106
107    def run(self):
108        _build.run(self)
109        wdir = os.getcwd()
110        pdir = os.environ['PETSC_DIR']
111        try:
112            os.chdir(pdir)
113            config(self.dry_run)
114            build(self.dry_run)
115        finally:
116            os.chdir(wdir)
117
118class cmd_install(_install):
119
120    def run(self):
121        _install.run(self)
122        root_dir = self.install_platlib
123        dest_dir = os.path.join(root_dir, 'petsc')
124        bdist_base = self.get_finalized_command('bdist').bdist_base
125        if dest_dir.startswith(bdist_base):
126            prefix = dest_dir[len(bdist_base)+1:]
127            prefix = prefix[prefix.index(os.path.sep):]
128        else:
129            prefix = dest_dir
130        dest_dir = os.path.abspath(dest_dir)
131        prefix = os.path.abspath(prefix)
132        wdir = os.getcwd()
133        pdir = os.environ['PETSC_DIR']
134        try:
135            os.chdir(pdir)
136            install(dest_dir, prefix, self.dry_run)
137        finally:
138            os.chdir(wdir)
139
140def version():
141    return 'dev'
142def tarball():
143    return None
144
145description = __doc__.split('\n')[1:-1]; del description[1:3]
146classifiers = """
147License :: Public Domain
148Operating System :: POSIX
149Intended Audience :: Developers
150Intended Audience :: Science/Research
151Programming Language :: C
152Programming Language :: C++
153Programming Language :: Fortran
154Programming Language :: Python
155Topic :: Scientific/Engineering
156Topic :: Software Development :: Libraries
157"""
158
159bootstrap()
160setup(name='petsc',
161      version=version(),
162      description=description.pop(0),
163      long_description='\n'.join(description),
164      classifiers= classifiers.split('\n')[1:-1],
165      keywords = ['PETSc', 'MPI'],
166      platforms=['POSIX'],
167      license='PETSc',
168
169      provides=['petsc'],
170      requires=[],
171
172      url='http://www.mcs.anl.gov/petsc/',
173      download_url=tarball(),
174
175      author='PETSc Team',
176      author_email='petsc-users@mcs.anl.gov',
177      maintainer='Lisandro Dalcin',
178      maintainer_email='dalcinl@gmail.com',
179
180      packages = ['petsc'],
181      package_dir = {'petsc': os.environ['PETSC_ARCH']},
182      cmdclass={
183        'build': cmd_build,
184        'install': cmd_install,
185        },
186      )
187