-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
72 lines (64 loc) · 3.24 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
# This is not actually a standard distutils setup.py script.
# Here we build and install the submodules, and optionally run the self-test routines
#
# In future I might be able to turn this into a proper distutils script, but part of my issue
# is that I am not *installing* fast-light-field, I am just setting things up so it can run in situ.
# Note that, looking back at things, it looks like I should be able to figure out a better way of
# doing the setup.py distutils stuff - see documentation:
# https://docs.python.org/3.11/distutils/apiref.html#distutils.core.setup
# https://docs.python.org/3.11/distutils/apiref.html#distutils.core.Extension
# https://setuptools.pypa.io/en/latest/setuptools.html
import sys, os, datetime
if __name__ == "__main__":
args = sys.argv
if (len(args) == 1): # We test against 1 because argv[0] is the script path
print('No arguments passed - will run full setup')
# For now I do not do the init stage by default, since the submodules are not publicly accessible.
# I just need to provide people with the pre-downloaded git module.
args = ['build', 'self-test', 'benchmark']
if ('init' in args):
# Set up git submodules
for cmd in ['git submodule init', 'git submodule update']:
ret = os.system(cmd)
if (ret != 0):
print('Command "%s" failed' % cmd)
exit(ret)
if ('build' in args):
# Build custom python modules
if '--user' in args:
userFlag = '--user'
else:
userFlag = ''
for subfolder in ['light-field-integrands', 'py_light_field']:
print('Build %s' % subfolder)
ret = os.system('cd %s; python3 setup.py install %s' % (subfolder, userFlag))
if (ret != 0):
print('Failed to build \"%s\" - terminating setup process' % subfolder)
exit(ret)
if ('self-test' in args):
# Run self-tests
print('\033[1;32m=== RUNNING SELF-TESTS ===\033[0m')
print('This will take several minutes to complete')
import lfdeconv
import projector as proj
# Tests that verify fast implementations against my slow reference python implementation
testOutcomes = proj.selfTest(verbose=False)
# Tests that compare against reconstructions from Prevedel's MATLAB
for cacheFH in [[], ['cacheFH']]:
args = ['basic', 'full', 'parallel', 'parallel-threading'] + cacheFH
testOutcomes += lfdeconv.main(args)
if proj.gpuAvailable:
testOutcomes += lfdeconv.main(args, projectorClass=proj.Projector_gpuHelpers)
if testOutcomes[0] == testOutcomes[1]:
print('\033[1;32m')
else:
print('\033[1;31m')
print('== Self-tests complete (passed %d/%d) ==' % (testOutcomes[0], testOutcomes[1]))
print('\033[0m')
if ('benchmark' in args):
# Run benchmarks
# Note that we shouldn't do the import globally, before we have built all our dependencies
import benchmark
result = benchmark.RunSimpleBenchmarks()
with open('benchmarks.txt', 'a') as f:
f.write("%s: %s\n" % (datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S"), result))