forked from libAudioFlux/audioFlux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
158 lines (136 loc) · 5.03 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
import os
import sys
from sys import platform
from setuptools import find_packages, setup
import setuptools.command.build_py
class BuildPyCommand(setuptools.command.build_py.build_py):
def run(self):
if sys.argv[1].startswith('build'):
self.compile_c()
setuptools.command.build_py.build_py.run(self)
def compile_c(self):
"""Only supports macOS/linux"""
print('=' * 20)
print('Starting compile audioFlux of c')
current_cwd = os.getcwd()
os.chdir(os.path.join(os.getcwd(), './scripts'))
if platform == 'darwin':
r = os.system('bash ./build_macOS.sh')
filename = 'libaudioflux.dylib'
src_lib_fp = './build/macOSBuild/{}'.format(filename)
elif platform == 'linux':
r = os.system('bash ./build_linux.sh')
filename = 'libaudioflux.so'
src_lib_fp = './build/linuxBuild/{}'.format(filename)
else:
raise ValueError('Platform={} is not supported'.format(platform))
if r != 0:
exit(-1)
os.chdir(current_cwd)
print('Compile audioFlux successful.')
import shutil
dst_lib_path = 'python/audioflux/lib'
if not os.path.exists(dst_lib_path):
os.makedirs(dst_lib_path)
dst_lib_fp = os.path.join(dst_lib_path, filename)
if os.path.exists(dst_lib_fp):
os.remove(dst_lib_fp)
shutil.copyfile(src_lib_fp, dst_lib_fp)
print('Copying {src_lib_fp} to {dst_lib_fp}'.format(src_lib_fp=src_lib_fp, dst_lib_fp=dst_lib_fp))
print('=' * 20)
class BuildPyWinCommand(setuptools.command.build_py.build_py):
def run(self):
self.compile_c()
setuptools.command.build_py.build_py.run(self)
def compile_c(self):
"""Only supports macOS"""
print('Starting compile audioFlux of c')
current_cwd = os.getcwd()
os.chdir(os.path.join(os.getcwd(), './scripts'))
if platform == 'darwin' or platform == 'linux':
r = os.system('bash ./build_windows.sh')
filename = 'libaudioflux.dll'
src_lib_fp = './build/windowBuild/libaudioflux.so'.format(filename)
else:
raise ValueError('Platform={} is not supported'.format(platform))
if r != 0:
exit(-1)
os.chdir(current_cwd)
print('Compile audioFlux successful.')
import shutil
dst_lib_path = 'python/audioflux/lib'
if not os.path.exists(dst_lib_path):
os.makedirs(dst_lib_path)
dst_lib_fp = os.path.join(dst_lib_path, filename)
if os.path.exists(dst_lib_fp):
os.remove(dst_lib_fp)
shutil.copyfile(src_lib_fp, dst_lib_fp)
print('Copying {src_lib_fp} to {dst_lib_fp}'.format(src_lib_fp=src_lib_fp, dst_lib_fp=dst_lib_fp))
print('=' * 20)
about = {}
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, "python", "audioflux", "__version__.py"), "r") as f:
exec(f.read(), about)
with open("README.md", "r") as f:
readme = f.read()
def get_package_data():
package_data = {
'audioflux': ["utils/sample_data/*.wav"]
}
if sys.argv[1].startswith(('bdist', 'sdist')):
package_data['audioflux'].extend(["lib/lib/*", "lib/*"])
else:
cur_sys = platform
if sys.argv[1] == 'build_py_win':
cur_sys = 'win32'
if cur_sys == 'linux':
package_data['audioflux'].extend(["lib/*.so"])
elif cur_sys == 'darwin':
package_data['audioflux'].extend(["lib/*.dylib"])
elif cur_sys == 'win32':
package_data['audioflux'].extend(["lib/*.dll"])
return package_data
setup(
name=about['__title__'],
description=about['__description__'],
long_description=readme,
long_description_content_type="text/markdown",
keywords=[about['__title__']],
version=about['__version__'],
package_dir={"": "python"},
packages=find_packages("python"),
package_data=get_package_data(),
author="audioflux",
url='https://audioflux.top',
project_urls={
"Source": "https://github.com/libAudioFlux/audioFlux",
},
license='MIT',
python_requires=">=3.6",
install_requires=[
"numpy",
"scipy >= 1.2.0",
"soundfile>=0.12.1",
"matplotlib",
],
classifiers=[
'License :: OSI Approved :: MIT License',
'Development Status :: 3 - Alpha',
'Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'Framework :: Matplotlib',
'Programming Language :: C',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
],
cmdclass={
'build_py': BuildPyCommand,
'build_py_win': BuildPyWinCommand,
}
)