@@@ cython and python3
[mLib-python] / setup.py
index 66aafc5..1ec65dc 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -1,28 +1,46 @@
 #! /usr/bin/python
 
+import os as OS
+import sys as SYS
 import distutils.core as DC
-import Pyrex.Distutils as PXD
+import Cython.Build as CB
 import mdwsetup as MS
 
-MS.pkg_config('mLib', '2.1.0')
+MS.pkg_config('mLib', '2.4.99~')
 
-mLib = DC.Extension('mLib', ['mLib.pyx', 'atom-base.c', 'array.c'],
+PYVERSION = SYS.version_info[0:3]
+pyxc = 'mLib-py%d.%d.%d.c' % PYVERSION
+mLib = DC.Extension('mLib', [pyxc,
+                             'atom-base.c',
+                             ##'array.c'
+                            ],
                     ##extra_compile_args = ['-O0'],
                     include_dirs = MS.uniquify(MS.INCLUDEDIRS),
                     library_dirs = MS.uniquify(MS.LIBDIRS),
                     libraries = MS.uniquify(MS.LIBS))
 
+## The `cythonize' function generates the C sources immediately, so we have
+## to generate its inputs even earlier.
+genfiles = [
+#            MS.Derive('base64.pyx', 'codec.pyx.in',
+#                      {'CLASS': 'Base64', 'PREFIX': 'base64'}),
+#            MS.Derive('base32.pyx', 'codec.pyx.in',
+#                      {'CLASS': 'Base32', 'PREFIX': 'base32'}),
+#            MS.Derive('hex.pyx', 'codec.pyx.in',
+#                      {'CLASS': 'Hex', 'PREFIX': 'hex'})
+]
+for g in genfiles: g.gen()
+
+## Generate the main C code.
+if OS.path.exists(pyxc): OS.rename(pyxc, "mLib.c")
+CB.cythonize("mLib.pyx", compile_time_env = dict(PYVERSION = PYVERSION))
+OS.rename("mLib.c", pyxc)
+
 MS.setup(name = 'mLib-python',
          description = 'Python interface to mLib utilities library',
          author = 'Straylight/Edgeware',
          author_email = 'mdw@distorted.org.uk',
          license = 'GNU General Public License',
          ext_modules = [mLib],
-         genfiles = [MS.Derive('base64.pyx', 'codec.pyx.in',
-                               {'CLASS': 'Base64', 'PREFIX': 'base64'}),
-                     MS.Derive('base32.pyx', 'codec.pyx.in',
-                               {'CLASS': 'Base32', 'PREFIX': 'base32'}),
-                     MS.Derive('hex.pyx', 'codec.pyx.in',
-                               {'CLASS': 'Hex', 'PREFIX': 'hex'})],
-         cleanfiles = ['mLib.c'],
-         cmdclass = { 'build_ext': PXD.build_ext })
+         genfiles = genfiles,
+         cleanfiles = [pyxc])