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

Conversation

dliappis
Copy link
Contributor

This commit fixes two issues. Firstly, let ./rally start when
executed for the first time with self update disabled (e.g. from a non
master branch in a fork) by ensuring the esrally binary has been
installed with setuptools.

Secondly, fix virtualenv detection when pyenv is in use. On some
configurations when pyenv is present, creating a Python3 virtualenv
uses pyvenv instead of Python3's own virtualenv[1] which fails the
current check for a virtualenv in the run.sh script.

[1] https://legacy.python.org/dev/peps/pep-0405/

Closes #447
Closes #448

This commit fixes two issues. Firstly, let `./rally` start when
executed for the first time with self update disabled (e.g. from a non
master branch in a fork) by ensuring the `esrally` binary has been
installed with setuptools.

Secondly, fix virtualenv detection when pyenv is in use. On some
configurations when pyenv is present, creating a Python3 virtualenv
uses pyvenv instead of Python3's own virtualenv[1] which fails the
current check for a virtualenv in the `run.sh` script.

[1] https://legacy.python.org/dev/peps/pep-0405/

Closes elastic#447
Closes elastic#448
@dliappis dliappis added this to the 0.10.0 milestone Mar 27, 2018
@dliappis dliappis added bug Something's wrong :Config Config file format changes, new properties, ... labels Mar 27, 2018
Copy link
Member

@danielmitterdorfer danielmitterdorfer left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I left a few suggestions otherwise LGTM.

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.

run.sh Outdated
# 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://legacy.python.org/dev/peps/pep-0405/
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason why you linked to the legacy site instead of https://www.python.org/dev/peps/pep-0405/?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will address

run.sh Outdated
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://legacy.python.org/dev/peps/pep-0405/
if python3 -c 'import sys; sys.exit(0) if ".pyenv" in sys.base_prefix else exit(0) if hasattr(sys,"real_path") else exit(1)' >/dev/null 2>&1
Copy link
Member

Choose a reason for hiding this comment

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

I think the following would be a bit simpler?

import sys; exit(0) if ".pyenv" in sys.base_prefix or hasattr(sys,"real_path") else exit(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.

Changing the logic entirely here as per our discussion.

@dliappis dliappis merged commit 9599b24 into elastic:master Apr 3, 2018
@dliappis dliappis deleted the fix-venv-detection-with-pyenv branch April 3, 2018 11:52
danielmitterdorfer added a commit that referenced this pull request Apr 3, 2018
With this commit we use the syntax `function X` instead of
`function X()` which is more compatible and also works with older bash
versions (such as the one on MacOS).

See also the [GNU bash docs on shell
functions](https://www.gnu.org/software/bash/manual/bash.html#Shell-Functions).

Relates #449
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something's wrong :Config Config file format changes, new properties, ...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix pyvenv detection when executing Rally from source Allow first Rally run from non master branch
2 participants