ensure-venv.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. # optionally opt out of virtualenv creation
  3. # WARNING: this will be removed (most likely renamed) soon!
  4. if [[ "$SENTRY_NO_VIRTUALENV_CREATION" == "1" ]]; then
  5. exit 0
  6. fi
  7. red="$(tput setaf 1)"
  8. yellow="$(tput setaf 3)"
  9. bold="$(tput bold)"
  10. reset="$(tput sgr0)"
  11. venv_name=".venv"
  12. die() {
  13. cat <<EOF
  14. $@
  15. EOF
  16. exit 1
  17. }
  18. if [[ -n "$VIRTUAL_ENV" ]]; then
  19. minor=$(python -c "import sys; print(sys.version_info[1])")
  20. # If .venv is less than Python 3.6 fail
  21. [[ "$minor" -lt 6 ]] &&
  22. die "Remove $VIRTUAL_ENV and try again since the Python version installed should be at least 3.6."
  23. # If .venv is created with Python greater than 3.6 you might encounter problems and we want to ask you to downgrade
  24. # unless you explicitely set an environment variable
  25. if [[ "$minor" -gt 6 ]]; then
  26. if [[ -n "$SENTRY_PYTHON_VERSION" ]]; then
  27. cat <<EOF
  28. ${yellow}${bold}
  29. You have explicitly set a non-recommended Python version (${SENTRY_PYTHON_VERSION}). You're on your own.
  30. ${reset}
  31. EOF
  32. else
  33. cat <<EOF
  34. ${red}${bold}
  35. ERROR! You are running a virtualenv with a Python version different than 3.6
  36. We recommend you start with a fresh virtualenv or to set the variable SENTRY_PYTHON_VERSION
  37. to the Python version you want to use (e.g. 3.7).
  38. ${reset}
  39. EOF
  40. exit 1
  41. fi
  42. fi
  43. else
  44. if [[ ! -f "${venv_name}/bin/activate" ]]; then
  45. die "You don't seem to have a virtualenv. Please create one by running: python3.6 -m venv ${venv_name}"
  46. fi
  47. die "You have a virtualenv, but it doesn't seem to be activated. Please run: source ${venv_name}/bin/activate"
  48. fi
  49. # Somehow it does not succeed unless I exit with 0
  50. exit 0