ref: ad5203c3dd81feadb90a11c8e694908838565256
parent: 208336b59c75969bf945e0c2dc048daefba0f5b1
author: Paul Brossier <piem@piem.org>
date: Tue Mar 5 06:46:48 EST 2013
python/: improve build
--- /dev/null
+++ b/python/README
@@ -1,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/).
--- a/python/README.md
+++ /dev/null
@@ -1,24 +1,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/).
--- a/python/ext/aubio-types.h
+++ b/python/ext/aubio-types.h
@@ -10,16 +10,19 @@
// 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
--- a/python/ext/aubiomodule.c
+++ b/python/ext/aubiomodule.c
@@ -1,7 +1,10 @@
#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";
static PyObject *
@@ -261,10 +264,9 @@
}
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);
--- a/python/ext/ufuncs.c
+++ b/python/ext/ufuncs.c
@@ -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 @@
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;
--- a/python/gen_pyobject.py
+++ b/python/gen_pyobject.py
@@ -172,7 +172,7 @@
// 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
{
--- a/python/generator.py
+++ b/python/generator.py
@@ -27,9 +27,9 @@
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 @@
for this_object in cpp_objects:
lint = 0
-
+
if this_object[-2:] == '_t':
object_name = this_object[:-2]
else:
@@ -126,11 +126,11 @@
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 @@
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')
--- a/python/setup.py
+++ b/python/setup.py
@@ -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 @@
"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'])
--- a/tests/demo/localaubio.py
+++ /dev/null
@@ -1,13 +1,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