ensure-venv.sh 1006 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. HERE="$(
  3. cd "$(dirname "${BASH_SOURCE[0]}")" || exit
  4. pwd -P
  5. )"
  6. # shellcheck disable=SC1090
  7. source "${HERE}/lib.sh"
  8. # optionally opt out of virtualenv creation
  9. # WARNING: this will be removed (most likely renamed) soon!
  10. if [[ "$SENTRY_NO_VIRTUALENV_CREATION" == "1" ]]; then
  11. exit 0
  12. fi
  13. die() {
  14. cat <<EOF
  15. $@
  16. EOF
  17. exit 1
  18. }
  19. if [[ -n "$VIRTUAL_ENV" ]]; then
  20. # The developer is inside a virtualenv *and* has set a SENTRY_PYTHON_VERSION
  21. # Let's assume that they know what they're doing
  22. # Let's make sure they know that they're not using a different version by mistake
  23. query-valid-python-version || exit 1
  24. else
  25. if [[ ! -f "${venv_name}/bin/activate" ]]; then
  26. die "You don't seem to have a virtualenv. Please create one by running: source ./scripts/bootstrap-py3-venv"
  27. fi
  28. die "You have a virtualenv, but it doesn't seem to be activated. Please run: source ${venv_name}/bin/activate"
  29. fi
  30. # Somehow it does not succeed unless I exit with 0
  31. exit 0