3
"""PyFFTW: Python bindings to the FFTW3 C-library
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
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
24
from distutils.core import setup
25
from distutils.log import warn
26
from distutils.command.build_py import build_py
28
from ctypes import util
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.
41
FFTW_PATH = os.environ['FFTW_PATH']
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)
50
elif platform.system()=='Darwin':
52
FFTW_PATH = os.environ['FFTW_PATH']
55
packages_library_names = {'fftw3': 'libfftw3.dylib', 'fftw3f' : 'libfftw3f.dylib',
56
'fftw3l': 'libfftw3l.dylib'}
59
FFTW_PATH = os.environ['FFTW_PATH']
61
FFTW_PATH = r'/usr/lib/'
62
packages_library_names = {'fftw3': 'libfftw3.so', 'fftw3f' : 'libfftw3f.so',
63
'fftw3l': 'libfftw3l.so'}
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.
70
def create_source_from_template(tmplfile, outfile, lib, libname, _complex,
72
fp = open(tmplfile, 'r')
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')
81
print "build %s from template %s" %(outfile, tmplfile)
83
def check_libs(packages):
85
for name in packages[:]:
87
libpath = os.path.join(FFTW_PATH, packages_library_names[name])
90
lib = ctypes.cdll.LoadLibrary(libpath)
91
print "found %s at %s" %(name, libpath)
93
warn("%s is not located at %s, trying util.find_library(%s)"
94
%(name, libpath, name))
96
libpath = util.find_library(name)
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)
107
return packages, libs
109
packages, liblocation = check_libs(packages_0)
110
if len(packages) < 1:
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)
122
return self.copy_file(module_file, outfile, preserve_mode=0)
124
outfile = self.get_module_outfile(self.build_lib, [package], module)
125
dir = os.path.dirname(outfile)
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])
133
doclines = __doc__.split("\n")
135
setup(name='PyFFTW3',
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',
145
package_dir = dict([(n, 'src/templates') for n in packages]),
147
cmdclass = {"build_py": build_from_templates},