1#!/usr/bin/env python 2 3""" 4PETSc for Python 5================ 6 7Python bindings for PETSc libraries. 8""" 9 10 11## try: 12## import setuptools 13## except ImportError: 14## pass 15 16 17# ----------------------------------------------------------------------------- 18# Metadata 19# ----------------------------------------------------------------------------- 20 21from conf.metadata import metadata 22 23def version(): 24 import os, re 25 data = open(os.path.join('src', '__init__.py')).read() 26 m = re.search(r"__version__\s*=\s*'(.*)'", data) 27 return m.groups()[0] 28 29name = 'petsc4py' 30version = version() 31 32url = 'http://%(name)s.googlecode.com/' % vars() 33download = url + 'files/%(name)s-%(version)s.tar.gz' % vars() 34 35descr = __doc__.strip().split('\n'); del descr[1:3] 36devstat = ['Development Status :: 3 - Alpha'] 37keywords = ['PETSc', 'MPI'] 38 39metadata['name'] = name 40metadata['version'] = version 41metadata['description'] = descr.pop(0) 42metadata['long_description'] = '\n'.join(descr) 43metadata['keywords'] += keywords 44metadata['classifiers'] += devstat 45metadata['url'] = url 46metadata['download_url'] = download 47 48metadata['provides'] = ['petsc4py'] 49metadata['requires'] = ['numpy'] 50 51# ----------------------------------------------------------------------------- 52# Extension modules 53# ----------------------------------------------------------------------------- 54 55def get_ext_modules(Extension): 56 from os import walk, path 57 from glob import glob 58 depends = [] 59 for pth, dirs, files in walk('src'): 60 depends += glob(path.join(pth, '*.h')) 61 for pth, dirs, files in walk(path.join('src', 'source')): 62 depends += glob(path.join(pth, '*.h')) 63 depends += glob(path.join(pth, '*.c')) 64 try: 65 import numpy 66 numpy_includes = [numpy.get_include()] 67 except ImportError: 68 numpy_includes = [] 69 return [Extension('petsc4py.lib.PETSc', 70 sources=['src/PETSc.c', 71 'src/source/libpetsc4py.c', 72 ], 73 include_dirs=['src/include', 74 'src/source', 75 ] + numpy_includes, 76 depends=depends)] 77 78# ----------------------------------------------------------------------------- 79# Setup 80# ----------------------------------------------------------------------------- 81 82from conf.petscconf import setup, Extension 83from conf.petscconf import config, build, build_ext 84 85def run_setup(): 86 setup(packages = ['petsc4py', 87 'petsc4py.lib',], 88 package_dir = {'petsc4py' : 'src', 89 'petsc4py.lib' : 'src/lib'}, 90 package_data = {'petsc4py' : ['include/petsc4py/*.h', 91 'include/petsc4py/*.i', 92 'include/petsc4py/*.pxd', 93 'include/petsc4py/*.pxi', 94 'include/petsc4py/*.pyx',], 95 'petsc4py.lib' : ['petsc.cfg'],}, 96 ext_modules = get_ext_modules(Extension), 97 cmdclass = {'config' : config, 98 'build' : build, 99 'build_ext' : build_ext}, 100 **metadata) 101 102def run_cython(*C_SOURCE): 103 import sys, os 104 if os.path.exists(os.path.join(*C_SOURCE)): return 105 if "install" not in sys.argv: return 106 warn = lambda msg='': sys.stderr.write(msg+'\n') 107 warn("*"*80) 108 warn() 109 warn(" Attempting to generate C source files with Cython!!") 110 warn() 111 warn("*"*80) 112 try: 113 import conf.cythonize 114 conf.cythonize.run('petsc4py.PETSc.pyx', wdir='src') 115 except ImportError: 116 warn("*"*80) 117 warn() 118 warn(" Download and install Cython <http://www.cython.org>") 119 warn(" and next execute in your shell:") 120 warn() 121 warn(" $ python ./conf/cythonize.py") 122 warn() 123 warn("*"*80) 124 raise 125 except: 126 warn("*"*80) 127 warn() 128 warn(" Unable to generate C source files with Cython!!") 129 warn() 130 warn("*"*80) 131 raise 132 133if __name__ == '__main__': 134 run_cython('src', 'petsc4py.PETSc.c') 135 try: 136 run_setup() 137 except: 138 raise 139 140# ----------------------------------------------------------------------------- 141