From: Paul Brossier Date: Fri, 13 May 2016 16:50:20 +0000 (+0200) Subject: move python/setup.py to setup.py, update Makefile, add requirements X-Git-Tag: 0.4.4~300^2~52 X-Git-Url: https://git.aubio.org/?p=aubio.git;a=commitdiff_plain;h=1167631cbafc6fa1cbc277c7f9c195d47b08b72d move python/setup.py to setup.py, update Makefile, add requirements --- 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/nose2.cfg b/nose2.cfg new file mode 100644 index 00000000..ca85bd29 --- /dev/null +++ b/nose2.cfg @@ -0,0 +1,6 @@ +[unittest] +start-dir = python/tests/ +plugins = nose2.plugins.mp + +[multiprocess] +always-on = true 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/python/nose2.cfg b/python/nose2.cfg deleted file mode 100644 index 93f8a5f1..00000000 --- a/python/nose2.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[unittest] -start-dir = tests/ -plugins = nose2.plugins.mp - -[multiprocess] -always-on = true diff --git a/python/setup.py b/python/setup.py deleted file mode 100755 index f57280ef..00000000 --- a/python/setup.py +++ /dev/null @@ -1,95 +0,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, - } - ) 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/setup.py b/setup.py new file mode 100755 index 00000000..269f15c9 --- /dev/null +++ b/setup.py @@ -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', + )