-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
75 lines (67 loc) · 2.23 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
from setuptools import setup, Extension
from distutils.command.build import build
from shutil import copyfile
from os.path import exists
# Need custom build sequence to accomodate swig
class CustomBuild(build):
def run(self):
self.run_command('build_ext')
copyfile('src/rtfir.py','rtfir.py')
build.run(self)
# Assert manifest
if not exists('MANIFEST.in'):
fd=open('MANIFEST.in','w')
fd.write('include src/rtfir.hpp')
fd.close()
# Try to compile binary extensions
try:
setup(
name='rtfir',
version='1.1.3',
ext_modules=[Extension('_rtfir',['src/rtfir.cpp','src/rtfir.i'],extra_compile_args=['-O2'],swig_opts=['-c++'])],
py_modules=['rtfir'],
author='Vegard Fiksdal',
author_email='[email protected]',
description='Realtime FIR filteters',
url='https://github.com/vfiksdal/rtfir',
cmdclass={'build': CustomBuild}
)
# Handle compilation failure
except SystemExit as e:
# Inform user of fallback option
print(str(e))
print('')
print('='*74)
print('Compilation of binary extensions failed, please read the')
print('error-information above and fix the problem. Alternatively you can')
print('choose to install the pure-python fallback, but this will incur')
print('a *massive* performance hit and will not be suitable for embedded')
print('systems, big filters or large datasets.')
print('='*74)
# Get user confirmation
print('\nDo you wish to install the pure python fallback (yes/no)?')
process=False
while not process:
yes = {'yes','y', 'ye', ''}
no = {'no','n'}
choice = input().lower()
if choice in yes:
process=True
elif choice in no:
break
else:
print('Please respond with "yes" or "no"')
# Process if user wants to
if process:
copyfile('src/rtfir_fallback.py','rtfir.py')
setup(
name='rtfir',
version='1.1.3',
py_modules=['rtfir'],
author='Vegard Fiksdal',
author_email='[email protected]',
description='Realtime FIR filteters',
url='https://github.com/vfiksdal/rtfir'
)
else:
exit(1)