xref: /petsc/setup.py (revision c626558a411d3e14cb33657ba3d2dd751b344553)
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
23name     = 'petsc4py'
24version  = open('VERSION.txt').read().strip()
25descr    = __doc__.strip().split('\n'); del descr[1:3]
26keywords = ['PETSc','MPI']
27devstat  = ['Development Status :: 3 - Alpha']
28url      = 'http://%s.googlecode.com/' % name
29download = 'http://%s.googlecode.com/files/%s-%s.tar.gz'
30download = download % (name, name, version)
31
32metadata['name'] = name
33metadata['version'] = version
34metadata['description'] = descr.pop(0)
35metadata['long_description'] = '\n'.join(descr)
36metadata['keywords'] += keywords
37metadata['classifiers'] += devstat
38metadata['url'] = url
39metadata['download_url'] = download
40
41# --------------------------------------------------------------------
42# Extension modules
43# --------------------------------------------------------------------
44
45def get_ext_modules(Extension):
46    from os   import walk, path
47    from glob import glob
48    depends = []
49    for pth, dirs, files in walk('src'):
50        depends += glob(path.join(pth, '*.h'))
51    for pth, dirs, files in walk(path.join('src', 'source')):
52        depends += glob(path.join(pth, '*.h'))
53        depends += glob(path.join(pth, '*.c'))
54    return [Extension('petsc4py.lib.PETSc',
55                      sources=['src/PETSc.c',
56                               'src/source/libpetsc4py.c',],
57                      include_dirs=['src/include',
58                                    'src/source',],
59                      depends=depends, language='c'),
60            Extension('petsc4py.lib.PETSc',
61                      sources=['src/PETSc.cpp',
62                               'src/source/libpetsc4py.cpp',],
63                      include_dirs=['src/include',
64                                    'src/source',],
65                      depends=depends, language='c++'),
66            ]
67# --------------------------------------------------------------------
68# Setup
69# --------------------------------------------------------------------
70
71from conf.petscconf import setup, Extension
72from conf.petscconf import config, build, build_py, build_ext
73
74def main():
75    setup(packages     = ['petsc4py',
76                          'petsc4py.lib',],
77          package_dir  = {'petsc4py'     : 'src',
78                          'petsc4py.lib' : 'src/lib'},
79          package_data = {'petsc4py'     : ['include/petsc4py/*.h',
80                                            'include/petsc4py/*.i',
81                                            'include/petsc4py/*.pxd',
82                                            'include/petsc4py/*.pxi',
83                                            'include/petsc4py/*.pyx',],
84                          'petsc4py.lib' : ['petsc.cfg'],},
85          ext_modules  = get_ext_modules(Extension),
86          cmdclass     = {'config'     : config,
87                          'build'      : build,
88                          'build_py'   : build_py,
89                          'build_ext'  : build_ext},
90          **metadata)
91
92if __name__ == '__main__':
93    import sys, os
94    C_SOURCE = os.path.join('src', 'petsc4py_PETSc.c')
95    def cython_help():
96        if os.path.exists(C_SOURCE): return
97        warn = lambda msg='': sys.stderr.write(msg+'\n')
98        warn("*"*70)
99        warn()
100        warn("You need to generate C source files with Cython !!!")
101        warn("Please execute in your shell:")
102        warn()
103        warn("$ python ./conf/cythonize.py")
104        warn()
105        warn("*"*70)
106        warn()
107    ## from distutils import log
108    ## log.set_verbosity(log.DEBUG)
109    cython_help()
110    main()
111
112# --------------------------------------------------------------------
113