History

Merge branch 'master' into feature/pitchshift

Paul Brossier committed 7 years ago

Commit 633400d2 parents 5b46bc3 f19db54230 files · +12450 −4607Browse files

Showing the changes to python/lib/moresetuptools.py (1 of 230 files). Show all

Unified · Split

python/lib/moresetuptools.py+78−26
@@ -2,7 +2,9 @@ · 1 unmodified line
22 #
33 import sys, os, glob, subprocess
44 import distutils, distutils.command.clean, distutils.dir_util
5−from .gen_external import generate_external, header, output_path
5+from gen_external import generate_external, header, output_path
6+
7+from this_version import get_aubio_version
68
79 # inspired from https://gist.github.com/abergmeier/9488990
810 def add_packages(packages, ext=None, **kw):
@@ -21,6 +23,7 @@ def add_packages(packages, ext=None, **kw): · 12 unmodified lines
2123 }
2224
2325 for package in packages:
26+ print("checking for {:s}".format(package))
2427 cmd = ['pkg-config', '--libs', '--cflags', package]
2528 try:
2629 tokens = subprocess.check_output(cmd)
@@ -54,13 +57,14 @@ def add_local_aubio_lib(ext): · 27 unmodified lines
5457
5558 def add_local_aubio_sources(ext):
5659 """ build aubio inside python module instead of linking against libaubio """
57− print("Warning: libaubio was not built with waf, adding src/")
58− # create an empty header, macros will be passed on the command line
59− fake_config_header = os.path.join('python', 'ext', 'config.h')
60− distutils.file_util.write_file(fake_config_header, "")
61− aubio_sources = glob.glob(os.path.join('src', '**.c'))
62− aubio_sources += glob.glob(os.path.join('src', '*', '**.c'))
60+ print("Info: libaubio was not installed or built locally with waf, adding src/")
61+ aubio_sources = sorted(glob.glob(os.path.join('src', '**.c')))
62+ aubio_sources += sorted(glob.glob(os.path.join('src', '*', '**.c')))
6363 ext.sources += aubio_sources
64+
65+def add_local_macros(ext, usedouble = False):
66+ if usedouble:
67+ ext.define_macros += [('HAVE_AUBIO_DOUBLE', 1)]
6468 # define macros (waf puts them in build/src/config.h)
6569 for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H',
6670 'HAVE_MATH_H', 'HAVE_STRING_H',
@@ -69,22 +73,31 @@ def add_local_aubio_sources(ext): · 2 unmodified lines
6973 'HAVE_MEMCPY_HACKS']:
7074 ext.define_macros += [(define_macro, 1)]
7175
76+def add_external_deps(ext, usedouble = False):
7277 # loof for additional packages
7378 print("Info: looking for *optional* additional packages")
74− packages = ['libavcodec', 'libavformat', 'libavutil', 'libavresample',
79+ packages = ['libavcodec', 'libavformat', 'libavutil',
80+ 'libswresample', 'libavresample',
7581 'jack',
76− 'sndfile', 'samplerate',
82+ 'sndfile',
7783 'rubberband',
7884 #'fftw3f',
7985 ]
86+ # samplerate only works with float
87+ if usedouble is False:
88+ packages += ['samplerate']
89+ else:
90+ print("Info: not adding libsamplerate in double precision mode")
8091 add_packages(packages, ext=ext)
8192 if 'avcodec' in ext.libraries \
8293 and 'avformat' in ext.libraries \
83− and 'avutil' in ext.libraries \
84− and 'avresample' in ext.libraries:
85− ext.define_macros += [('HAVE_LIBAV', 1)]
86− if 'jack' in ext.libraries:
87− ext.define_macros += [('HAVE_JACK', 1)]
94+ and 'avutil' in ext.libraries:
95+ if 'swresample' in ext.libraries:
96+ ext.define_macros += [('HAVE_SWRESAMPLE', 1)]
97+ elif 'avresample' in ext.libraries:
98+ ext.define_macros += [('HAVE_AVRESAMPLE', 1)]
99+ if 'swresample' in ext.libraries or 'avresample' in ext.libraries:
100+ ext.define_macros += [('HAVE_LIBAV', 1)]
88101 if 'sndfile' in ext.libraries:
89102 ext.define_macros += [('HAVE_SNDFILE', 1)]
90103 if 'samplerate' in ext.libraries:
@@ -107,39 +120,78 @@ def add_local_aubio_sources(ext): · 16 unmodified lines
107120
108121 ext.define_macros += [('HAVE_WAVWRITE', 1)]
109122 ext.define_macros += [('HAVE_WAVREAD', 1)]
110− # TODO:
111− # add cblas
123+
124+ # TODO: add cblas
112125 if 0:
113126 ext.libraries += ['cblas']
114127 ext.define_macros += [('HAVE_ATLAS_CBLAS_H', 1)]
115128
116129 def add_system_aubio(ext):
117130 # use pkg-config to find aubio's location
118− add_packages(['aubio'], ext)
131+ aubio_version = get_aubio_version()
132+ add_packages(['aubio = ' + aubio_version], ext)
119133 if 'aubio' not in ext.libraries:
120− print("Error: libaubio not found")
134+ print("Info: aubio " + aubio_version + " was not found by pkg-config")
135+ else:
136+ print("Info: using system aubio " + aubio_version + " found in " + ' '.join(ext.library_dirs))
137+
138+def add_libav_on_win(ext):
139+ """ no pkg-config on windows, simply assume these libs are available """
140+ ext.libraries += ['avformat', 'avutil', 'avcodec', 'swresample']
141+ for define_macro in ['HAVE_LIBAV', 'HAVE_SWRESAMPLE']:
142+ ext.define_macros += [(define_macro, 1)]
121143
122144 class CleanGenerated(distutils.command.clean.clean):
123145 def run(self):
124− distutils.dir_util.remove_tree(output_path)
125− distutils.command.clean.clean.run(self)
146+ if os.path.isdir(output_path):
147+ distutils.dir_util.remove_tree(output_path)
148+
149+from distutils.command.build_ext import build_ext as _build_ext
150+class build_ext(_build_ext):
126151
127−class GenerateCommand(distutils.cmd.Command):
128− description = 'generate gen/gen-*.c files from ../src/aubio.h'
129− user_options = [
152+ user_options = _build_ext.user_options + [
130153 # The format is (long option, short option, description).
131154 ('enable-double', None, 'use HAVE_AUBIO_DOUBLE=1 (default: 0)'),
132155 ]
133156
134157 def initialize_options(self):
158+ _build_ext.initialize_options(self)
135159 self.enable_double = False
136160
137161 def finalize_options(self):
162+ _build_ext.finalize_options(self)
138163 if self.enable_double:
139164 self.announce(
140165 'will generate code for aubio compiled with HAVE_AUBIO_DOUBLE=1',
141166 level=distutils.log.INFO)
142167
143− def run(self):
144− self.announce( 'Generating code', level=distutils.log.INFO)
145− generated_object_files = generate_external(header, output_path, usedouble=self.enable_double)
168+ def build_extension(self, extension):
169+ if self.enable_double or 'HAVE_AUBIO_DOUBLE' in os.environ:
170+ enable_double = True
171+ else:
172+ enable_double = False
173+ # seack for aubio headers and lib in PKG_CONFIG_PATH
174+ add_system_aubio(extension)
175+ # the lib was not installed on this system
176+ if 'aubio' not in extension.libraries:
177+ # use local src/aubio.h
178+ if os.path.isfile(os.path.join('src', 'aubio.h')):
179+ add_local_aubio_header(extension)
180+ add_local_macros(extension, usedouble=enable_double)
181+ # look for a local waf build
182+ if os.path.isfile(os.path.join('build','src', 'fvec.c.1.o')):
183+ add_local_aubio_lib(extension)
184+ else:
185+ # check for external dependencies
186+ add_external_deps(extension, usedouble=enable_double)
187+ # force adding libav on windows
188+ if os.name == 'nt' and ('WITH_LIBAV' in os.environ \
189+ or 'CONDA_PREFIX' in os.environ):
190+ add_libav_on_win(extension)
191+ # add libaubio sources and look for optional deps with pkg-config
192+ add_local_aubio_sources(extension)
193+ # generate files python/gen/*.c, python/gen/aubio-generated.h
194+ extension.include_dirs += [ output_path ]
195+ extension.sources += generate_external(header, output_path, overwrite = False,
196+ usedouble=enable_double)
197+ return _build_ext.build_extension(self, extension)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t