Skip to content

Commit b9af38c

Browse files
committed
enhance 'eb' command to ensure that easybuild.main can be imported before settling on python* command to use
1 parent 724b8a9 commit b9af38c

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

.github/workflows/eb_command.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ jobs:
7373
pymajver=$(python -c 'import sys; print(sys.version_info[0])')
7474
pymajminver=$(python -c 'import sys; print(".".join(str(x) for x in sys.version_info[:2]))')
7575
# check patterns in verbose output
76-
for pattern in "^>> Considering .python.\.\.\." "^>> .python. version: ${pymajminver}\.[0-9]\+, which matches Python ${pymajver} version requirement" "^>> Selected Python command: python \(.*/bin/python\)" "^This is EasyBuild 4\.[0-9.]\+"; do
76+
for pattern in "^>> Considering .python.\.\.\." "^>> .python. version: ${pymajminver}\.[0-9]\+, which matches Python ${pymajver} version requirement" "^>> 'python' is able to import 'easybuild.main', so retaining it" "^>> Selected Python command: python \(.*/bin/python\)" "^This is EasyBuild 4\.[0-9.]\+"; do
7777
echo "Looking for pattern \"${pattern}\" in eb_version.out..."
7878
grep "$pattern" eb_version.out
7979
done
8080
# also check when specifying Python command via $EB_PYTHON
8181
for eb_python in "python${pymajver}" "python${pymajminver}"; do
8282
export EB_PYTHON="${eb_python}"
8383
eb --version | tee eb_version.out 2>&1
84-
for pattern in "^>> Considering .${eb_python}.\.\.\." "^>> .${eb_python}. version: ${pymajminver}\.[0-9]\+, which matches Python ${pymajver} version requirement" "^>> Selected Python command: ${eb_python} \(.*/bin/${eb_python}\)" "^This is EasyBuild 4\.[0-9.]\+"; do
84+
for pattern in "^>> Considering .${eb_python}.\.\.\." "^>> .${eb_python}. version: ${pymajminver}\.[0-9]\+, which matches Python ${pymajver} version requirement" "^>> '${eb_python}' is able to import 'easybuild.main', so retaining it" "^>> Selected Python command: ${eb_python} \(.*/bin/${eb_python}\)" "^This is EasyBuild 4\.[0-9.]\+"; do
8585
echo "Looking for pattern \"${pattern}\" in eb_version.out..."
8686
grep "$pattern" eb_version.out
8787
done

eb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
REQ_MIN_PY2VER=6
3838
REQ_MIN_PY3VER=5
3939

40+
EASYBUILD_MAIN='easybuild.main'
4041

4142
function verbose() {
4243
if [ ! -z ${EB_VERBOSE} ]; then echo ">> $1"; fi
@@ -52,6 +53,8 @@ for python_cmd in ${EB_PYTHON} ${EB_INSTALLPYTHON} 'python' 'python3' 'python2';
5253

5354
verbose "Considering '$python_cmd'..."
5455

56+
# check whether python* command being considered is available
57+
# (using 'command -v', since 'which' implies an extra dependency)
5558
command -v $python_cmd &> /dev/null
5659
if [ $? -eq 0 ]; then
5760

@@ -63,10 +66,25 @@ for python_cmd in ${EB_PYTHON} ${EB_INSTALLPYTHON} 'python' 'python3' 'python2';
6366
if [ $pyver_maj -eq 2 ] && [ $pyver_min -ge $REQ_MIN_PY2VER ]; then
6467
verbose "'$python_cmd' version: $pyver, which matches Python 2 version requirement (>= 2.$REQ_MIN_PY2VER)"
6568
PYTHON=$python_cmd
66-
break
6769
elif [ $pyver_maj -eq 3 ] && [ $pyver_min -ge $REQ_MIN_PY3VER ]; then
6870
verbose "'$python_cmd' version: $pyver, which matches Python 3 version requirement (>= 3.$REQ_MIN_PY3VER)"
6971
PYTHON=$python_cmd
72+
fi
73+
74+
if [ ! -z $PYTHON ]; then
75+
# check whether easybuild.main is available for selected python command
76+
$PYTHON -c "import $EASYBUILD_MAIN" 2> /dev/null
77+
if [ $? -eq 0 ]; then
78+
verbose "'$python_cmd' is able to import '$EASYBUILD_MAIN', so retaining it"
79+
else
80+
# if easybuild.main is not available, don't use this python command, keep searching...
81+
verbose "'$python_cmd' is NOT able to import '$EASYBUILD_MAIN', so NOT retaining it"
82+
unset PYTHON
83+
fi
84+
fi
85+
86+
# break out of for loop if we've found a valid python command
87+
if [ ! -z $PYTHON ]; then
7088
break
7189
fi
7290
else
@@ -97,5 +115,5 @@ fi
97115

98116
export EB_SCRIPT_PATH=$0
99117

100-
verbose "$PYTHON -m easybuild.main `echo \"$@\"`"
101-
$PYTHON -m easybuild.main "$@"
118+
verbose "$PYTHON -m $EASYBUILD_MAIN `echo \"$@\"`"
119+
$PYTHON -m $EASYBUILD_MAIN "$@"

0 commit comments

Comments
 (0)