Skip to content

Commit

Permalink
Merge pull request #16665 from mppf/start-test-missing-venv
Browse files Browse the repository at this point in the history
Improve error message for start_test with no venv

Follow-up to PRs #16644 and #16560.

Improve error message for `start_test` with no venv or for a venv that is
built without testing support (say, if one runs `make clobber && make
docs` and then tries to use `start_test`).

Additionally recent changes had broken workflows using
`CHPL_TEST_VENV_DIR=none` / `CHPL_TEST_VENV_DIR=<dir> `.

This PR improves the situation by adding a script
`util/test/run-in-test-venv.bash` that is run from `paratest.server` and
from the `start_test`, `sub_test`, and `genGraphs` wrappers. The new
script includes the logic previously present in
`util/test/activate_chpl_test_venv.py` to work with
`CHPL_TEST_VENV_DIR=none` / `CHPL_TEST_VENV_DIR=<dir> `.

Reviewed by @ronawho - thanks!

- [x] verified expected error from `start_test`
- [x] verified expected error from `paratest.server`
  • Loading branch information
mppf committed Nov 5, 2020
2 parents 04730b9 + 97b0636 commit 3f87db2
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Expand Up @@ -59,7 +59,7 @@ jobs:
- name: check annotations
run: |
make test-venv
CHPL_HOME=$PWD ./util/config/run-in-venv.bash ./util/test/check_annotations.py
CHPL_HOME=$PWD ./util/test/run-in-test-venv.bash ./util/test/check_annotations.py
bad_rt_calls:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion doc/rst/developer/bestPractices/TestAnnotationsLocally.rst
Expand Up @@ -12,4 +12,4 @@ resolve this by installing it yourself with ``python3 -m pip install
PyYAML`` or by using the version bundled with the testing system::

