-
Notifications
You must be signed in to change notification settings - Fork 15
/
setup.py
71 lines (60 loc) · 2.49 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
from sys import exit, argv
from distutils.core import setup, Extension
from os.path import exists, realpath, dirname, join as path_join
from sys import argv as sys_argv
from sysconfig import get_platform
def main():
mod_name = 'G722'
mod_name_dbg = mod_name + '_debug'
mod_dir = dirname(realpath(sys_argv[0]))
src_dir = './' if exists('g722_decode.c') else '../'
mod_fname = mod_name + '_mod.c'
mod_dir = '' if exists(mod_fname) else 'python/'
def np_include():
import numpy as np
return f'-I{np.get_include()}'
is_win = get_platform().startswith('win')
is_mac = get_platform().startswith('macosx-')
compile_args = [f'-I{src_dir}', np_include()]
if not is_win:
compile_args.append('-flto')
link_args = ['-flto',] if not is_win else []
if not is_mac and not is_win:
smap_fname = f'{mod_dir}symbols.map'
link_args.append(f'-Wl,--version-script={smap_fname}')
debug_cflags = ['-g3', '-O0', '-DDEBUG_MOD']
debug_link_args = ['-g3', '-O0']
mod_common_args = {
'sources': [mod_dir + mod_fname, src_dir + 'g722_decode.c', src_dir + 'g722_encode.c'],
'extra_compile_args': compile_args,
'extra_link_args': link_args
}
mod_debug_args = mod_common_args.copy()
mod_debug_args['extra_compile_args'] = mod_debug_args['extra_compile_args'] + debug_cflags
mod_debug_args['extra_link_args'] = mod_debug_args['extra_link_args'] + debug_link_args
module1 = Extension(mod_name, **mod_common_args)
module2 = Extension(mod_name_dbg, **mod_debug_args)
requirements = [x.strip() for x in open(mod_dir + "requirements.txt", "r").readlines()]
with open(src_dir + "README.md", "r") as fh:
long_description = fh.read()
kwargs = {
'name':mod_name,
'version':'1.2.0',
'description':'This is a package for G.722 module',
'long_description': long_description,
'long_description_content_type': "text/markdown",
'author':'Maksym Sobolyev',
'author_email':'[email protected]',
'url':'https://github.com/sippy/libg722',
'ext_modules': [module1, module2],
'python_requires': '>=3.10',
'install_requires': requirements,
'classifiers': [
'License :: Public Domain',
'Operating System :: OS Independent',
'Programming Language :: C',
'Programming Language :: Python'
]
}
setup (**kwargs)
if __name__ == '__main__': main()