From ad5203c3dd81feadb90a11c8e694908838565256 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 5 Mar 2013 11:46:48 -0500 Subject: [PATCH] python/: improve build --- python/{README.md => README} | 0 python/ext/aubio-types.h | 11 +++++++---- python/ext/aubiomodule.c | 8 +++++--- python/ext/ufuncs.c | 6 ++++-- python/gen_pyobject.py | 2 +- python/generator.py | 20 ++++++++++---------- python/setup.py | 25 ++++++++++++++++++++----- tests/demo/localaubio.py | 13 ------------- 8 files changed, 47 insertions(+), 38 deletions(-) rename python/{README.md => README} (100%) delete mode 100644 tests/demo/localaubio.py diff --git a/python/README.md b/python/README similarity index 100% rename from python/README.md rename to python/README diff --git a/python/ext/aubio-types.h b/python/ext/aubio-types.h index b2747a60..0cdac2c4 100644 --- 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 +#ifndef PY_AUBIO_MODULE_UFUNC #define NO_IMPORT_UFUNC +#else +#include #endif // import aubio -#include -#include -#include +//#include #define AUBIO_UNSTABLE 1 -#include +#include "aubio.h" #define Py_default_vector_length 1024 diff --git a/python/ext/aubiomodule.c b/python/ext/aubiomodule.c index 74ad7cb8..76afd1e6 100644 --- a/python/ext/aubiomodule.c +++ b/python/ext/aubiomodule.c @@ -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); diff --git a/python/ext/ufuncs.c b/python/ext/ufuncs.c index 63b11460..9eb1a83e 100644 --- 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 @@ 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; diff --git a/python/gen_pyobject.py b/python/gen_pyobject.py index 14920fbc..20f4534a 100644 --- a/python/gen_pyobject.py +++ b/python/gen_pyobject.py @@ -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 { diff --git a/python/generator.py b/python/generator.py index 6e904a1e..ead37cf7 100755 --- a/python/generator.py +++ b/python/generator.py @@ -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') diff --git a/python/setup.py b/python/setup.py index 10415465..a4e1ccc4 100755 --- 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 @@ 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 index a0d8c20f..00000000 --- a/tests/demo/localaubio.py +++ /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 -- 2.26.2