source: inundation/pypar_dist/setup.py @ 3330

Last change on this file since 3330 was 2778, checked in by steve, 19 years ago

On our 64 bit machine, ran into problem in pmesh/mesh.py where seg[0], seg[1], triangle,
and neighbor where not seen as integers. Had to wrap them in int(..)

File size: 4.2 KB
Line 
1#!/usr/bin/env python
2
3# Examples of setup
4#
5# python setup.py install
6# python setup.py install --prefix=/opt/python-2.3
7# python setup.py install --home=~
8#
9# Some times you'll have to add a file called pypar.pth
10# containing the word pypar to site-packages
11
12
13
14from distutils.core import setup, Extension
15import distutils.sysconfig
16import os, sys
17import popen2
18import string
19import tempfile
20
21def setup_compiler():
22    distutils.sysconfig.get_config_vars()
23    config_vars = distutils.sysconfig._config_vars
24    if sys.platform == 'sunos5':
25        config_vars['LDSHARED'] = "gcc -G"
26        config_vars['CCSHARED'] = ""
27
28
29def uniq_arr(arr):
30    """Remove repeated values from an array and return new array."""
31    ret = []
32    for i in arr:
33        if i not in ret:
34            ret.append(i)
35    return ret
36
37
38def _run_command(cmd):
39    out_file, in_file, err_file = popen2.popen3(cmd)
40    output = out_file.read() + err_file.read()
41    out_file.close()
42    in_file.close()
43    err_file.close()
44    # need this hack to get the exit status
45    out_file = os.popen(cmd)
46    if out_file.close():
47        # close returns exit status of command.
48        return ""
49    else:
50        # no errors, out_file.close() returns None.
51        return output
52
53
54def _get_mpi_cmd():
55    """Returns the output of the command used to compile using
56    mpicc."""
57    # LAM
58    output = _run_command("mpicc -showme")
59    if output:
60        return output
61
62    # MPICH
63    # works with MPICH version 1.2.1 (on Debian)
64    output = _run_command("mpicc -compile_info -link_info")
65    if output:
66        return output
67
68    # old version of MPICH needs this hack.
69    tmp_base = tempfile.mktemp()
70    tmp_c = tmp_base + ".c"
71    tmp_o = tmp_base + ".o"
72    tmp_file = open(tmp_c, "w")
73    tmp_file.write('#include "mpi.h"\nint main(){return 0;}\n')
74    tmp_file.close()
75    output = _run_command("mpicc -show;"\
76                          "mpicc -echo -c %s -o %s"%(tmp_c, tmp_o))
77    os.remove(tmp_c)
78    if os.path.exists(tmp_o):
79        os.remove(tmp_o)
80    if output:
81        return output
82    else:
83        return ""
84
85
86def get_mpi_flags():
87    output = _get_mpi_cmd()
88    print output
89    if not output:
90        if sys.platform=='win32': #From Simon Frost
91            output = "gcc -L$MPICH_DIR\SDK.gcc\lib -lmpich -I$MPICH_DIR\SDK.gcc\include"
92        else:
93            output = "cc -L/usr/opt/mpi -lmpi -lelan"
94
95
96    # now get the include, library dirs and the libs to link with.
97    flags = string.split(output)
98    flags = uniq_arr(flags) # remove repeated values.
99    inc_dirs = []
100    lib_dirs = []
101    libs = []
102    def_macros = []
103    undef_macros = []
104    for f in flags:
105        if f[:2] == '-I':
106            inc_dirs.append(f[2:])
107        elif f[:2] == '-L':
108            lib_dirs.append(f[2:])
109        elif f[:2] == '-l':
110            libs.append(f[2:])
111        elif f[:2] == '-U':
112            undef_macros.append(f[2:])
113        elif f[:2] == '-D':
114            tmp = string.split(f[2:], '=')
115            if len(tmp) == 1:
116                def_macros.append((tmp[0], None))
117            else:
118                def_macros.append(tuple(tmp))
119    return {'inc_dirs': inc_dirs, 'lib_dirs': lib_dirs, 'libs':libs,
120            'def_macros': def_macros, 'undef_macros': undef_macros}
121
122
123if __name__ == "__main__":
124    setup_compiler()
125
126    mpi_flags = get_mpi_flags()
127
128    setup(name="Pypar",
129          version="1.5",
130          description="Pypar - Parallel Python",
131          long_description="Pypar - Parallel Python, no-frills MPI interface",
132          author="Ole Nielsen",
133          author_email="Ole.Nielsen@anu.edu.au",
134          url="http://datamining.anu.edu.au/pypar",
135          package_dir = {'': 'lib'},
136          packages  = ['pypar'],
137          ext_modules = [Extension('pypar.mpiext',
138                                   ['mpiext.c'],
139                                   include_dirs=mpi_flags['inc_dirs'],
140                                   library_dirs=mpi_flags['lib_dirs'],
141                                   libraries=mpi_flags['libs'],
142                                   define_macros=mpi_flags['def_macros'],
143                                   undef_macros=mpi_flags['undef_macros'])]
144          )
Note: See TracBrowser for help on using the repository browser.