forked from the-aerospace-corporation/brainblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.py
More file actions
221 lines (174 loc) · 5.89 KB
/
Copy pathhelper.py
File metadata and controls
221 lines (174 loc) · 5.89 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# ==============================================================================
# install.py
# ==============================================================================
import argparse
import os
import platform
import shutil
import subprocess
import struct
import sys
from pathlib import Path
def is_python_64bit():
return (struct.calcsize('P') == 8)
def rm_r(path):
if not os.path.exists(path):
return
if os.path.isfile(path) or os.path.islink(path):
os.unlink(path)
else:
shutil.rmtree(path)
# ==============================================================================
# Install
#
# Installs Python BrainBlocks to the environment
# ==============================================================================
def install():
# Uninstall Python BrainBlocks if it already exists
uninstall()
# Clean
clean()
# Create wheel package
build()
# Install Python BrainBlocks
print('=' * 80)
print('Install Wheel Package')
print('=' * 80, flush=True)
shutil.rmtree('brainblocks.egg-info', ignore_errors=True)
wheel_path = next(Path("dist").glob("*.whl"))
subprocess.check_call(
[sys.executable, "-m", "pip", "install", str(wheel_path)])
# Clean
clean()
# ==============================================================================
# Build
#
# Builds Python wheel package
# ==============================================================================
def build():
# Create wheel package
print('=' * 80)
print('Build Python Packages')
print('=' * 80, flush=True)
subprocess.check_call([sys.executable, "-m", "build"])
# ==============================================================================
# Uninstall
#
# Uninstalls Python BrainBlocks from environment
# ==============================================================================
def uninstall():
# Uninstall Python BrainBlocks if it already exists
print('=' * 80)
print('Uninstall Any Existing BrainBlocks')
print('=' * 80, flush=True)
result = subprocess.check_output([sys.executable, "-m", "pip", "list"])
if "brainblocks" in str(result):
subprocess.check_call(
[sys.executable, '-m', 'pip', 'uninstall', 'brainblocks', '-y'])
# ==============================================================================
# Build C++ Tests
#
# Compiles C++ BrainBlocks tests
# ==============================================================================
def cpptests():
# Clear previous build
for directory in ['build', 'dist']:
if os.path.exists(directory):
shutil.rmtree(directory)
os.mkdir(directory)
# Navigate to build directory
os.chdir('build')
# Get system name
uname_obj = platform.uname()
# Get system type
if is_python_64bit():
ARCH='x64'
else:
ARCH='x32'
# Generating BrainBlocks build system
print('=' * 80)
print('Generating BrainBlocks build system')
print('=' * 80, flush=True)
if uname_obj.system == 'Windows':
cmd = ['cmake', '-DCMAKE_GENERATOR_PLATFORM=%s' % ARCH,
'-DBRAINBLOCKS_TESTS=true', '..']
else:
cmd = ['cmake', '-DBRAINBLOCKS_TESTS=true', '..']
if subprocess.call(cmd) != 0:
print('ERROR while cmake configure')
sys.exit(-1)
# Building BrainBlocks
print('=' * 80)
print('Building BrainBlocks')
print('=' * 80, flush=True)
cmd = ['cmake', '--build', '.', '--config', 'Release']
if subprocess.call(cmd) != 0:
print('ERROR while cmake build')
sys.exit(-1)
os.chdir('..')
# ==============================================================================
# Clean
#
# Remove all known artifacts from CMake and setuptools build processes
# ==============================================================================
def clean():
print('=' * 80)
print('Clean Previous Builds')
print('=' * 80, flush=True)
directories = [
'cmake_install.cmake',
'brainblocks.egg-info',
'CMakeCache.txt',
'Makefile',
'CMakeFiles',
'bin',
'build',
'dist',
'.pytest_cache']
for directory in directories:
rm_r(directory)
for wildcard in ['*.a', '*.so', '*.lib', '*.dll', '*.egg-info']:
for path in Path('.').rglob(wildcard):
rm_r(path.name)
# ==============================================================================
# Tests
#
# Run Python unit tests
# ==============================================================================
def test():
print('=' * 80)
print('Run Python Tests')
print('=' * 80, flush=True)
subprocess.check_call([sys.executable, "-m", "pytest"])
# ==============================================================================
# Main
# ==============================================================================
if __name__ == '__main__':
# Handle argument parser
parser = argparse.ArgumentParser()
parser.add_argument('--install', action='store_true',
help='Installs Python BrainBlocks')
parser.add_argument('--uninstall', action='store_true',
help='Uninstalls Python BrainBlocks')
parser.add_argument('--build', action='store_true',
help='Build Python Packages')
parser.add_argument('--clean', action='store_true',
help='Cleans up project directory')
parser.add_argument('--test', action='store_true',
help='Run Python Unit Tests')
parser.add_argument('--cpptests', action='store_true',
help='Compiles C++ unit tests')
args = parser.parse_args()
# Handle functions
if args.install:
install()
if args.uninstall:
uninstall()
if args.build:
build()
if args.clean:
clean()
if args.test:
test()
if args.cpptests:
cpptests()