Showing the changes to python (5 of 5 files). Show all
Unified · Split
| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | #include <Python.h> |
| 2 | 2 | #include <structmember.h> |
| 3 | 3 | |
| 4 | +#include "aubio-generated.h" | |
| 5 | + | |
| 4 | 6 | #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION |
| 5 | 7 | |
| 6 | 8 | // define numpy unique symbols for aubio |
| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | #define PY_AUBIO_MODULE_MAIN |
| 2 | 2 | #include "aubio-types.h" |
| 3 | −#include "aubio-generated.h" | |
| 4 | 3 | #include "py-musicutils.h" |
| 5 | 4 | |
| 6 | 5 | static char aubio_module_doc[] = "Python module for the aubio library"; |
| @@ -1,4 +1,4 @@ | ||
| 1 | −import os | |
| 1 | +import os, glob | |
| 2 | 2 | |
| 3 | 3 | header = """// this file is generated! do not modify |
| 4 | 4 | #include "aubio-types.h" |
| @@ -66,8 +66,9 @@ def get_cpp_objects(): · 61 unmodified lines | ||
| 66 | 66 | |
| 67 | 67 | return cpp_output, cpp_objects |
| 68 | 68 | |
| 69 | −def generate_external(output_path, usedouble = False): | |
| 69 | +def generate_external(output_path, usedouble = False, overwrite = True): | |
| 70 | 70 | if not os.path.isdir(output_path): os.mkdir(output_path) |
| 71 | + elif overwrite == False: return glob.glob(os.path.join(output_path, '*.c')) | |
| 71 | 72 | sources_list = [] |
| 72 | 73 | cpp_output, cpp_objects = get_cpp_objects() |
| 73 | 74 | lib = {} |
| @@ -160,10 +161,17 @@ void add_generated_objects ( PyObject *m ) · 86 unmodified lines | ||
| 160 | 161 | sources_list.append(output_file) |
| 161 | 162 | |
| 162 | 163 | objlist = "".join(["extern PyTypeObject Py_%sType;\n" % p for p in lib]) |
| 163 | − out = """ | |
| 164 | −// generated list of objects created with gen_external.py | |
| 165 | −#include <Python.h> | |
| 164 | + out = """// generated list of objects created with gen_external.py | |
| 166 | 165 | |
| 166 | +#include <Python.h> | |
| 167 | +""" | |
| 168 | + if usedouble: | |
| 169 | + out += """ | |
| 170 | +#ifndef HAVE_AUBIO_DOUBLE | |
| 171 | +#define HAVE_AUBIO_DOUBLE 1 | |
| 172 | +#endif | |
| 173 | +""" | |
| 174 | + out += """ | |
| 167 | 175 | {objlist} |
| 168 | 176 | int generated_objects ( void ); |
| 169 | 177 | void add_generated_objects( PyObject *m ); |
| @@ -0,0 +1,30 @@ | ||
| 1 | +import distutils, os, subprocess | |
| 2 | +import setuptools.command.build_py | |
| 3 | +import distutils.command.clean | |
| 4 | +from distutils.dir_util import remove_tree | |
| 5 | + | |
| 6 | +class CleanGenerated(distutils.command.clean.clean): | |
| 7 | + def run(self): | |
| 8 | + remove_tree('gen') | |
| 9 | + distutils.command.clean.clean.run(self) | |
| 10 | + | |
| 11 | +class GenerateCommand(distutils.cmd.Command): | |
| 12 | + description = 'generate gen/gen-*.c files from ../src/aubio.h' | |
| 13 | + user_options = [ | |
| 14 | + # The format is (long option, short option, description). | |
| 15 | + ('enable-double', None, 'use HAVE_AUBIO_DOUBLE=1 (default: 0)'), | |
| 16 | + ] | |
| 17 | + | |
| 18 | + def initialize_options(self): | |
| 19 | + self.enable_double = False | |
| 20 | + | |
| 21 | + def finalize_options(self): | |
| 22 | + if self.enable_double: | |
| 23 | + self.announce( | |
| 24 | + 'will generate code for aubio compiled with HAVE_AUBIO_DOUBLE=1', | |
| 25 | + level=distutils.log.INFO) | |
| 26 | + | |
| 27 | + def run(self): | |
| 28 | + self.announce( 'Generating code', level=distutils.log.INFO) | |
| 29 | + from .gen_external import generate_external | |
| 30 | + generated_object_files = generate_external('gen', usedouble = self.enable_double) | |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | #! /usr/bin/env python |
| 2 | 2 | |
| 3 | −from setuptools import setup, Extension | |
| 3 | +from setuptools import setup, Extension, Command | |
| 4 | +from lib.moresetuptools import CleanGenerated, GenerateCommand | |
| 4 | 5 | |
| 5 | 6 | import sys |
| 6 | 7 | import os.path |
| @@ -12,30 +13,22 @@ __version__ = '.'.join \ · 5 unmodified lines | ||
| 12 | 13 | ([str(x) for x in [AUBIO_MAJOR_VERSION, AUBIO_MINOR_VERSION, AUBIO_PATCH_VERSION]]) \ |
| 13 | 14 | + AUBIO_VERSION_STATUS |
| 14 | 15 | |
| 16 | +# function to generate gen/*.{c,h} | |
| 17 | +from lib.gen_external import generate_external | |
| 18 | +output_path = 'gen' | |
| 15 | 19 | |
| 16 | 20 | include_dirs = [] |
| 17 | 21 | library_dirs = [] |
| 18 | 22 | define_macros = [] |
| 19 | 23 | extra_link_args = [] |
| 20 | 24 | |
| 21 | −include_dirs += ['ext'] | |
| 25 | +include_dirs += [ 'ext' ] | |
| 26 | +include_dirs += [ output_path ] # aubio-generated.h | |
| 22 | 27 | include_dirs += [ numpy.get_include() ] |
| 23 | 28 | |
| 24 | 29 | if sys.platform.startswith('darwin'): |
| 25 | 30 | extra_link_args += ['-framework','CoreFoundation', '-framework','AudioToolbox'] |
| 26 | 31 | |
| 27 | −output_path = 'gen' | |
| 28 | −generated_object_files = [] | |
| 29 | − | |
| 30 | −if not os.path.isdir(output_path): | |
| 31 | − from lib.gen_external import generate_external | |
| 32 | − generated_object_files = generate_external(output_path) | |
| 33 | − # define include dirs | |
| 34 | −else: | |
| 35 | − import glob | |
| 36 | − generated_object_files = glob.glob(os.path.join(output_path, '*.c')) | |
| 37 | −include_dirs += [output_path] | |
| 38 | − | |
| 39 | 32 | if os.path.isfile('../src/aubio.h'): |
| 40 | 33 | define_macros += [('USE_LOCAL_AUBIO', 1)] |
| 41 | 34 | include_dirs += ['../src'] # aubio.h |
| @@ -56,8 +49,8 @@ aubio_extension = Extension("aubio._aubio", [ · 14 unmodified lines | ||
| 56 | 49 | "ext/py-phasevoc.c", |
| 57 | 50 | "ext/py-source.c", |
| 58 | 51 | "ext/py-sink.c", |
| 59 | − # generated files | |
| 60 | − ] + generated_object_files, | |
| 52 | + # generate files if they don't exit | |
| 53 | + ] + generate_external(output_path, overwrite = False), | |
| 61 | 54 | include_dirs = include_dirs, |
| 62 | 55 | library_dirs = library_dirs, |
| 63 | 56 | extra_link_args = extra_link_args, |
| @@ -96,4 +89,8 @@ distrib = setup(name='aubio', · 32 unmodified lines | ||
| 96 | 89 | platforms = 'any', |
| 97 | 90 | classifiers = classifiers, |
| 98 | 91 | install_requires = ['numpy'], |
| 92 | + cmdclass = { | |
| 93 | + 'clean': CleanGenerated, | |
| 94 | + 'generate': GenerateCommand, | |
| 95 | + } | |
| 99 | 96 | ) |