Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix venv detection with venv and Rally execution on non master #449

Merged
merged 2 commits into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rally
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ cd "${RALLY_SRC_HOME}" >/dev/null 2>&1
__RALLY_INTERNAL_BINARY_NAME="esrally"
__RALLY_INTERNAL_HUMAN_NAME="Rally"

source run.sh
source run.sh

42 changes: 29 additions & 13 deletions run.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,33 @@
readonly BINARY_NAME="${__RALLY_INTERNAL_BINARY_NAME}"
readonly HUMAN_NAME="${__RALLY_INTERNAL_HUMAN_NAME}"

function install_esrally_with_setuptools() {
# Check if optional parameter with Rally binary path, points to an existing executable file.
if [[ -n $1 ]]; then
if [[ -f $1 && -x $1 ]]; then return; fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to enclose the parameter in double quotes to avoid issues with spaces in path names? (i.e. "${1}"?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double quotes are needed only for the backwards compatible [. Double square braces do not require double quoting for the variables.

fi

if [[ ${IN_VIRTUALENV} == 0 ]]; then
python3 setup.py -q develop --user
else
python3 setup.py -q develop
fi
}

# Attempt to update Rally itself by default but allow user to skip it.
SELF_UPDATE=YES
# Assume that the "main remote" is called "origin"
REMOTE="origin"

# While we could also check via the presence of `VIRTUAL_ENV` this is a bit more reliable.
python3 -c 'import sys; print(sys.real_prefix)' >/dev/null 2>&1 && IN_VIRTUALENV=1 || IN_VIRTUALENV=0
# Check for both pyvenv and normal venv environments
# https://www.python.org/dev/peps/pep-0405/
if python3 -c 'import os, sys; sys.exit(0) if "VIRTUAL_ENV" in os.environ else sys.exit(1)' >/dev/null 2>&1
then
IN_VIRTUALENV=1
else
IN_VIRTUALENV=0
fi

# Check for parameters that are intended for this script. Note that they only work if they're specified at the beginning (due to how
# the shell builtin `shift` works. We could make it work for arbitrary positions but that's not worth the complexity for such an
Expand Down Expand Up @@ -45,7 +65,7 @@ case ${i} in
esac
done

if [ ${SELF_UPDATE} == YES ]
if [[ $SELF_UPDATE == YES ]]
then
# see http://unix.stackexchange.com/a/155077
if output=$(git status --porcelain) && [ -z "$output" ] && on_master=$(git rev-parse --abbrev-ref HEAD) && [ "$on_master" == "master" ]
Expand All @@ -56,17 +76,11 @@ then
git fetch ${REMOTE} --quiet >/dev/null 2>&1
exit_code=$?
set -e
if [ ${exit_code} == 0 ]
if [[ $exit_code == 0 ]]
then
echo "Auto-updating Rally from ${REMOTE}"
git rebase ${REMOTE}/master --quiet
# if we're running in a virtualenv then the --user prefix is not defined (and makes no sense)
if [ ${IN_VIRTUALENV} == 0 ]
then
python3 setup.py -q develop --user
else
python3 setup.py -q develop
fi
install_esrally_with_setuptools
#else
# offline - skipping update
fi
Expand All @@ -85,16 +99,18 @@ export THESPLOG_FILE_MAXSIZE=${THESPLOG_FILE_MAXSIZE:-204800}

# Provide a consistent binary name to the user and hide the fact that we call another binary under the hood.
export RALLY_ALTERNATIVE_BINARY_NAME=$(basename "$0")
if [ ${IN_VIRTUALENV} == 0 ]
if [[ $IN_VIRTUALENV == 0 ]]
then
RALLY_ROOT=$(python3 -c "import site; print(site.USER_BASE)")
RALLY_BIN=${RALLY_ROOT}/bin/${BINARY_NAME}
if [ -x "$RALLY_BIN" ]
then
install_esrally_with_setuptools "${RALLY_BIN}"
if [[ -x $RALLY_BIN ]]; then
${RALLY_BIN} "$@"
else
echo "Cannot execute ${HUMAN_NAME} in ${RALLY_BIN}."
fi
else
install_esrally_with_setuptools "${BINARY_NAME}"

${BINARY_NAME} "$@"
fi