-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.py
489 lines (401 loc) · 18.4 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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
#!/usr/bin/python
####################################################################################################
# Copyright (c) 2016 - 2020, EPFL / Blue Brain Project
# Author(s): Marwan Abdellah <[email protected]>
#
# This file is part of VessMorphoVis <https://github.com/BlueBrain/VessMorphoVis>
#
# This program is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, version 3 of the License.
#
# This Blender-based tool is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <http://www.gnu.org/licenses/>.
####################################################################################################
# System imports
import os
import sys
import subprocess
import argparse
import shutil
import shlex
####################################################################################################
# @parse_command_line_arguments
####################################################################################################
def parse_command_line_arguments(arguments=None):
"""Parses the input arguments.
:param arguments:
Command line arguments.
:return:
Arguments list.
"""
# add all the options
description = 'Installing Neuro/Vess-MorphoVis from scratch. Simple, easy and awesome! ' \
'This script is valid for *nix-based operating systems including macOSX and ' \
'Linux distributions. For windows, you can download a zip package from the ' \
'release page. \n' \
'NOTE: git, wget or curl must be installed to run this script.'
parser = argparse.ArgumentParser(description=description)
arg_help = 'Blender version. 2.79, 2.80, or 2.81, 2.82, and 2.90, 2.93. ' \
'By default it is 2.90. It is recommended to avoid 2.79.'
parser.add_argument('--blender-version',
action='store', dest='blender_version', default='2.80', help=arg_help)
arg_help = 'Installation directory.'
parser.add_argument('--prefix',
action='store', dest='install_prefix', required=True, help=arg_help)
arg_help = 'Enable to get a detailed log, otherwise only the basic operations'
parser.add_argument('--verbose',
action='store_true', default=False, dest='verbose', help=arg_help)
# Parse the arguments
return parser.parse_args()
####################################################################################################
# @run_command
####################################################################################################
def run_command(shell_command,
verbose=False):
"""Runs a shell command.
:param shell_command:
A shell command to execute.
:param verbose:
Flag to print more massages for debugging.
"""
if verbose:
print('\t* SHELL: ' + shell_command)
subprocess.call(shell_command, shell=True)
else:
devnull = open(os.devnull, 'w')
subprocess.call(shlex.split(shell_command), stdout=devnull)
####################################################################################################
# @log_header
####################################################################################################
def log_header(msg):
"""Header.
:param msg:
Message.
"""
print('* %s' % msg)
####################################################################################################
# @log_process
####################################################################################################
def log_process(msg):
"""Process.
:param msg:
Message.
"""
print('\t* %s' % msg)
####################################################################################################
# @log_detail
####################################################################################################
def log_detail(msg):
"""Detail.
:param msg:
Message.
"""
print('\t\t* %s' % msg)
####################################################################################################
# @install_for_linux
####################################################################################################
def install_for_linux(directory, blender_version, verbose=False):
"""Install NeuroMorphoVis on Linux operating system.
:param directory:
Installation directory.
:param blender_version
The version of Blender.
:param verbose:
Verbose.
"""
# Blender url
if blender_version == '2.79':
python_version = '3.5'
package_name = 'blender-2.79-linux-glibc219-x86_64'
extension = 'tar.bz2'
elif blender_version == '2.80':
python_version = '3.7'
package_name = 'blender-2.80-linux-glibc217-x86_64'
extension = 'tar.bz2'
elif blender_version == '2.81':
python_version = '3.7'
package_name = 'blender-2.81-linux-glibc217-x86_64'
extension = 'tar.bz2'
elif blender_version == '2.82':
python_version = '3.7'
package_name = 'blender-2.82a-linux64'
extension = 'tar.xz'
elif blender_version == '2.83':
python_version = '3.7'
package_name = 'blender-2.83.9-linux64'
extension = 'tar.xz'
elif blender_version == '2.90':
python_version = '3.7'
package_name = 'blender-2.90.1-linux64'
extension = 'tar.xz'
else:
print('ERROR: Wrong Blender version [%s]' % blender_version)
exit(0)
# Blender url
server = 'https://download.blender.org/release/Blender%s/' % blender_version
blender_url = '%s/%s.%s' % (server, package_name, extension)
# wet (Download)
log_process('Downloading Blender [%s] from %s' % (blender_version, blender_url))
shell_command = 'wget -O %s/blender.%s %s' % (directory, extension, blender_url)
run_command(shell_command, verbose)
# Extract
if '.bz2' in extension:
shell_command = 'tar xjfv %s/blender.%s -C %s' % (directory, extension, directory)
else:
shell_command = 'tar xf %s/blender.%s -C %s' % (directory, extension, directory)
run_command(shell_command, verbose)
# Moving to blender
blender_directory = '%s/blender-bbp' % directory
shell_command = 'mv %s/%s %s' % (directory, package_name, blender_directory)
if os.path.exists(blender_directory):
os.rmdir(blender_directory)
run_command(shell_command, verbose)
# Clone NeuroMorphoVis into the 'addons' directory
addons_directory = '%s/blender-bbp/%s/scripts/addons/' % (directory, blender_version)
neuromorphovis_url = 'https://github.com/BlueBrain/NeuroMorphoVis.git'
shell_command = 'git clone %s %s/neuromorphovis' % (neuromorphovis_url, addons_directory)
run_command(shell_command, verbose)
# Clone VessMorphoVis into the 'addons' directory
addons_directory = '%s/blender-bbp/%s/scripts/addons/' % (directory, blender_version)
vessmorphovis_url = 'https://github.com/BlueBrain/VessMorphoVis.git'
shell_command = 'git clone %s %s/vessmorphovis' % (vessmorphovis_url, addons_directory)
run_command(shell_command, verbose)
# Installing dependencies
pip_wheels = ['numpy', 'matplotlib', 'seaborn', 'pandas', 'Pillow']
# Removing the site-packages directory
blender_python_wheels = '%s/blender-bbp/%s/python/lib/python%s/site-packages/' % \
(directory, blender_version, python_version)
shell_command = 'rm -rf %s/numpy' % blender_python_wheels
run_command(shell_command, verbose)
# Blender python
blender_python_prefix = '%s/%s/python/bin/' % (blender_directory, blender_version)
blender_python = '%s/python%sm' % (blender_python_prefix, python_version)
# Pip installation
get_pip_script_url = 'https://bootstrap.pypa.io/get-pip.py'
shell_command = 'wget -O %s/get-pip.py %s' % (blender_python_prefix, get_pip_script_url)
run_command(shell_command, verbose)
# Activate the get-pip.py script
get_pip_script = '%s/get-pip.py' % blender_python_prefix
shell_command = 'chmod +x %s' % get_pip_script
run_command(shell_command, verbose)
shell_command = '%s %s' % (blender_python, get_pip_script)
run_command(shell_command, verbose)
# Pip executable
pip_executable = '%s/pip' % blender_python_prefix
# packages
for i, wheel in enumerate(pip_wheels):
shell_command = '%s install --ignore-installed %s' % (pip_executable, wheel)
print('INSTALL: %s' % shell_command)
run_command(shell_command, verbose)
# h5py specific version
shell_command = '%s install --ignore-installed h5py==2.10.0' % pip_executable
print('INSTALL: %s' % shell_command)
run_command(shell_command, verbose)
try:
bbp_devpi = 'https://bbpteam.epfl.ch/repository/devpi/simple/'
log_detail('Installing: BBP dependencies')
shell_command = '%s install -i %s bluepy' % (pip_executable, bbp_devpi)
run_command(shell_command, verbose)
shell_command = '%s install -i %s bluepy_configfile' % (pip_executable, bbp_devpi)
run_command(shell_command, verbose)
shell_command = '%s install -i %s bluepy_snap' % (pip_executable, bbp_devpi)
run_command(shell_command, verbose)
except ImportError:
print('The BBP dependencies were not installed. Can NOT use BluePy or load circuits!')
# Remove the archive
log_process('Cleaning')
shell_command = 'rm %s/blender.%s' % (directory, extension)
run_command(shell_command, verbose)
####################################################################################################
# @install_for_mac
####################################################################################################
def install_for_mac(directory, blender_version, verbose=False):
"""Install NeuroMorphoVis on macOSX operating system.
:param directory:
Installation directory.
:param blender_version
The version of Blender.
:param verbose:
Verbose.
"""
# Server
server = 'https://download.blender.org/release/Blender%s/' % blender_version
# Blender url
if blender_version == '2.79':
python_version = '3.5'
package_name = 'blender-2.79b-macOS-10.6.dmg'
elif blender_version == '2.80':
python_version = '3.7'
package_name = 'blender-2.80rc3-macOS.dmg'
elif blender_version == '2.81':
python_version = '3.7'
package_name = 'blender-2.81-macOS.dmg'
elif blender_version == '2.82':
python_version = '3.7'
package_name = 'blender-2.82a-macOS.dmg'
elif blender_version == '2.83':
python_version = '3.7'
package_name = 'blender-2.83.1-macOS.dmg'
elif blender_version == '2.90':
python_version = '3.7'
package_name = 'blender-2.90.1-macOS.dmg'
else:
print('ERROR: Wrong Blender version [%s]' % blender_version)
exit(0)
# curl (Download)
blender_url = '%s/%s' % (server, package_name)
log_process('Downloading Blender [%s] from %s' % (blender_version, blender_url))
shell_command = 'curl %s -o %s/blender.dmg' % (blender_url, directory)
run_command(shell_command, verbose)
# Extract
log_process('Extracting Blender')
shell_command = 'hdiutil attach %s/blender.dmg' % directory
run_command(shell_command, verbose)
# Copy the Blender.app
log_process('Copying Blender')
if blender_version == '2.79':
shell_command = 'cp -r /Volumes/Blender/Blender %s/.' % directory
else:
shell_command = 'cp -r /Volumes/Blender/Blender.app %s/.' % directory
run_command(shell_command, verbose)
# Detach
log_process('Detaching DMG Image')
shell_command = 'hdiutil detach /Volumes/Blender'
run_command(shell_command, verbose)
# Clone NeuroMorphoVis into the 'addons' directory
log_process('Clone NeuroMorphoVis')
if blender_version == '2.79':
blender_app_directory = '%s/Blender/blender.app' % directory
else:
blender_app_directory = '%s/Blender.app' % directory
addons_directory = '%s/Contents/Resources/%s/scripts/addons/' % (blender_app_directory,
blender_version)
# Clone NeuroMorphoVis
neuromorphovis_url = 'https://github.com/BlueBrain/NeuroMorphoVis.git'
shell_command = 'git clone %s %s/neuromorphovis' % (neuromorphovis_url, addons_directory)
run_command(shell_command, verbose)
# Clone VessMorphoVis
vessmorphovis_url = 'https://github.com/BlueBrain/VessMorphoVis.git'
shell_command = 'git clone %s %s/vessmorphovis' % (vessmorphovis_url, addons_directory)
run_command(shell_command, verbose)
# Blender python
blender_python_prefix = '%s/Contents/Resources/%s/python/bin/' % (blender_app_directory,
blender_version)
blender_python = '%s/python%sm' % (blender_python_prefix, python_version)
# Pip installation
log_process('Installing Dependencies')
get_pip_script_url = 'https://bootstrap.pypa.io/get-pip.py'
shell_command = 'curl %s -o %s/get-pip.py' % (get_pip_script_url, blender_python_prefix)
run_command(shell_command, verbose)
# Activate the get-pip.py script
log_detail('Installing: pip')
get_pip_script = '%s/get-pip.py' % blender_python_prefix
shell_command = 'chmod +x %s' % get_pip_script
run_command(shell_command, verbose)
shell_command = '%s %s' % (blender_python, get_pip_script)
run_command(shell_command, verbose)
pip_executable = '%s/pip' % blender_python_prefix
# Removing the previous numpy installation
log_detail('Uninstalling: numpy')
blender_python_wheels = '%s/Contents/Resources/%s/python/lib/python%s/site-packages' % (
blender_app_directory, blender_version, python_version)
shell_command = 'rm -rf %s/numpy*' % blender_python_wheels
run_command(shell_command, verbose)
# Installing dependencies
pip_wheels = ['numpy', 'matplotlib', 'seaborn', 'pandas', 'Pillow']
for wheel in pip_wheels:
log_detail('Installing: %s' % wheel)
shell_command = '%s install --ignore-installed %s' % (pip_executable, wheel)
run_command(shell_command, verbose)
# h5py specific version
shell_command = '%s install --ignore-installed h5py==2.10.0' % pip_executable
print('INSTALL: %s' % shell_command)
run_command(shell_command, verbose)
try:
bbp_devpi = 'https://bbpteam.epfl.ch/repository/devpi/simple/'
log_detail('Installing: BBP dependencies')
shell_command = '%s install -i %s bluepy' % (pip_executable, bbp_devpi)
run_command(shell_command, verbose)
shell_command = '%s install -i %s bluepy_configfile' % (pip_executable, bbp_devpi)
run_command(shell_command, verbose)
shell_command = '%s install -i %s bluepy_snap' % (pip_executable, bbp_devpi)
run_command(shell_command, verbose)
except ImportError:
print('The BBP dependencies were not installed. Can NOT use BluePy or load circuits!')
# Copying the perf file to loade NMV directly
# Remove the .dmg file
log_process('Cleaning')
shell_command = 'rm %s/blender.dmg' % directory
run_command(shell_command, verbose)
####################################################################################################
# @install_neuromorphovis
####################################################################################################
def install_neuromorphovis(directory, blender_version, verbose=False):
"""Installs NeuroMorphoVis
:param directory:
Installation directory.
:param blender_version:
The version of Blender.
:param verbose:
Verbose.
"""
# Header
log_header('Installing Blender for %s' % sys.platform)
log_process('Installation Directory: %s' % directory)
# Linux
if sys.platform == "linux" or sys.platform == "linux2":
install_for_linux(directory, blender_version, verbose)
# OS X
elif sys.platform == "darwin":
install_for_mac(directory, blender_version, verbose)
# Windows
elif sys.platform == "win32":
print('This script is only valid for *nix-based operating systems. '
'For windows, you can download a zip package from the release page.')
exit(0)
else:
print('ERROR: Unrecognized operating system %s' % sys.platform)
exit(0)
####################################################################################################
# @ Run the main function if invoked from the command line.
####################################################################################################
if __name__ == "__main__":
# Parse the arguments
args = parse_command_line_arguments()
# Check that the apps required to install NMV are all there.
# check_apps()
# Create the installation directory
if not os.path.exists(args.install_prefix):
os.mkdir(args.install_prefix)
# Verify blender version
if args.blender_version == '2.79':
log_header('Blender 2.79')
elif args.blender_version == '2.80':
log_header('Blender 2.80')
elif args.blender_version == '2.81':
log_header('Blender 2.81')
elif args.blender_version == '2.82':
log_header('Blender 2.82')
elif args.blender_version == '2.83':
log_header('Blender 2.83')
elif args.blender_version == '2.90':
log_header('Blender 2.90')
else:
log_header('NeuroMorphoVis is ONLY available for Blender versions '
'2.79, 2.80, 2.81, 2.82, 2.83, 2.90. Recommended version: 2.83')
exit(0)
# Installation directory
installation_directory = '%s/bluebrain-blender-%s' % (args.install_prefix, args.blender_version)
# Verify the installation directory
if not os.path.exists(installation_directory):
os.mkdir(installation_directory)
else:
pass
shutil.rmtree(installation_directory)
os.mkdir(installation_directory)
# Download blender based on the software
install_neuromorphovis(installation_directory, args.blender_version, args.verbose)