Index: Makefile
===================================================================
--- Makefile	(revision c09efcaa6cbfc971096cd8ef40bf2726f42d3638)
+++ Makefile	(revision 1167631cbafc6fa1cbc277c7f9c195d47b08b72d)
@@ -29,25 +29,30 @@
 
 build_python:
-	cd python && python ./setup.py generate $(ENABLE_DOUBLE) build
+	python ./setup.py generate $(ENABLE_DOUBLE) build
 
+test_python: export LD_LIBRARY_PATH=$(PWD)/build/src
 test_python:
-	cd python && pip install -v .
-	cd python && LD_LIBRARY_PATH=$(PWD)/build/src nose2 --verbose
-	cd python && pip uninstall -y -v aubio
+	pip install -v -r requirements.txt
+	pip install -v .
+	nose2 --verbose
+	pip uninstall -y -v aubio
 
 test_python_osx:
-	cd python && pip install --user -v .
+	# create links from ~/lib/lib* to build/src/lib*
 	[ -f build/src/libaubio.[0-9].dylib ] && ( mkdir -p ~/lib && cp -prv build/src/libaubio.4.dylib ~/lib ) || true
-	cd python && nose2 --verbose
-	cd python && pip uninstall -y -v aubio
+	# then run the tests
+	pip install --user -v -r requirements.txt
+	pip install --user -v .
+	nose2 --verbose
+	pip uninstall -y -v aubio
 
 clean_python:
-	cd python && ./setup.py clean
+	./setup.py clean
 
 build_python3:
-	cd python && python3 ./setup.py generate $(ENABLE_DOUBLE) build
+	python3 ./setup.py generate $(ENABLE_DOUBLE) build
 
 clean_python3:
-	cd python && python3 ./setup.py clean
+	python3 ./setup.py clean
 
 clean:
Index: nose2.cfg
===================================================================
--- nose2.cfg	(revision 1167631cbafc6fa1cbc277c7f9c195d47b08b72d)
+++ nose2.cfg	(revision 1167631cbafc6fa1cbc277c7f9c195d47b08b72d)
@@ -0,0 +1,6 @@
+[unittest]
+start-dir = python/tests/
+plugins = nose2.plugins.mp
+
+[multiprocess]
+always-on = true
Index: python/lib/gen_external.py
===================================================================
--- python/lib/gen_external.py	(revision c09efcaa6cbfc971096cd8ef40bf2726f42d3638)
+++ python/lib/gen_external.py	(revision 1167631cbafc6fa1cbc277c7f9c195d47b08b72d)
@@ -1,5 +1,8 @@
 import os, glob
 
-header = """// this file is generated! do not modify
+header = 'src/aubio.h'
+output_path = 'python/gen'
+
+source_header = """// this file is generated! do not modify
 #include "aubio-types.h"
 """
@@ -42,7 +45,7 @@
 
 
-def get_cpp_objects():
+def get_cpp_objects(header=header):
 
-    cpp_output = [l.strip() for l in os.popen('cpp -DAUBIO_UNSTABLE=1 -I../build/src ../src/aubio.h').readlines()]
+    cpp_output = [l.strip() for l in os.popen('cpp -DAUBIO_UNSTABLE=1 {:s}'.format(header)).readlines()]
     #cpp_output = [l.strip() for l in os.popen('cpp -DAUBIO_UNSTABLE=0 -I../build/src ../src/onset/onset.h').readlines()]
     #cpp_output = [l.strip() for l in os.popen('cpp -DAUBIO_UNSTABLE=0 -I../build/src ../src/pitch/pitch.h').readlines()]
@@ -67,9 +70,9 @@
     return cpp_output, cpp_objects
 
-def generate_external(output_path, usedouble = False, overwrite = True):
+def generate_external(header=header, output_path=output_path, usedouble=False, overwrite=True):
     if not os.path.isdir(output_path): os.mkdir(output_path)
     elif overwrite == False: return glob.glob(os.path.join(output_path, '*.c'))
     sources_list = []
-    cpp_output, cpp_objects = get_cpp_objects()
+    cpp_output, cpp_objects = get_cpp_objects(header)
     lib = {}
 
@@ -122,7 +125,10 @@
     """
 
-    from .gen_code import MappedObject
+    try:
+        from .gen_code import MappedObject
+    except (SystemError, ValueError) as e:
+        from gen_code import MappedObject
     for o in lib:
-        out = header
+        out = source_header
         mapped = MappedObject(lib[o], usedouble = usedouble)
         out += mapped.gen_code()
@@ -133,5 +139,5 @@
             sources_list.append(output_file)
 
