python/: improve build
authorPaul Brossier <piem@piem.org>
Tue, 5 Mar 2013 16:46:48 +0000 (11:46 -0500)
committerPaul Brossier <piem@piem.org>
Tue, 5 Mar 2013 16:46:48 +0000 (11:46 -0500)
python/README [new file with mode: 0644]
python/README.md [deleted file]
python/ext/aubio-types.h
python/ext/aubiomodule.c
python/ext/ufuncs.c
python/gen_pyobject.py
python/generator.py
python/setup.py
tests/demo/localaubio.py [deleted file]

diff --git a/python/README b/python/README
new file mode 100644 (file)
index 0000000..4103c8b
--- /dev/null
@@ -0,0 +1,24 @@
+Python aubio module
+===================
+
+This module wraps the aubio library for python using the numpy module.
+
+See the [Python/C API Reference
+Manual] (http://docs.python.org/c-api/index.html) and the [Numpy/C API
+Reference](http://docs.scipy.org/doc/numpy/reference/c-api.html)
+
+Compiling python aubio
+----------------------
+
+You should be able to build the aubio python module out of the box:
+
+    $ ./build_osx
+
+This should work on linux based systems as well as recent versions of OS X
+(10.8.x). Let me know if you have issues on your platforms.
+
+Additional tools
+----------------
+
+To use some of the demo scripts, you will need
+[matplotlib](http://matplotlib.org/).
diff --git a/python/README.md b/python/README.md
deleted file mode 100644 (file)
index 4103c8b..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-Python aubio module
-===================
-
-This module wraps the aubio library for python using the numpy module.
-
-See the [Python/C API Reference
-Manual] (http://docs.python.org/c-api/index.html) and the [Numpy/C API
-Reference](http://docs.scipy.org/doc/numpy/reference/c-api.html)
-
-Compiling python aubio
-----------------------
-
-You should be able to build the aubio python module out of the box:
-
-    $ ./build_osx
-
-This should work on linux based systems as well as recent versions of OS X
-(10.8.x). Let me know if you have issues on your platforms.
-
-Additional tools
-----------------
-
-To use some of the demo scripts, you will need
-[matplotlib](http://matplotlib.org/).
index b2747a6..0cdac2c 100644 (file)
 // only import array and ufunc from main module
 #ifndef PY_AUBIO_MODULE_MAIN
 #define NO_IMPORT_ARRAY
+#endif
+#include <numpy/arrayobject.h>
+#ifndef PY_AUBIO_MODULE_UFUNC
 #define NO_IMPORT_UFUNC
+#else
+#include <numpy/ufuncobject.h>
 #endif
 
 // import aubio
-#include <numpy/ndarraytypes.h>
-#include <numpy/ufuncobject.h>
-#include <numpy/npy_3kcompat.h>
+//#include <numpy/npy_3kcompat.h>
 
 #define AUBIO_UNSTABLE 1
-#include <aubio.h>
+#include "aubio.h"
 
 #define Py_default_vector_length 1024
 
index 74ad7cb..76afd1e 100644 (file)
@@ -1,6 +1,9 @@
 #define PY_AUBIO_MODULE_MAIN
 #include "aubio-types.h"
-#include "generated/aubio-generated.h"
+#include "aubio-generated.h"
+
+extern void add_generated_objects ( PyObject *m );
+extern void add_ufuncs ( PyObject *m );
 
 static char Py_alpha_norm_doc[] = "compute alpha normalisation factor";
 
@@ -261,10 +264,9 @@ init_aubio (void)
   }
 
   err = _import_array ();
-
   if (err != 0) {
     fprintf (stderr,
-        "Unable to import Numpy C API from aubio module (error %d)\n", err);
+        "Unable to import Numpy array from aubio module (error %d)\n", err);
   }
 
   Py_INCREF (&Py_cvecType);
index 63b1146..9eb1a83 100644 (file)
@@ -1,3 +1,4 @@
+#define PY_AUBIO_MODULE_UFUNC
 #include "aubio-types.h"
 
 static void unwrap2pi(char **args, npy_intp *dimensions,
@@ -60,11 +61,12 @@ static char unwrap2pi_types[] = {
 
 void add_ufuncs ( PyObject *m )
 {
-  int err = _import_umath();
+  int err = 0;
 
+  err = _import_umath ();
   if (err != 0) {
     fprintf (stderr,
-            "Unable to import Numpy C API Ufunc from aubio module (error %d)\n", err);
+        "Unable to import Numpy umath from aubio module (error %d)\n", err);
   }
 
   PyObject *f, *dict;
index 14920fb..20f4534 100644 (file)
@@ -172,7 +172,7 @@ def gen_new_init(newfunc, name):
 // WARNING: this file is generated, DO NOT EDIT
 
 // WARNING: if you haven't read the first line yet, please do so
-#include "ext/aubiowraphell.h"
+#include "aubiowraphell.h"
 
 typedef struct
 {
index 6e904a1..ead37cf 100755 (executable)
@@ -27,9 +27,9 @@ def get_cpp_objects():
 
   return cpp_output, cpp_objects
 
-def generate_object_files():
-  if os.path.isdir('generated'): shutil.rmtree('generated')
-  os.mkdir('generated')
+def generate_object_files(output_path):
+  if os.path.isdir(output_path): shutil.rmtree(output_path)
+  os.mkdir(output_path)
 
   generated_objects = []
   cpp_output, cpp_objects = get_cpp_objects()
@@ -48,7 +48,7 @@ def generate_object_files():
 
   for this_object in cpp_objects:
       lint = 0
-   
+
       if this_object[-2:] == '_t':
           object_name = this_object[:-2]
       else:
@@ -126,11 +126,11 @@ def generate_object_files():
               continue
       if 1: #try:
           s = gen_new_init(new_methods[0], short_name)
-          s += gen_do(do_methods[0], short_name) 
+          s += gen_do(do_methods[0], short_name)
           s += gen_members(new_methods[0], short_name)
           s += gen_methods(get_methods, set_methods, short_name)
           s += gen_finish(short_name)
-          generated_filepath = 'generated/gen-'+short_name+'.c'
+          generated_filepath = os.path.join(output_path,'gen-'+short_name+'.c')
           fd = open(generated_filepath, 'w')
           fd.write(s)
       #except Exception, e:
@@ -174,14 +174,14 @@ def generate_object_files():
   s += """
   }"""
 
-  fd = open('generated/aubio-generated.h', 'w')
+  fd = open(os.path.join(output_path,'aubio-generated.h'), 'w')
   fd.write(s)
 
   from os import listdir
-  generated_files = listdir('generated')
+  generated_files = listdir(output_path)
   generated_files = filter(lambda x: x.endswith('.c'), generated_files)
-  generated_files = ['generated/'+f for f in generated_files]
+  generated_files = [output_path+'/'+f for f in generated_files]
   return generated_files
 
 if __name__ == '__main__':
-  generate_object_files(
+  generate_object_files('gen')
index 1041546..a4e1ccc 100755 (executable)
@@ -1,22 +1,37 @@
 #! /usr/bin/python
 
 from distutils.core import setup, Extension
-from generator import generate_object_files
 import sys
 import os.path
 import numpy
 
 # read from VERSION
-for l in open(os.path.join('..','VERSION')).readlines(): exec (l.strip())
+for l in open('VERSION').readlines(): exec (l.strip())
 __version__ = '.'.join \
         ([str(x) for x in [AUBIO_MAJOR_VERSION, AUBIO_MINOR_VERSION, AUBIO_PATCH_VERSION]]) \
         + AUBIO_VERSION_STATUS
 
-library_dirs = ['../build/src', '../src/.libs']
-include_dirs = ['../build/src', '../src', '.' ]
+library_dirs = ['../build/src']
+include_dirs = ['../src'] # aubio.h
+include_dirs += ['../build/src'] # config.h
+include_dirs += ['ext']
+include_dirs += ['gen']
+#include_dirs += ['../build/src', '../src', '.' ]
+
 library_dirs = filter (lambda x: os.path.isdir(x), library_dirs)
 include_dirs = filter (lambda x: os.path.isdir(x), include_dirs)
 
+generated_object_files = []
+
+output_path = 'gen'
+
+if not os.path.isdir(output_path):
+    from generator import generate_object_files
+    generated_object_files = generate_object_files(output_path)
+else:
+    import glob
+    generated_object_files = glob.glob(os.path.join(output_path, '*.c'))
+
 aubio_extension = Extension("aubio._aubio", [
             "ext/aubiomodule.c",
             "ext/aubioproxy.c",
@@ -29,7 +44,7 @@ aubio_extension = Extension("aubio._aubio", [
             "ext/py-fft.c",
             "ext/py-phasevoc.c",
             # generated files
-            ] + generate_object_files(),
+            ] + generated_object_files,
         include_dirs = include_dirs + [ numpy.get_include() ],
         library_dirs = library_dirs,
         libraries=['aubio'])
diff --git a/tests/demo/localaubio.py b/tests/demo/localaubio.py
deleted file mode 100644 (file)
index a0d8c20..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-
-try:
-  from aubio.aubiowrapper import * 
-except ImportError:
-  try: 
-    import os
-    import sys
-    cur_dir = os.path.dirname(sys.argv[0])
-    sys.path.append(os.path.join(cur_dir,'..','..','python'))
-    sys.path.append(os.path.join(cur_dir,'..','..','python','aubio','.libs'))
-    from aubio.aubiowrapper import * 
-  except ImportError:
-    raise