*.pyx: Replace __new__ with __cinit__ like the program says.
[mLib-python] / setup.py
CommitLineData
20bce5e9 1from distutils.core import setup, Extension
2from Pyrex.Distutils import build_ext
3from os import *
4from errno import *
244ede18 5import re
20bce5e9 6import sys
7from sys import stdin, stdout, stderr
8
9incdirs = []
10libdirs = []
11libs = []
12
13def progoutput(cmd):
14 p = popen(cmd)
15 out = p.readline()
16 if p.read() != '': raise 'extra junk from %s' % cmd
17 p.close()
18 return out.rstrip('\n')
19
20def libconfig(lib, ver):
e59e053a 21 for i in progoutput('pkg-config --cflags "%s >= %s"' % (lib, ver)).split():
20bce5e9 22 if i[:2] == '-I': incdirs.append(i[2:])
23 else: raise 'strange cflags item %s' % i
e59e053a 24 for i in progoutput('pkg-config --libs "%s >= %s"' % (lib, ver)).split():
20bce5e9 25 if i[:2] == '-L': libdirs.append(i[2:])
26 elif i[:2] == '-l': libs.append(i[2:])
27 else: raise 'strange libs item %s' % i
28
29def uniquify(l):
30 u = {}
31 o = []
32 for i in l:
33 if i not in u:
34 o.append(i)
35 u[i] = 1
36 return o
37
38libconfig('catacomb', '2.1.0')
ea2fc600 39libconfig('mLib', '2.1.0')
20bce5e9 40
41def needs_update_p(target, sources):
42 if not path.exists(target): return True
43 t_target = stat(target).st_mtime
44 for s in sources:
45 if stat(s).st_mtime > t_target: return True
46 return False
47
244ede18 48rx_subst = re.compile(r'\%(\w+)\%')
20bce5e9 49
579d0169 50def derive(target, src, subs):
51 if needs_update_p(target, [src]):
52 out = file(target + '.new', 'w')
53 for line in file(src):
d8d81d1b 54 out.write(rx_subst.sub((lambda m: subs[m.group(1)]), line))
20bce5e9 55 out.close()
579d0169 56 rename(target + '.new', target)
57
58derive('base64.pyx', 'codec.pyx.in',
59 {'CLASS': 'Base64', 'PREFIX': 'base64'})
60derive('base32.pyx', 'codec.pyx.in',
61 {'CLASS': 'Base32', 'PREFIX': 'base32'})
62derive('hex.pyx', 'codec.pyx.in',
63 {'CLASS': 'Hex', 'PREFIX': 'hex'})
20bce5e9 64
65def mlibext(src):
66 col = src.find('!')
67 if col >= 0:
68 mod = src[:col]
69 srcs = [getsource(s) for s in src[col + 1:].split(',')]
70 else:
71 src = getsource(src)
72 mod, hunoz = src.split('.', 1)
73 srcs = [src]
579d0169 74
75mlib = Extension('mLib', ['mLib.pyx', 'atom-base.c', 'array.c'],
d8d81d1b
MW
76
77 ##extra_compile_args = ['-O0'],
78 include_dirs = uniquify(incdirs),
79 library_dirs = uniquify(libdirs),
80 libraries = uniquify(libs))
20bce5e9 81
82setup(name = 'mLib-python',
83 version = '1.0.0',
84 description = 'Python interface to mLib utilities library',
85 author = 'Straylight/Edgeware',
86 author_email = 'mdw@distorted.org.uk',
87 license = 'GNU General Public License',
579d0169 88 ext_modules = [mlib],
20bce5e9 89 cmdclass = {'build_ext': build_ext})