-    out = header
+    out = source_header
     out += "#include \"aubio-generated.h\""
     check_types = "\n     ||  ".join(["PyType_Ready(&Py_%sType) < 0" % o for o in lib])
@@ -187,4 +193,6 @@
 
 if __name__ == '__main__':
-    output_path = 'gen'
-    generate_external(output_path)
+    import sys
+    if len(sys.argv) > 1: header = sys.argv[1]
+    if len(sys.argv) > 2: output_path = sys.argv[2]
+    generate_external(header, output_path)
Index: python/lib/moresetuptools.py
===================================================================
--- python/lib/moresetuptools.py	(revision c09efcaa6cbfc971096cd8ef40bf2726f42d3638)
+++ python/lib/moresetuptools.py	(revision 1167631cbafc6fa1cbc277c7f9c195d47b08b72d)
@@ -1,7 +1,8 @@
 import distutils, distutils.command.clean, distutils.dir_util
+from .gen_external import generate_external, header, output_path
 
 class CleanGenerated(distutils.command.clean.clean):
     def run(self):
-        distutils.dir_util.remove_tree('gen')
+        distutils.dir_util.remove_tree(output_path)
         distutils.command.clean.clean.run(self)
 
@@ -24,4 +25,3 @@
     def run(self):
         self.announce( 'Generating code', level=distutils.log.INFO)
