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
2#2#
3import sys, os, glob, subprocess3import sys, os, glob, subprocess
4import distutils, distutils.command.clean, distutils.dir_util4import distutils, distutils.command.clean, distutils.dir_util
5from .gen_external import generate_external, header, output_path5from gen_external import generate_external, header, output_path
6
7from this_version import get_aubio_version
6 8
7# inspired from https://gist.github.com/abergmeier/94889909# inspired from https://gist.github.com/abergmeier/9488990
8def add_packages(packages, ext=None, **kw):10def add_packages(packages, ext=None, **kw):
@@ -21,6 +23,7 @@ def add_packages(packages, ext=None, **kw): · 12 unmodified lines
21 }23 }
22 24
23 for package in packages:25 for package in packages:
26 print("checking for {:s}".format(package))
24 cmd = ['pkg-config', '--libs', '--cflags', package]27 cmd = ['pkg-config', '--libs', '--cflags', package]
25 try:28 try:
26 tokens = subprocess.check_output(cmd)29 tokens = subprocess.check_output(cmd)
@@ -54,13 +57,14 @@ def add_local_aubio_lib(ext): · 27 unmodified lines
54 57
55def add_local_aubio_sources(ext):58def add_local_aubio_sources(ext):
56 """ build aubio inside python module instead of linking against libaubio """59 """ build aubio inside python module instead of linking against libaubio """
57 print("Warning: libaubio was not built with waf, adding src/")60 print("Info: libaubio was not installed or built locally with waf, adding src/")
58 # create an empty header, macros will be passed on the command line61 aubio_sources = sorted(glob.glob(os.path.join('src', '**.c')))
59 fake_config_header = os.path.join('python', 'ext', 'config.h')62 aubio_sources += sorted(glob.glob(os.path.join('src', '*', '**.c')))
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'))
63 ext.sources += aubio_sources63 ext.sources += aubio_sources
64
65def add_local_macros(ext, usedouble = False):
66 if usedouble:
67 ext.define_macros += [('HAVE_AUBIO_DOUBLE', 1)]
64 # define macros (waf puts them in build/src/config.h)68 # define macros (waf puts them in build/src/config.h)
65 for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H',69 for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H',
66 'HAVE_MATH_H', 'HAVE_STRING_H',70 'HAVE_MATH_H', 'HAVE_STRING_H',
@@ -69,22 +73,31 @@ def add_local_aubio_sources(ext): · 2 unmodified lines
69 'HAVE_MEMCPY_HACKS']:73 'HAVE_MEMCPY_HACKS']:
70 ext.define_macros += [(define_macro, 1)]74 ext.define_macros += [(define_macro, 1)]
71 75
76def add_external_deps(ext, usedouble = False):
72 # loof for additional packages77 # loof for additional packages
73 print("Info: looking for *optional* additional packages")78 print("Info: looking for *optional* additional packages")
74 packages = ['libavcodec', 'libavformat', 'libavutil', 'libavresample',79 packages = ['libavcodec', 'libavformat', 'libavutil',
80 'libswresample', 'libavresample',
75 'jack',81 'jack',
76 'sndfile', 'samplerate',82 'sndfile',
77 'rubberband',83 'rubberband',
78 #'fftw3f',84 #'fftw3f',
79 ]85 ]
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")
80 add_packages(packages, ext=ext)91 add_packages(packages, ext=ext)
81 if 'avcodec' in ext.libraries \92 if 'avcodec' in ext.libraries \
82 and 'avformat' in ext.libraries \93 and 'avformat' in ext.libraries \
83 and 'avutil' in ext.libraries \94 and 'avutil' in ext.libraries:
84 and 'avresample' in ext.libraries:95 if 'swresample' in ext.libraries:
85 ext.define_macros += [('HAVE_LIBAV', 1)]96 ext.define_macros += [('HAVE_SWRESAMPLE', 1)]
86 if 'jack' in ext.libraries:97 elif 'avresample' in ext.libraries:
87 ext.define_macros += [('HAVE_JACK', 1)]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)]
88 if 'sndfile' in ext.libraries:101 if 'sndfile' in ext.libraries:
89 ext.define_macros += [('HAVE_SNDFILE', 1)]102 ext.define_macros += [('HAVE_SNDFILE', 1)]
90 if 'samplerate' in ext.libraries:103 if 'samplerate' in ext.libraries:
@@ -107,39 +120,78 @@ def add_local_aubio_sources(ext): · 16 unmodified lines
107 120
108 ext.define_macros += [('HAVE_WAVWRITE', 1)]121 ext.define_macros += [('HAVE_WAVWRITE', 1)]
109 ext.define_macros += [('HAVE_WAVREAD', 1)]122 ext.define_macros += [('HAVE_WAVREAD', 1)]
110 # TODO:123
111 # add cblas124 # TODO: add cblas
112 if 0:125 if 0:
113 ext.libraries += ['cblas']126 ext.libraries += ['cblas']
114 ext.define_macros += [('HAVE_ATLAS_CBLAS_H', 1)]127 ext.define_macros += [('HAVE_ATLAS_CBLAS_H', 1)]
115 128
116def add_system_aubio(ext):129def add_system_aubio(ext):
117 # use pkg-config to find aubio's location130 # 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)
119 if 'aubio' not in ext.libraries:133 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
138def 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)]
121 143
122class CleanGenerated(distutils.command.clean.clean):144class CleanGenerated(distutils.command.clean.clean):
123 def run(self):145 def run(self):
124 distutils.dir_util.remove_tree(output_path)146 if os.path.isdir(output_path):
125 distutils.command.clean.clean.run(self)147 distutils.dir_util.remove_tree(output_path)
148
149from distutils.command.build_ext import build_ext as _build_ext
150class build_ext(_build_ext):
126 151
127class GenerateCommand(distutils.cmd.Command):152 user_options = _build_ext.user_options + [
128 description = 'generate gen/gen-*.c files from ../src/aubio.h'
129 user_options = [
130 # The format is (long option, short option, description).153 # The format is (long option, short option, description).
131 ('enable-double', None, 'use HAVE_AUBIO_DOUBLE=1 (default: 0)'),154 ('enable-double', None, 'use HAVE_AUBIO_DOUBLE=1 (default: 0)'),
132 ]155 ]
133 156
134 def initialize_options(self):157 def initialize_options(self):
158 _build_ext.initialize_options(self)
135 self.enable_double = False159 self.enable_double = False
136 160
137 def finalize_options(self):161 def finalize_options(self):
162 _build_ext.finalize_options(self)
138 if self.enable_double:163 if self.enable_double:
139 self.announce(164 self.announce(
140 'will generate code for aubio compiled with HAVE_AUBIO_DOUBLE=1',165 'will generate code for aubio compiled with HAVE_AUBIO_DOUBLE=1',
141 level=distutils.log.INFO)166 level=distutils.log.INFO)
142 167
143 def run(self):168 def build_extension(self, extension):
144 self.announce( 'Generating code', level=distutils.log.INFO)169 if self.enable_double or 'HAVE_AUBIO_DOUBLE' in os.environ:
145 generated_object_files = generate_external(header, output_path, usedouble=self.enable_double)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