Skip to content

Commit d6fd180

Browse files
authored
Merge pull request #3610 from boegel/eb_enhancements
enhance 'eb' command to ensure that easybuild.main can be imported before settling on python* command to use
2 parents ee06900 + b9af38c commit d6fd180

File tree

2 files changed

+109
-3
lines changed

2 files changed

+109
-3
lines changed

.github/workflows/eb_command.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# documentation: https://help.github.com/en/articles/workflow-syntax-for-github-actions
2+
name: Tests for the 'eb' command
3+
on: [push, pull_request]
4+
jobs:
5+
test-eb:
6+
runs-on: ubuntu-18.04
7+
strategy:
8+
matrix:
9+
python: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
10+
fail-fast: false
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: set up Python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: ${{matrix.python}}
18+
architecture: x64
19+
20+
- name: install OS & Python packages
21+
run: |
22+
# check Python version
23+
python -V
24+
# update to latest pip, check version
25+
pip install --upgrade pip
26+
pip --version
27+
# install packages required for modules tool
28+
sudo apt-get install lua5.2 liblua5.2-dev lua-filesystem lua-posix tcl tcl-dev
29+
# fix for lua-posix packaging issue, see https://bugs.launchpad.net/ubuntu/+source/lua-posix/+bug/1752082
30+
# needed for Ubuntu 18.04, but not for Ubuntu 20.04, so skipping symlinking if posix.so already exists
31+
if [ ! -e /usr/lib/x86_64-linux-gnu/lua/5.2/posix.so ] ; then
32+
sudo ln -s /usr/lib/x86_64-linux-gnu/lua/5.2/posix_c.so /usr/lib/x86_64-linux-gnu/lua/5.2/posix.so
33+
fi
34+
35+
- name: install modules tool
36+
run: |
37+
# avoid downloading modules tool sources into easybuild-framework dir
38+
cd $HOME
39+
export INSTALL_DEP=$GITHUB_WORKSPACE/easybuild/scripts/install_eb_dep.sh
40+
# install Lmod
41+
source $INSTALL_DEP Lmod-8.4.26 $HOME
42+
# changes in environment are not passed to other steps, so need to create files...
43+
echo $MOD_INIT > mod_init
44+
echo $PATH > path
45+
if [ ! -z $MODULESHOME ]; then echo $MODULESHOME > moduleshome; fi
46+
47+
- name: install EasyBuild framework
48+
run: |
49+
# install from source distribution tarball, to test release as published on PyPI
50+
python setup.py sdist
51+
ls dist
52+
export PREFIX=/tmp/$USER/$GITHUB_SHA
53+
pip install --prefix $PREFIX dist/easybuild-framework*tar.gz
54+
55+
- name: run tests for 'eb' command
56+
env:
57+
EB_VERBOSE: 1
58+
run: |
59+
# run tests *outside* of checked out easybuild-framework directory,
60+
# to ensure we're testing installed version (see previous step)
61+
cd $HOME
62+
# initialize environment for modules tool
63+
if [ -f $HOME/moduleshome ]; then export MODULESHOME=$(cat $HOME/moduleshome); fi
64+
source $(cat $HOME/mod_init); type module
65+
# make sure 'eb' is available via $PATH, and that $PYTHONPATH is set (some tests expect that);
66+
# also pick up changes to $PATH set by sourcing $MOD_INIT
67+
export PREFIX=/tmp/$USER/$GITHUB_SHA
68+
export PATH=$PREFIX/bin:$(cat $HOME/path)
69+
export PYTHONPATH=$PREFIX/lib/python${{matrix.python}}/site-packages:$PYTHONPATH
70+
# run --version, capture (verbose) output
71+
eb --version | tee eb_version.out 2>&1
72+
# determine active Python version
73+
pymajver=$(python -c 'import sys; print(sys.version_info[0])')
74+
pymajminver=$(python -c 'import sys; print(".".join(str(x) for x in sys.version_info[:2]))')
75+
# check patterns in verbose output
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
77+
echo "Looking for pattern \"${pattern}\" in eb_version.out..."
78+
grep "$pattern" eb_version.out
79+
done
80+
# also check when specifying Python command via $EB_PYTHON
81+
for eb_python in "python${pymajver}" "python${pymajminver}"; do
82+
export EB_PYTHON="${eb_python}"
83+
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" "^>> '${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
85+
echo "Looking for pattern \"${pattern}\" in eb_version.out..."
86+
grep "$pattern" eb_version.out
87+
done
88+
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)