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 '3.2.dev1' 142def tarball(): 143 return None # XXX remove this line 144 return ('http://ftp.mcs.anl.gov/pub/petsc/<XXX>/' # XXX fix this line 145 'petsc-lite-%s.tar.gz' % version() ) 146 147description = __doc__.split('\n')[1:-1]; del description[1:3] 148classifiers = """ 149License :: Public Domain 150Operating System :: POSIX 151Intended Audience :: Developers 152Intended Audience :: Science/Research 153Programming Language :: C 154Programming Language :: C++ 155Programming Language :: Fortran 156Programming Language :: Python 157Topic :: Scientific/Engineering 158Topic :: Software Development :: Libraries 159""" 160 161bootstrap() 162setup(name='petsc', 163 version=version(), 164 description=description.pop(0), 165 long_description='\n'.join(description), 166 classifiers= classifiers.split('\n')[1:-1], 167 keywords = ['PETSc', 'MPI'], 168 platforms=['POSIX'], 169 license='PETSc', 170 171 provides=['petsc'], 172 requires=[], 173 174 url='http://www.mcs.anl.gov/petsc/', 175 download_url=tarball(), 176 177 author='PETSc Team', 178 author_email='petsc-users@mcs.anl.gov', 179 maintainer='Lisandro Dalcin', 180 maintainer_email='dalcinl@gmail.com', 181 182 packages = ['petsc'], 183 package_dir = {'petsc': os.environ['PETSC_ARCH']}, 184 cmdclass={ 185 'build': cmd_build, 186 'install': cmd_install, 187 }, 188 ) 189