@@ -4,7 +4,8 @@ unset u_c
4
4
unset u_cg
5
5
6
6
MFC_PYTHON_MIN_MAJOR=3
7
- MFC_PYTHON_MIN_MINOR=9
7
+ MFC_PYTHON_MIN_MINOR=8
8
+ MFC_PYTHON_MIN_STR=" $MFC_PYTHON_MIN_MAJOR .$MFC_PYTHON_MIN_MINOR "
8
9
9
10
# Check whether this script was called from MFC's root directory.
10
11
if [ ! -f " $( pwd) /toolchain/mfc.py" ]; then
@@ -81,14 +82,14 @@ if [ "$1" == 'load' ]; then
81
82
}
82
83
83
84
COMPUTER=" $( __extract " $u_c " ) "
84
-
85
+
85
86
if [[ -z " $COMPUTER " ]]; then
86
87
error " Computer $M$u_cg$CR not recognized."
87
88
return
88
89
fi
89
-
90
+
90
91
MODULES=($( __extract " $u_c -$cg " ) $( __combine $( __extract " $u_c -all" ) ) )
91
-
92
+
92
93
log " Loading modules for $M$COMPUTER$CR on $M$CG$CR " ' s:'
93
94
94
95
# Reset modules to default system configuration
@@ -124,7 +125,7 @@ if [ "$1" == 'load' ]; then
124
125
if [ " $delta " -ge " 0" ]; then
125
126
printf " %0.s " $( seq 0 $delta )
126
127
fi
127
-
128
+
128
129
# Load the module
129
130
module load " $module_name " > /dev/null 2>&1
130
131
@@ -190,7 +191,7 @@ elif [ "$1" == "docker" ]; then
190
191
dockerintopts=' --interactive --tty'
191
192
fi
192
193
193
- __docker_run () {
194
+ __docker_run () {
194
195
docker run $dockerintopts --rm --workdir /home/me/MFC \
195
196
--mount type=bind,source=" $( pwd) " ,target=/home/me/MFC \
196
197
sbryngelson/mfc:latest $@
@@ -330,11 +331,27 @@ if [ "$bShouldInstallCMake" = true ]; then
330
331
fi
331
332
332
333
334
+ is_python_compatible () {
335
+ if ! ${1:- python3} -c " import sys; exit(int(not (sys.version_info[0]==$MFC_PYTHON_MIN_MAJOR and sys.version_info[1] >= $MFC_PYTHON_MIN_MINOR )))" ; then
336
+ return 1
337
+ fi
338
+
339
+ return 0
340
+ }
341
+
342
+
343
+ assert_python_compatible () {
344
+ if ! is_python_compatible $1 ; then
345
+ error " $MAGENTA $( ${1:- python3} --version) $COLOR_RESET (${1:- python3} ) is out of date. Required >= $MAGENTA$MFC_PYTHON_MIN_STR$COLOR_RESET ."
346
+
347
+ exit 1
348
+ fi
349
+ }
350
+
351
+
333
352
if [ -f " $( pwd) /build/venv/bin/activate" ]; then
334
- # Check Python is still working within the VENV
335
- if ! $( pwd) /build/venv/bin/python3 --version > /dev/null 2>&1 ; then
336
- # If not, delete it and install it again
337
- warn " $MAGENTA " " Python$COLOR_RESET is no longer working inside the Virtualenv."
353
+ if ! is_python_compatible " $( pwd) /build/venv/bin/python3" ; then
354
+ warn " $MAGENTA " " Python$COLOR_RESET is outdated inside the Virtualenv."
338
355
warn " Deleting the Virtualenv and starting from scratch..."
339
356
340
357
rm -r " $( pwd) /build/venv"
@@ -349,12 +366,7 @@ if ! command -v pip3 > /dev/null 2>&1 && [ ! -f "$(pwd)/build/venv/bin/activate"
349
366
exit 1
350
367
fi
351
368
352
- # CHeck Python's version for compatibility
353
- if ! python3 -c " import sys; exit(int(not (sys.version_info[0]==$MFC_PYTHON_MIN_MAJOR and sys.version_info[1] >= $MFC_PYTHON_MIN_MINOR )))" ; then
354
- error " $( python3 --version) is incompatible.$MAGENTA Python$COLOR_RESET v$MFC_PYTHON_MIN_MAJOR .$MFC_PYTHON_MIN_MINOR or higher is required."
355
-
356
- exit 1
357
- fi
369
+ assert_python_compatible
358
370
359
371
get_pip_url=" https://bootstrap.pypa.io/pip/get-pip.py"
360
372
381
393
382
394
# Create a Python virtualenv if it hasn't already been created
383
395
if [ ! -f " $( pwd) /build/venv/bin/activate" ]; then
396
+ assert_python_compatible
397
+
384
398
if ! python3 -m venv " $( pwd) /build/venv" ; then
385
399
error " Failed to create a$MAGENTA Python$COLOR_RESET virtual environment. Delete the build/venv folder and try again."
386
400
420
434
421
435
# Activate the Python venv
422
436
source " $( pwd) /build/venv/bin/activate"
423
- ok " (venv) Entered the$MAGENTA Python $COLOR_RESET virtual environment."
437
+ ok " (venv) Entered the $MAGENTA $( python3 --version ) $COLOR_RESET virtual environment (>= $MAGENTA$MFC_PYTHON_MIN_STR$COLOR_RESET ) ."
424
438
425
439
426
440
# Install Python dependencies if, either:
@@ -456,5 +470,5 @@ log "(venv) Exiting the$MAGENTA Python$COLOR_RESET virtual environment."
456
470
deactivate
457
471
458
472
459
- # Exit proper exit code
473
+ # Exit with proper exit code
460
474
exit $code
0 commit comments