-        from .gen_external import generate_external
-        generated_object_files = generate_external('gen', usedouble = self.enable_double)
+        generated_object_files = generate_external(header, output_path, usedouble = self.enable_double)
Index: thon/nose2.cfg
===================================================================
--- python/nose2.cfg	(revision c09efcaa6cbfc971096cd8ef40bf2726f42d3638)
+++ 	(revision )
@@ -1,6 +1,0 @@
-[unittest]
-start-dir = tests/
-plugins = nose2.plugins.mp
-
-[multiprocess]
-always-on = true
Index: thon/setup.py
===================================================================
--- python/setup.py	(revision c09efcaa6cbfc971096cd8ef40bf2726f42d3638)
+++ 	(revision )
@@ -1,95 +1,0 @@
-#! /usr/bin/env python
-
-from setuptools import setup, Extension
-from lib.moresetuptools import CleanGenerated, GenerateCommand
-
-import sys
-import os.path
-import numpy
-
-# read from VERSION
-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
-
-# function to generate gen/*.{c,h}
-from lib.gen_external import generate_external
-output_path = 'gen'
-
-include_dirs = []
-library_dirs = []
-define_macros = []
-extra_link_args = []
-
-include_dirs += [ 'ext' ]
-include_dirs += [ output_path ] # aubio-generated.h
-include_dirs += [ numpy.get_include() ]
-
-if sys.platform.startswith('darwin'):
-    extra_link_args += ['-framework','CoreFoundation', '-framework','AudioToolbox']
-
-if os.path.isfile('../src/aubio.h'):
-    define_macros += [('USE_LOCAL_AUBIO', 1)]
-    include_dirs += ['../src'] # aubio.h
-    library_dirs += ['../build/src']
-
-aubio_extension = Extension("aubio._aubio", [
-    "ext/aubiomodule.c",
-    "ext/aubioproxy.c",
-    "ext/ufuncs.c",
-    "ext/py-musicutils.c",
-    "ext/py-cvec.c",
-    # example without macro
-    "ext/py-filter.c",
-    # macroised
-    "ext/py-filterbank.c",
-    "ext/py-fft.c",
-    "ext/py-phasevoc.c",
-    "ext/py-source.c",
-    "ext/py-sink.c",
-    # generate files if they don't exit
-    ] + generate_external(output_path, overwrite = False),
-    include_dirs = include_dirs,
-    library_dirs = library_dirs,
-    extra_link_args = extra_link_args,
-    define_macros = define_macros,
-    libraries=['aubio'])
-
-classifiers = [
-    'Development Status :: 4 - Beta',
-    'Environment :: Console',
-    'Intended Audience :: Science/Research',
-    'Topic :: Software Development :: Libraries',
-    'Topic :: Multimedia :: Sound/Audio :: Analysis',
-    'Topic :: Multimedia :: Sound/Audio :: Sound Synthesis',
-    'Operating System :: POSIX',
-    'Operating System :: MacOS :: MacOS X',
-    'Operating System :: Microsoft :: Windows',
-    'Programming Language :: C',
-    'Programming Language :: Python',
-    'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
-    ]
-
-distrib = setup(name='aubio',
-    version = __version__,
-    packages = ['aubio'],
-    package_dir = {'aubio':'lib/aubio'},
-    scripts = ['scripts/aubiocut'],
-    ext_modules = [aubio_extension],
-    description = 'interface to the aubio library',
-    long_description = 'interface to the aubio library',
-    license = 'GNU/GPL version 3',
-    author = 'Paul Brossier',
-    author_email = 'piem@aubio.org',
-    maintainer = 'Paul Brossier',
-    maintainer_email = 'piem@aubio.org',
-    url = 'http://aubio.org/',
-    platforms = 'any',
-    classifiers = classifiers,
-    install_requires = ['numpy'],
-    cmdclass = {
-        'clean': CleanGenerated,
-        'generate': GenerateCommand,
-        }
-    )
Index: requirements.txt
===================================================================
--- requirements.txt	(revision 1167631cbafc6fa1cbc277c7f9c195d47b08b72d)
+++ requirements.txt	(revision 1167631cbafc6fa1cbc277c7f9c195d47b08b72d)
@@ -0,0 +1,2 @@
+numpy
+nose2
Index: setup.py
===================================================================
--- setup.py	(revision 1167631cbafc6fa1cbc277c7f9c195d47b08b72d)
+++ setup.py	(revision 1167631cbafc6fa1cbc277c7f9c195d47b08b72d)
@@ -0,0 +1,91 @@
+#! /usr/bin/env python
+
+import sys
+import os.path
+import numpy
+from setuptools import setup, Extension
+from python.lib.moresetuptools import CleanGenerated, GenerateCommand
+# function to generate gen/*.{c,h}
+from python.lib.gen_external import generate_external, header, output_path
+
+# read from VERSION
+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
+
+include_dirs = []
+library_dirs = []
+define_macros = []
+extra_link_args = []
+
+include_dirs += [ 'python/ext' ]
+include_dirs += [ output_path ] # aubio-generated.h
+include_dirs += [ numpy.get_include() ]
+
+if sys.platform.startswith('darwin'):
+    extra_link_args += ['-framework','CoreFoundation', '-framework','AudioToolbox']
+
+if os.path.isfile('src/aubio.h'):
+    define_macros += [('USE_LOCAL_AUBIO', 1)]
+    include_dirs += ['src'] # aubio.h
+    library_dirs += ['build/src']
+
+aubio_extension = Extension("aubio._aubio", [
+    "python/ext/aubiomodule.c",
+    "python/ext/aubioproxy.c",
+    "python/ext/ufuncs.c",
+    "python/ext/py-musicutils.c",
+    "python/ext/py-cvec.c",
+    "python/ext/py-filter.c",
+    "python/ext/py-filterbank.c",
+    "python/ext/py-fft.c",
+    "python/ext/py-phasevoc.c",
+    "python/ext/py-source.c",
+    "python/ext/py-sink.c",
+    # generate files if they don't exit
+    ] + generate_external(header, output_path, overwrite = False),
+    include_dirs = include_dirs,
+    library_dirs = library_dirs,
+    extra_link_args = extra_link_args,
+    define_macros = define_macros,
+    libraries=['aubio'])
+
+classifiers = [
+    'Development Status :: 4 - Beta',
+    'Environment :: Console',
+    'Intended Audience :: Science/Research',
+    'Topic :: Software Development :: Libraries',
+    'Topic :: Multimedia :: Sound/Audio :: Analysis',
+    'Topic :: Multimedia :: Sound/Audio :: Sound Synthesis',
+    'Operating System :: POSIX',
+    'Operating System :: MacOS :: MacOS X',
+    'Operating System :: Microsoft :: Windows',
+    'Programming Language :: C',
+    'Programming Language :: Python',
+    'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
+    ]
+
+distrib = setup(name='aubio',
+    version = __version__,
+    packages = ['aubio'],
+    package_dir = {'aubio':'python/lib/aubio'},
+    scripts = ['python/scripts/aubiocut'],
+    ext_modules = [aubio_extension],
+    description = 'interface to the aubio library',
+    long_description = 'interface to the aubio library',
+    license = 'GNU/GPL version 3',
+    author = 'Paul Brossier',
+    author_email = 'piem@aubio.org',
+    maintainer = 'Paul Brossier',
+    maintainer_email = 'piem@aubio.org',
+    url = 'http://aubio.org/',
+    platforms = 'any',
+    classifiers = classifiers,
+    install_requires = ['numpy'],
+    cmdclass = {
+        'clean': CleanGenerated,
+        'generate': GenerateCommand,
+        },
+    test_suite = 'nose2.collector.collector',
+    )
