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