cd $CHPL_HOME && make test-venv
$CHPL_HOME/util/config/run-in-venv.bash $CHPL_HOME/util/test/check_annotations.py
$CHPL_HOME/util/test/run-in-test-venv.bash $CHPL_HOME/util/test/check_annotations.py
2 changes: 2 additions & 0 deletions third-party/chpl-venv/Makefile.include
Expand Up @@ -32,6 +32,8 @@ CHPL_VENV_VIRTUALENV_SUBDIR=$(CHPL_VENV_INSTALL_SUBDIR)/$(CHPL_VENV_VIRTUALENV_N
CHPL_VENV_VIRTUALENV_DIR=$(CHPL_VENV_DIR)/$(CHPL_VENV_VIRTUALENV_SUBDIR)
CHPL_VENV_VIRTUALENV_BIN=$(CHPL_VENV_VIRTUALENV_DIR)/bin
CHPL_VENV_SPHINX_BUILD=$(CHPL_VENV_VIRTUALENV_BIN)/sphinx-build

# note - run-in-test-venv.bash also uses this path
CHPL_VENV_TEST_REQS=$(CHPL_VENV_VIRTUALENV_DIR)/chpl-test-reqs
CHPL_VENV_C2CHAPEL_REQS=$(CHPL_VENV_VIRTUALENV_DIR)/c2chapel-reqs
CHPL_VENV_CHPLSPELL_REQS=$(CHPL_VENV_VIRTUALENV_DIR)/chpl-chplspell-reqs
Expand Down
5 changes: 5 additions & 0 deletions util/config/run-in-venv.bash
Expand Up @@ -15,6 +15,11 @@ if [ ! -d "$venv_path" ]; then
exit 1
fi

if [ ! -f "$venv_path/bin/activate" ]; then
echo "Activation file $venv_path/bin/activate is missing" 1>&2
exit 1
fi

source "$venv_path/bin/activate"

exec "$1" "${@:2}"
2 changes: 1 addition & 1 deletion util/start_test
Expand Up @@ -3,4 +3,4 @@
# get the chpl home directory
FIND_CHPL_HOME=$(cd $(dirname $0) ; cd ..; pwd)

$FIND_CHPL_HOME/util/config/run-in-venv.bash $FIND_CHPL_HOME/util/test/start_test.py "$@"
$FIND_CHPL_HOME/util/test/run-in-test-venv.bash $FIND_CHPL_HOME/util/test/start_test.py "$@"
20 changes: 13 additions & 7 deletions util/test/genGraphs
Expand Up @@ -3,12 +3,18 @@
# get the chpl home directory
FIND_CHPL_HOME=$(cd $(dirname $0) ; cd ..; cd ..; pwd)

python=$($FIND_CHPL_HOME/util/config/find-python.sh)
venv_path=$("$python" "$FIND_CHPL_HOME/util/chplenv/chpl_home_utils.py" --venv)
# Test to see if the test venv is working
# If so, run genGraphs.py in it
# Otherwise, run genGraphs.py outside of the venv.
# : is just a no-op in sh
if $FIND_CHPL_HOME/util/test/run-in-test-venv.bash \
/bin/sh -c : > /dev/null 2>&1
then

# activate the venv if it exists but also proceed if it does not
if [ -d "$venv_path" ]; then
. "$venv_path/bin/activate"
fi
$FIND_CHPL_HOME/util/test/run-in-test-venv.bash \
$FIND_CHPL_HOME/util/test/genGraphs.py "$@"

else

$python $FIND_CHPL_HOME/util/test/genGraphs.py "$@"
$FIND_CHPL_HOME/util/test/genGraphs.py "$@"
fi
2 changes: 1 addition & 1 deletion util/test/paratest.server
Expand Up @@ -36,7 +36,7 @@ $synchdir = "$logdir/.synch"; # where to store temporary metadata
$rem_exe = "ssh -x"; # disable X
$pwd = `pwd`; chomp $pwd;
$client_script = "$pwd/../util/test/paratest.client";
$venv_check = "$pwd/../util/config/run-in-venv.bash /bin/sh -c echo OK";
$venv_check = "$pwd/../util/test/run-in-test-venv.bash /bin/sh -c echo OK";
$summary_len = 2;
$sleep_time = 1; # polling time (sec) to distribute work
$futures_mode = 0;
Expand Down
46 changes: 46 additions & 0 deletions util/test/run-in-test-venv.bash
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
# Active the virtual environment and run the command supplied
# usage: ./run-in-test-venv prog [args]

if [ -z "$CHPL_HOME" ]; then
# compute the chpl home directory
export CHPL_HOME=$(cd $(dirname $0) ; cd ..; cd ..; pwd)
fi

python=$($CHPL_HOME/util/config/find-python.sh)
venv_dir=$("$python" "$CHPL_HOME/util/chplenv/chpl_home_utils.py" --test-venv)
def_venv_dir=$("$python" "$CHPL_HOME/util/chplenv/chpl_home_utils.py" --venv)

if [ "$venv_dir" = "none" ]
then
echo "Skipping virtualenv activation because CHPL_TEST_VENV_DIR=$venv_dir."\
"test-venv requirements must be available."

else
if [ "$venv_dir" != "$def_venv_dir" ]
then
echo "Using custom virtualenv because CHPL_TEST_VENV_DIR=$venv_dir."\
"test-venv requirements must be available"

elif [ ! -f "$venv_dir/chpl-test-reqs" ]
then
make=$("$python" "$CHPL_HOME/util/chplenv/chpl_make.py")
echo "Chapel test virtualenv not available."\
"Run a top-level $make test-venv" 1>&2
exit 1

fi

if [ ! -f "$venv_dir/bin/activate" ]
then
echo "Activation file $venv_dir/bin/activate is missing" 1>&2
exit 1

fi

source "$venv_dir/bin/activate"

fi

# now run the command in the (possibly) activated venv
exec "$1" "${@:2}"
2 changes: 1 addition & 1 deletion util/test/sub_test
Expand Up @@ -3,4 +3,4 @@
# get the chpl home directory
FIND_CHPL_HOME=$(cd $(dirname $0) ; cd ..; cd ..; pwd)

$FIND_CHPL_HOME/util/config/run-in-venv.bash $FIND_CHPL_HOME/util/test/sub_test.py "$@"
$FIND_CHPL_HOME/util/test/run-in-test-venv.bash $FIND_CHPL_HOME/util/test/sub_test.py "$@"

0 comments on commit 3f87db2

Please sign in to comment.