From 1167631cbafc6fa1cbc277c7f9c195d47b08b72d Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 13 May 2016 18:50:20 +0200 Subject: [PATCH] move python/setup.py to setup.py, update Makefile, add requirements --- Makefile | 25 ++++++++++++--------- python/nose2.cfg => nose2.cfg | 2 +- python/lib/gen_external.py | 28 ++++++++++++++--------- python/lib/moresetuptools.py | 6 ++--- requirements.txt | 2 ++ python/setup.py => setup.py | 52 ++++++++++++++++++++----------------------- 6 files changed, 63 insertions(+), 52 deletions(-) rename python/nose2.cfg => nose2.cfg (73%) create mode 100644 requirements.txt rename python/setup.py => setup.py (72%) diff --git a/Makefile b/Makefile index 939c7c1d..c3684d0c 100644 --- a/Makefile +++ b/Makefile @@ -28,27 +28,32 @@ build: configure $(WAFCMD) build $(WAFOPTS) 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: $(WAFCMD) clean diff --git a/python/nose2.cfg b/nose2.cfg similarity index 73% rename from python/nose2.cfg rename to nose2.cfg index 93f8a5f1..ca85bd29 100644 --- a/python/nose2.cfg +++ b/nose2.cfg @@ -1,5 +1,5 @@ [unittest] -start-dir = tests/ +start-dir = python/tests/ plugins = nose2.plugins.mp [multiprocess] diff --git a/python/lib/gen_external.py b/python/lib/gen_external.py index e52f0f9b..2fd15195 100644 --- a/python/lib/gen_external.py +++ b/python/lib/gen_external.py @@ -1,6 +1,9 @@ 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" """ @@ -41,9 +44,9 @@ skip_objects = [ ] -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()] @@ -66,11 +69,11 @@ def get_cpp_objects(): 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 = {} for o in cpp_objects: @@ -121,9 +124,12 @@ def generate_external(output_path, usedouble = False, overwrite = True): print ( "{:15s} {:10s} {:d}".format(o, family, len(lib[o][family]) ) ) """ - 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() output_file = os.path.join(output_path, 'gen-%s.c' % o) @@ -132,7 +138,7 @@ def generate_external(output_path, usedouble = False, overwrite = True): print ("wrote %s" % output_file ) 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]) out += """ @@ -186,5 +192,7 @@ void add_generated_objects( PyObject *m ); return sources_list 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) diff --git a/python/lib/moresetuptools.py b/python/lib/moresetuptools.py index 7966606e..ac5c8fb9 100644 --- a/python/lib/moresetuptools.py +++ b/python/lib/moresetuptools.py @@ -1,8 +1,9 @@ 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) class GenerateCommand(distutils.cmd.Command): @@ -23,5 +24,4 @@ class GenerateCommand(distutils.cmd.Command): 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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..99ce0ab5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +numpy +nose2 diff --git a/python/setup.py b/setup.py similarity index 72% rename from python/setup.py rename to setup.py index f57280ef..269f15c9 100755 --- a/python/setup.py +++ b/setup.py @@ -1,11 +1,12 @@ #! /usr/bin/env python -from setuptools import setup, Extension -from lib.moresetuptools import CleanGenerated, GenerateCommand - 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()) @@ -13,43 +14,37 @@ __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 += [ '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'): +if os.path.isfile('src/aubio.h'): define_macros += [('USE_LOCAL_AUBIO', 1)] - include_dirs += ['../src'] # aubio.h - library_dirs += ['../build/src'] + 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", + "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(output_path, overwrite = False), + ] + generate_external(header, output_path, overwrite = False), include_dirs = include_dirs, library_dirs = library_dirs, extra_link_args = extra_link_args, @@ -74,8 +69,8 @@ classifiers = [ distrib = setup(name='aubio', version = __version__, packages = ['aubio'], - package_dir = {'aubio':'lib/aubio'}, - scripts = ['scripts/aubiocut'], + 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', @@ -91,5 +86,6 @@ distrib = setup(name='aubio', cmdclass = { 'clean': CleanGenerated, 'generate': GenerateCommand, - } + }, + test_suite = 'nose2.collector.collector', ) -- 2.11.0