Created
October 15, 2019 15:18
-
-
Save ztolley/9b631e003699c46633a3c4caaffc5743 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
realpath() { | |
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" | |
} | |
layout_python-venv() { | |
local python=${1:-python3} | |
[[ $# -gt 0 ]] && shift | |
unset PYTHONHOME | |
if [[ -n $VIRTUAL_ENV ]]; then | |
VIRTUAL_ENV=$(realpath "${VIRTUAL_ENV}") | |
else | |
local python_version | |
python_version=$("$python" -c "import platform; print(platform.python_version())") | |
if [[ -z $python_version ]]; then | |
log_error "Could not detect Python version" | |
return 1 | |
fi | |
VIRTUAL_ENV=$PWD/venv | |
fi | |
export VIRTUAL_ENV | |
if [[ ! -d $VIRTUAL_ENV ]]; then | |
log_status "no venv found; creating $VIRTUAL_ENV" | |
"$python" -m venv "$VIRTUAL_ENV" | |
fi | |
PATH_add "$VIRTUAL_ENV/bin" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment