File: cy2py

package info (click to toggle)
mpi4py 1.3%2Bhg20120611-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,020 kB
  • sloc: python: 9,503; ansic: 6,296; makefile: 571; f90: 158; sh: 146; cpp: 103
file content (75 lines) | stat: -rwxr-xr-x 2,175 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python

# --------

import sys, os, tempfile
from distutils.core import setup
from distutils.dir_util import remove_tree
from Cython.Distutils.extension import Extension
from Cython.Distutils import build_ext

INCLUDES = []
try:
    from numpy import get_include as npy_get_include
    INCLUDES += [npy_get_include()]
except ImportError:
    pass
try:
    from mpi4py import get_include as mpi_get_include
    INCLUDES += [mpi_get_include()]
except ImportError:
    pass

def main(cy_source, c_sources, lang='c', verb=False):
    name, ext = os.path.splitext(cy_source)
    tmpdir = tempfile.mkdtemp()
    try:
        setup(script_args = [['--quiet', '--verbose',][verb],
                             'build',     '--build-base', tmpdir,
                             'build_ext', '--inplace', #'--force',
                             ],
              ext_modules = [Extension(name,
                                       sources=[cy_source]+list(c_sources),
                                       depends=[],
                                       include_dirs=INCLUDES,
                                       language=lang)
                             ],
              cmdclass    = {'build_ext' : build_ext},
            )
    finally:
        remove_tree(tmpdir)

# --------

if __name__ == '__main__':
    args = list(sys.argv[1:])
    verbose  = 0
    if args[0] in ('-v',):
        verbose=1; del args[0]
    language = 'c'
    if args[0] in ('-c++', '-cxx', '-cplus'):
        language= 'c++'; del args[0]
    #
    from distutils.sysconfig import get_config_vars
    config = get_config_vars()
    if language == 'c':
        config['CC'] =  LD = os.environ.get('MPICC', 'mpicc')
    elif language == 'c++':
        config['CXX'] = LD = os.environ.get('MPICXX', 'mpicxx')
    LD = os.environ.get('MPILD', LD)
    try:
        LDSHARED = config['LDSHARED'].split()
        LDSHARED = LD.split() + LDSHARED[1:]
        config['LDSHARED'] = ' '.join(LDSHARED)
    except KeyError:
        pass
    #
    cy_source = args[0]
    c_sources = args[1:]
    main(cy_source, c_sources, language, verbose)

# --------

# Local Variables:
# mode: python
# End: