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 48# -------------------------------------------------------------------- 49# Extension modules 50# -------------------------------------------------------------------- 51 52def get_ext_modules(Extension): 53 from os import walk, path 54 from glob import glob 55 depends = [] 56 for pth, dirs, files in walk('src'): 57 depends += glob(path.join(pth, '*.h')) 58 for pth, dirs, files in walk(path.join('src', 'source')): 59 depends += glob(path.join(pth, '*.h')) 60 depends += glob(path.join(pth, '*.c')) 61 try: 62 import numpy 63 numpy_includes = [numpy.get_include()] 64 except ImportError: 65 numpy_includes = [] 66 return [Extension('petsc4py.lib.PETSc', 67 sources=['src/PETSc.c', 68 'src/source/libpetsc4py.c', 69 ], 70 include_dirs=['src/include', 71 'src/source', 72 ] + numpy_includes, 73 depends=depends)] 74 75# -------------------------------------------------------------------- 76# Setup 77# -------------------------------------------------------------------- 78 79from conf.petscconf import setup, Extension 80from conf.petscconf import config, build, build_ext 81 82def main(): 83 setup(packages = ['petsc4py', 84 'petsc4py.lib',], 85 package_dir = {'petsc4py' : 'src', 86 'petsc4py.lib' : 'src/lib'}, 87 package_data = {'petsc4py' : ['include/petsc4py/*.h', 88 'include/petsc4py/*.i', 89 'include/petsc4py/*.pxd', 90 'include/petsc4py/*.pxi', 91 'include/petsc4py/*.pyx',], 92 'petsc4py.lib' : ['petsc.cfg'],}, 93 ext_modules = get_ext_modules(Extension), 94 cmdclass = {'config' : config, 95 'build' : build, 96 'build_ext' : build_ext}, 97 **metadata) 98 99if __name__ == '__main__': 100 import sys, os 101 C_SOURCE = os.path.join('src', 'petsc4py_PETSc.c') 102 def cython_help(): 103 if os.path.exists(C_SOURCE): return 104 warn = lambda msg='': sys.stderr.write(msg+'\n') 105 warn("*"*70) 106 warn() 107 warn("You need to generate C source files with Cython !!!") 108 warn("Please execute in your shell:") 109 warn() 110 warn("$ python ./conf/cythonize.py") 111 warn() 112 warn("*"*70) 113 warn() 114 ## from distutils import log 115 ## log.set_verbosity(log.DEBUG) 116 cython_help() 117 main() 118 119# -------------------------------------------------------------------- 120