ensure-venv.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. venv_name=".venv"
  14. die() {
  15. cat <<EOF
  16. $@
  17. EOF
  18. exit 1
  19. }
  20. if [[ -n "$VIRTUAL_ENV" ]]; then
  21. # The developer is inside a virtualenv *and* has set a SENTRY_PYTHON_VERSION
  22. # Let's assume that they know what they're doing
  23. if [[ -n "$SENTRY_PYTHON_VERSION" ]]; then
  24. cat <<EOF
  25. ${yellow}${bold}
  26. You have explicitly set a non-recommended Python version ($(python -V | awk '{print $2}')). You're on your own.
  27. ${reset}
  28. EOF
  29. exit 0
  30. fi
  31. # Let's make sure they know that they're not using a different version by mistake
  32. if ! query-valid-python-version; then
  33. cat <<EOF
  34. ${red}${bold}
  35. WARNING! You are running a virtualenv with a Python version ($(which python))
  36. different than 3.6 (or at least 3.8.10 on M1 Macs). Either run "rm -rf ${venv_name} && direnv allow"
  37. OR use SENTRY_PYTHON_VERSION to by-pass this check."
  38. ${reset}
  39. EOF
  40. exit 1
  41. fi
  42. else
  43. if [[ ! -f "${venv_name}/bin/activate" ]]; then
  44. die "You don't seem to have a virtualenv. Please create one by running: source ./scripts/bootstrap-py3-venv"
  45. fi
  46. die "You have a virtualenv, but it doesn't seem to be activated. Please run: source ${venv_name}/bin/activate"
  47. fi
  48. # Somehow it does not succeed unless I exit with 0
  49. exit 0