~ubuntu-branches/ubuntu/wily/python-fftw/wily

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Package Import Robot
  • Author(s): Jerome Kieffer
  • Date: 2011-12-11 14:44:24 UTC
  • Revision ID: package-import@ubuntu.com-20111211144424-n2fel2ww3dlajmuf
Tags: upstream-0.2.2
ImportĀ upstreamĀ versionĀ 0.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
"""PyFFTW: Python bindings to the FFTW3 C-library
 
4
 
 
5
PyFFTW provieds Python bindings to the FFTW3  "Fastest Fourier Transform in 
 
6
the West." C-library(http://www.fftw.org/) for computing discrete Fourier 
 
7
transforms. It uses numpy and ctypes and includes a somewhat pythonic interface
 
8
to the FFTW routines, but leaves the concept of creating plans and executing 
 
9
these plans intact.
 
10
"""
 
11
 
 
12
classifiers = """\
 
13
Development Status :: 4 - Beta
 
14
Intended Audience :: Science/Research
 
15
Intended Audience :: Developers
 
16
License :: OSI Approved :: GNU General Public License (GPL)
 
17
Operating System :: OS Independent
 
18
Programming Language :: Python
 
19
Topic :: Scientific/Engineering
 
20
"""
 
21
 
 
22
 
 
23
 
 
24
from distutils.core import setup
 
25
from distutils.log import warn
 
26
from distutils.command.build_py import build_py
 
27
import ctypes
 
28
from ctypes import util
 
29
import os
 
30
import platform
 
31
import sys
 
32
 
 
33
package_data = {}
 
34
if os.name=='nt' or platform.system()=='Windows':
 
35
    # Assuming that the dll content of 
 
36
    #  ftp://ftp.fftw.org/pub/fftw/fftw-3.2.2.pl1-dll32.zip
 
37
    # is copied to the current working directory.
 
38
    # FFTW_PATH should be either the final installation directory
 
39
    # of the dll files or empty.
 
40
    try:
 
41
        FFTW_PATH = os.environ['FFTW_PATH']
 
42
    except KeyError:
 
43
        FFTW_PATH = r''
 
44
    packages_library_names = {'fftw3': 'libfftw3-3.dll',
 
45
                              'fftw3f' : 'libfftw3f-3.dll',
 
46
                              'fftw3l': 'libfftw3l-3.dll'}
 
47
    for l, dll in packages_library_names.items():
 
48
        s = os.path.join (FFTW_PATH, dll)
 
49
        package_data[l] = [s]
 
50
elif platform.system()=='Darwin':
 
51
    try:
 
52
        FFTW_PATH = os.environ['FFTW_PATH']
 
53
    except KeyError:
 
54
        FFTW_PATH=r'/sw/lib'
 
55
    packages_library_names = {'fftw3': 'libfftw3.dylib', 'fftw3f' : 'libfftw3f.dylib',
 
56
                              'fftw3l': 'libfftw3l.dylib'}
 
57
else:
 
58
    try:
 
59
        FFTW_PATH = os.environ['FFTW_PATH']
 
60
    except KeyError:
 
61
        FFTW_PATH = r'/usr/lib/'
 
62
    packages_library_names = {'fftw3': 'libfftw3.so', 'fftw3f' : 'libfftw3f.so',
 
63
                              'fftw3l': 'libfftw3l.so'}
 
64
 
 
65
_complex_typedict = {'fftw3':'complex', 'fftw3f': 'singlecomplex', 'fftw3l': 'longcomplex'}
 
66
_float_typedict = {'fftw3': 'double', 'fftw3f': 'single', 'fftw3l': 'longdouble'}
 
67
packages_0 = ['fftw3','fftw3f', 'fftw3l']
 
68
# To used threads, p+'_threads' library must exist in the system where p in packages_0.
 
69
 
 
70
def create_source_from_template(tmplfile, outfile, lib, libname, _complex,
 
71
                                _float, location):
 
72
    fp = open(tmplfile, 'r')
 
73
    tmpl = fp.read()
 
74
    fp.close()
 
75
    mod = tmpl.replace('$libname$',libname).replace('$complex$',_complex).\
 
76
            replace('$library$',packages_library_names[lib]).replace('$float$',_float).\
 
77
            replace('$libraryfullpath$', location)
 
78
    fp = open(outfile, 'w')
 
79
    fp.write(mod)
 
80
    fp.close()
 
81
    print "build %s from template %s" %(outfile, tmplfile)
 
82
 
 
83
def check_libs(packages):
 
84
    libs = {}
 
85
    for name in packages[:]:
 
86
        try:
 
87
            libpath = os.path.join(FFTW_PATH, packages_library_names[name])
 
88
            if libpath == None:
 
89
                raise OSError
 
90
            lib = ctypes.cdll.LoadLibrary(libpath)
 
91
            print "found %s at %s" %(name, libpath)
 
92
        except OSError, e:
 
93
            warn("%s is not located at %s, trying util.find_library(%s)"
 
94
                 %(name, libpath, name))
 
95
            try:
 
96
                libpath = util.find_library(name)
 
97
                if libpath == None:
 
98
                    raise OSError
 
99
                lib = ctypes.cdll.LoadLibrary(libpath)
 
100
                print "found %s at %s" %(name, libpath)
 
101
            except (TypeError,OSError), e:
 
102
                warn("Not installing bindings for %s, because could not load\
 
103
                     the library: %s\n if you know the library is installed\
 
104
                     you can specify the absolute path in setup.py" % (name, e))
 
105
                packages.remove(name)
 
106
        libs[name] = libpath
 
107
    return packages, libs
 
108
 
 
109
packages, liblocation = check_libs(packages_0)
 
110
if len(packages) < 1:
 
111
    packages = ['None']
 
112
 
 
113
class build_from_templates(build_py):
 
114
    def build_module(self, module, module_file, package):
 
115
        if package == 'None':
 
116
            raise ValueError('no FFTW files found')
 
117
        module, ext = os.path.splitext(module)
 
118
        if not ext == '.tmpl':
 
119
            outfile = self.get_module_outfile(self.build_lib, [package], module)
 
120
            dir = os.path.dirname(outfile)
 
121
            self.mkpath(dir)
 
122
            return self.copy_file(module_file, outfile, preserve_mode=0)
 
123
        else:
 
124
            outfile = self.get_module_outfile(self.build_lib, [package], module)
 
125
            dir = os.path.dirname(outfile)
 
126
            self.mkpath(dir)
 
127
            return create_source_from_template(module_file, outfile, package,
 
128
                                               package.replace('3',''),
 
129
                                               _complex_typedict[package],
 
130
                                               _float_typedict[package],
 
131
                                               liblocation[package])
 
132
 
 
133
doclines = __doc__.split("\n")
 
134
 
 
135
setup(name='PyFFTW3',
 
136
      version = '0.2.2',
 
137
      platforms = ["any"],
 
138
      description = doclines[0],
 
139
      classifiers = filter(None, classifiers.split("\n")),
 
140
      long_description = "\n".join(doclines[2:]),
 
141
      author = 'Jochen Schroeder',
 
142
      author_email = 'cycomanic@gmail.com',
 
143
      url = 'www.launchpad.net/pyfftw',
 
144
      packages = packages,
 
145
      package_dir = dict([(n, 'src/templates') for n in packages]),
 
146
      package_data = {},
 
147
      cmdclass = {"build_py": build_from_templates},
 
148
      license ='GPL v3'
 
149
     )