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 '--with-cmake=0', 60 ] 61 import configure 62 configure.petsc_configure(options) 63 import logger 64 logger.Logger.defaultLog = None 65 66def build(dry_run=False): 67 log.info('PETSc: build') 68 if dry_run: return 69 import builder 70 builder.PETScMaker().run() 71 import logger 72 logger.Logger.defaultLog = None 73 74def install(dest_dir, prefix=None, dry_run=False): 75 log.info('PETSc: install') 76 if dry_run: return 77 if prefix is None: 78 prefix = dest_dir 79 options = [ 80 '--destDir=' + dest_dir, 81 '--prefix=' + prefix 82 ] 83 import install 84 install.Installer(options).run() 85 import logger 86 logger.Logger.defaultLog = None 87 # temporary hack - delete log files created by BuildSystem 88 delfiles=['RDict.db','RDict.log', 89 'build.log','default.log', 90 'build.log.bkp','default.log.bkp'] 91 for delfile in delfiles: 92 try: 93 if (os.path.exists(delfile) and 94 os.stat(delfile).st_uid==0): 95 os.remove(delfile) 96 except: 97 pass 98 99class cmd_build(_build): 100 101 def finalize_options(self): 102 if self.build_base is None: 103 self.build_base= 'build' 104 self.build_base = os.path.join( 105 os.environ['PETSC_ARCH'], self.build_base) 106 _build.finalize_options(self) 107 108 def run(self): 109 _build.run(self) 110 wdir = os.getcwd() 111 pdir = os.environ['PETSC_DIR'] 112 try: 113 os.chdir(pdir) 114 config(self.dry_run) 115 build(self.dry_run) 116 finally: 117 os.chdir(wdir) 118 119class cmd_install(_install): 120 121 def run(self): 122 _install.run(self) 123 root_dir = self.install_platlib 124 dest_dir = os.path.join(root_dir, 'petsc') 125 bdist_base = self.get_finalized_command('bdist').bdist_base 126 if dest_dir.startswith(bdist_base): 127 prefix = dest_dir[len(bdist_base)+1:] 128 prefix = prefix[prefix.index(os.path.sep):] 129 else: 130 prefix = dest_dir 131 dest_dir = os.path.abspath(dest_dir) 132 prefix = os.path.abspath(prefix) 133 wdir = os.getcwd() 134 pdir = os.environ['PETSC_DIR'] 135 try: 136 os.chdir(pdir) 137 install(dest_dir, prefix, self.dry_run) 138 finally: 139 os.chdir(wdir) 140 141def version(): 142 return '3.2.dev1' 143def tarball(): 144 return "http://petsc.cs.iit.edu/petsc/petsc-dev/archive/tip.tar.gz" 145 return ('http://ftp.mcs.anl.gov/pub/petsc/<XXX>/' # XXX fix this line 146 'petsc-lite-%s.tar.gz' % version() ) 147 148description = __doc__.split('\n')[1:-1]; del description[1:3] 149classifiers = """ 150License :: Public Domain 151Operating System :: POSIX 152Intended Audience :: Developers 153Intended Audience :: Science/Research 154Programming Language :: C 155Programming Language :: C++ 156Programming Language :: Fortran 157Programming Language :: Python 158Topic :: Scientific/Engineering 159Topic :: Software Development :: Libraries 160""" 161 162bootstrap() 163setup(name='petsc', 164 version=version(), 165 description=description.pop(0), 166 long_description='\n'.join(description), 167 classifiers= classifiers.split('\n')[1:-1], 168 keywords = ['PETSc', 'MPI'], 169 platforms=['POSIX'], 170 license='PETSc', 171 172 provides=['petsc'], 173 requires=[], 174 175 url='http://www.mcs.anl.gov/petsc/', 176 download_url=tarball(), 177 178 author='PETSc Team', 179 author_email='petsc-users@mcs.anl.gov', 180 maintainer='Lisandro Dalcin', 181 maintainer_email='dalcinl@gmail.com', 182 183 packages = ['petsc'], 184 package_dir = {'petsc': os.environ['PETSC_ARCH']}, 185 cmdclass={ 186 'build': cmd_build, 187 'install': cmd_install, 188 }, 189 ) 190