Skip to content

Instantly share code, notes, and snippets.

@ztraboo

ztraboo/.bashrc Secret

Last active May 29, 2020 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ztraboo/d1e9cad3e9a9c03e75f2792922f887f2 to your computer and use it in GitHub Desktop.
Save ztraboo/d1e9cad3e9a9c03e75f2792922f887f2 to your computer and use it in GitHub Desktop.
direnv – configuration for multidevstack environment for Open edX
## ~/.bashrc
## Hook in `direnv` for local directory environment overrides.
## https://direnv.net/docs/hook.html
eval "$(direnv hook bash)"
# https://github.com/direnv/direnv/wiki/Python#bash
show_virtual_env() {
if [[ -n "$VIRTUAL_ENV" && -n "$DIRENV_DIR" ]]; then
echo "($(basename $VIRTUAL_ENV))"
fi
}
export -f show_virtual_env
PS1='$(show_virtual_env)'$PS1
## /Users/ztraboo/Dev/EducateWorkforce/Repos/open-edx/devstack.ironwood/.envrc
# https://discuss.openedx.org/t/docker-devstack-multiple-releases-one-machine/1902/10
# This is handled when OPENEDX_RELEASE is set. Leaving this in for manual override.
# export COMPOSE_PROJECT_NAME=devstack-hawthorn
export DEVSTACK_WORKSPACE="$(pwd)"
export OPENEDX_RELEASE=hawthorn.master
export VIRTUAL_ENV="$(pwd)/devstack/venv"
# https://github.com/direnv/direnv/wiki/Python#virtualenv
layout python-venv
## /Users/ztraboo/Dev/EducateWorkforce/Repos/open-edx/devstack.ironwood/.envrc
# https://discuss.openedx.org/t/docker-devstack-multiple-releases-one-machine/1902/10
# This is handled when OPENEDX_RELEASE is set. Leaving this in for manual override.
# export COMPOSE_PROJECT_NAME=devstack-ironwood
export DEVSTACK_WORKSPACE="$(pwd)"
export OPENEDX_RELEASE=ironwood.master
export VIRTUAL_ENV="$(pwd)/devstack/venv"
# https://github.com/direnv/direnv/wiki/Python#virtualenv
layout python-venv
## /Users/ztraboo/Dev/EducateWorkforce/Repos/open-edx/devstack.ironwood/.envrc
# https://discuss.openedx.org/t/docker-devstack-multiple-releases-one-machine/1902/10
# This is handled when OPENEDX_RELEASE is set. Leaving this in for manual override.
# export COMPOSE_PROJECT_NAME=devstack
export DEVSTACK_WORKSPACE="$(pwd)"
# Don't define OPENEDX_RELEASE for the `master` release.
export VIRTUAL_ENV="$(pwd)/devstack/venv"
# https://github.com/direnv/direnv/wiki/Python#virtualenv
layout python-venv
## ~/.zshrc
## Hook in `direnv` for local directory environment setup.
## https://direnv.net/docs/hook.html
eval "$(direnv hook zsh)"
# https://github.com/direnv/direnv/wiki/Python#zsh
setopt PROMPT_SUBST
show_virtual_env() {
if [[ -n "$VIRTUAL_ENV" && -n "$DIRENV_DIR" ]]; then
echo "($(basename $VIRTUAL_ENV))"
fi
}
PS1='$(show_virtual_env)'$PS1
## ~/.config/direnv/direnvrc
# https://github.com/direnv/direnv/wiki/Python#venv-stdlib-module
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/.direnv/python-venv-$python_version
fi
export VIRTUAL_ENV
if [[ ! -d $VIRTUAL_ENV ]]; then
log_status "no venv found; creating $VIRTUAL_ENV"
"$python" -m venv "$VIRTUAL_ENV"
fi
PATH="${VIRTUAL_ENV}/bin:${PATH}"
export PATH
}
@ztraboo
Copy link
Author

ztraboo commented May 29, 2020

If you get this error then you just need to issue a direnv allow to make this permission work.

ztraboo-macbookpro:devstack.hawthorn ztraboo$ zsh
direnv: error /Users/ztraboo/Dev/EducateWorkforce/Repos/open-edx/devstack.hawthorn/.envrc is blocked. Run `direnv allow` to approve its content   

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment