ensure-venv.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. venv_name=".venv"
  8. python_bin="python2.7"
  9. if [ "$SENTRY_PYTHON3" = "1" ]; then
  10. venv_name=".venv3"
  11. python_bin="python3.6"
  12. fi
  13. die() {
  14. cat >&2 "${@}"
  15. exit 1
  16. }
  17. if [ -n "$VIRTUAL_ENV" ]; then
  18. # we're enforcing that virtualenv be in .venv, since future tooling e.g. venv-update will rely on this.
  19. if [ "$VIRTUAL_ENV" != "${PWD}/${venv_name}" ]; then
  20. die "You're in a virtualenv, but it's not in the expected location (${PWD}/${venv_name})"
  21. fi
  22. # TODO: Update this to strictly check .python-version
  23. if [ "$SENTRY_PYTHON3" = "1" ]; then
  24. python -c "import sys; sys.exit(sys.version_info[:2] != (3, 6))" ||
  25. die "For some reason, the virtualenv isn't Python 3.6."
  26. else
  27. python -c "import sys; sys.exit(sys.version_info[:2] != (2, 7))" ||
  28. die "For some reason, the virtualenv isn't Python 2.7."
  29. fi
  30. else
  31. if [ ! -f "${venv_name}/bin/activate" ]; then
  32. die "You don't seem to have a virtualenv. Please create one by running: ${python_bin} -m virtualenv ${venv_name}"
  33. fi
  34. die "You have a virtualenv, but it doesn't seem to be activated. Please run: source ${venv_name}/bin/activate"
  35. fi