shithub: aubio

Download patch

ref: 8d09036dba68f1b646c23d7167f967761c5fbaed
parent: 45521d2a2d96b210bd7ccd6e855c8093bcfde60e
author: Paul Brossier <piem@piem.org>
date: Mon Oct 3 12:40:48 EDT 2016

setup.py: use custom build_ext instead of 'generate' command, define HAVE_AUBIO_DOUBLE to 1 if needed

--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@
 	$(WAFCMD) build $(WAFOPTS)
 
 build_python:
-	python ./setup.py generate $(ENABLE_DOUBLE) build
+	python ./setup.py build_ext $(ENABLE_DOUBLE)
 
 test_python: export LD_LIBRARY_PATH=$(PWD)/build/src
 test_python:
@@ -72,7 +72,7 @@
 	pip uninstall -v -y aubio
 
 build_python3:
-	python3 ./setup.py generate $(ENABLE_DOUBLE) build
+	python3 ./setup.py build_ext $(ENABLE_DOUBLE)
 
 clean_python3:
 	python3 ./setup.py clean
--- a/python/lib/moresetuptools.py
+++ b/python/lib/moresetuptools.py
@@ -127,22 +127,42 @@
         distutils.dir_util.remove_tree(output_path)
         distutils.command.clean.clean.run(self)
 
-class GenerateCommand(distutils.cmd.Command):
-    description = 'generate gen/gen-*.c files from ../src/aubio.h'
-    user_options = [
+from distutils.command.build_ext import build_ext as _build_ext
+class build_ext(_build_ext):
+
+    user_options = _build_ext.user_options + [
             # The format is (long option, short option, description).
             ('enable-double', None, 'use HAVE_AUBIO_DOUBLE=1 (default: 0)'),
             ]
 
     def initialize_options(self):
+        _build_ext.initialize_options(self)
         self.enable_double = False
 
     def finalize_options(self):
+        _build_ext.finalize_options(self)
         if self.enable_double:
             self.announce(
                     'will generate code for aubio compiled with HAVE_AUBIO_DOUBLE=1',
                     level=distutils.log.INFO)
 
-    def run(self):
-        self.announce( 'Generating code', level=distutils.log.INFO)
-        generated_object_files = generate_external(header, output_path, usedouble=self.enable_double)
+    def build_extension(self, extension):
+        if self.enable_double:
+            extension.define_macros += [('HAVE_AUBIO_DOUBLE', 1)]
+        if os.path.isfile('src/aubio.h'):
+            # if aubio headers are found in this directory
+            add_local_aubio_header(extension)
+            # was waf used to build the shared lib?
+            if os.path.isdir(os.path.join('build','src')):
+                # link against build/src/libaubio, built with waf
+                add_local_aubio_lib(extension)
+            else:
+                # add libaubio sources and look for optional deps with pkg-config
+                add_local_aubio_sources(extension, usedouble=self.enable_double)
+        else:
+            # look for aubio headers and lib using pkg-config
+            add_system_aubio(extension)
+        # generate files python/gen/*.c, python/gen/aubio-generated.h
+        extension.sources += generate_external(header, output_path, overwrite = False,
+                usedouble=self.enable_double)
+        return _build_ext.build_extension(self, extension)
--- a/setup.py
+++ b/setup.py
@@ -47,21 +47,9 @@
     define_macros = define_macros)
 
 if os.path.isfile('src/aubio.h'):
-    # if aubio headers are found in this directory
-    add_local_aubio_header(aubio_extension)
-    # was waf used to build the shared lib?
-    if os.path.isdir(os.path.join('build','src')):
-        # link against build/src/libaubio, built with waf
-        add_local_aubio_lib(aubio_extension)
-    else:
-        # add libaubio sources and look for optional deps with pkg-config
-        add_local_aubio_sources(aubio_extension)
-        __version__ += 'a2' # pypi version
-else:
-    # look for aubio headers and lib using pkg-config
-    add_system_aubio(aubio_extension)
+    if not os.path.isdir(os.path.join('build','src')):
+        __version__ += 'a2' # python only version
 
-
 classifiers = [
     'Development Status :: 4 - Beta',
     'Environment :: Console',
@@ -77,14 +65,6 @@
     'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
     ]
 
-from distutils.command.build_ext import build_ext as _build_ext
-class build_ext(_build_ext):
-
-    def build_extension(self, extension):
-        # generate files python/gen/*.c, python/gen/aubio-generated.h
-        extension.sources += generate_external(header, output_path, overwrite = False)
-        return _build_ext.build_extension(self, extension)
-
 distrib = setup(name='aubio',
     version = __version__,
     packages = ['aubio'],
@@ -104,7 +84,6 @@
     install_requires = ['numpy'],
     cmdclass = {
         'clean': CleanGenerated,
-        'generate': GenerateCommand,
         'build_ext': build_ext,
         },
     test_suite = 'nose2.collector.collector',