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 [moved from python/README.md with 100% similarity]
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]

similarity index 100%
rename from python/README.md
rename to python/README
index b2747a607ce75650416da45c8b680897d743068a..0cdac2c453117389b474aee7f33208cf02d90753 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 74ad7cb864d5274825520e6aaaa418531debe1e9..76afd1e6655d1ab3c21db31f0fa312478bf9e6a5 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 63b11460016518241d5ce7457654621a188e2fb3..9eb1a83e6f91497b6d4431341e44c6f08a6e8b58 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 14920fbca808b56a28f92379fe480bb7fba35db3..20f4534a14c1d79ae4b6b946df74c5c28d7f232e 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 6e904a1e874af5ac5ecef35c594dc53cd002d1e3..ead37cf70bc19bdae0b957232c5f008eead06e57 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 104154658aa7535391e108da383420d10d443078..a4e1ccc407cf6fd3a2cf996b35854e906768352c 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