setup.py: use custom build_ext instead of 'generate' command, define HAVE_AUBIO_DOUBL...
authorPaul Brossier <piem@piem.org>
Mon, 3 Oct 2016 14:40:48 +0000 (16:40 +0200)
committerPaul Brossier <piem@piem.org>
Mon, 3 Oct 2016 14:40:48 +0000 (16:40 +0200)
Makefile
python/lib/moresetuptools.py
setup.py

index 9a0a80d..07e6bcd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ build: configure
        $(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 @@ test_pure_python_wheel:
        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
index 957dfdd..8eb6113 100644 (file)
@@ -127,22 +127,42 @@ class CleanGenerated(distutils.command.clean.clean):
         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)
index 7fc102c..f79e59a 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -47,20 +47,8 @@ aubio_extension = Extension("aubio._aubio",
     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',
@@ -77,14 +65,6 @@ classifiers = [
     '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 @@ distrib = setup(name='aubio',
     install_requires = ['numpy'],
     cmdclass = {
         'clean': CleanGenerated,
-        'generate': GenerateCommand,
         'build_ext': build_ext,
         },
     test_suite = 'nose2.collector.collector',