bootstrap-py3-venv 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # This script is meant to be sourced by bash, not executed.
  2. # As such, don't use exit, use return.
  3. # This script is purely a python virtualenv bootstrap, not the entire development environment.
  4. # For the entire thing, you should still use make bootstrap.
  5. # Eventually, the goal would be to have an idempotent single script that does
  6. # everything make bootstrap does and more (system dependencies and so on).
  7. # This... doesn't quite work.
  8. # set -e
  9. # trap "echo 'bootstrap FAILED.' && trap - ERR && return" ERR
  10. # So just going to sprinkle returns everywhere.
  11. SCRIPTS_DIR="$(
  12. cd "$(dirname "${BASH_SOURCE[0]}")"
  13. pwd -P
  14. )"
  15. source "${SCRIPTS_DIR}/lib.sh"
  16. command -v pyenv >/dev/null || {
  17. echo "You need to install pyenv. https://develop.sentry.dev/environment/#python"
  18. return 1
  19. }
  20. command -v direnv >/dev/null || {
  21. echo "You need to install direnv. https://develop.sentry.dev/environment/#direnv"
  22. return 1
  23. }
  24. gitroot="$(git rev-parse --show-toplevel)"
  25. cd "$gitroot"
  26. # This executes very quickly if the Python versions are already installed
  27. make setup-pyenv
  28. export PYENV_VERSION=$(SENTRY_NO_VENV_CHECK=1 ${SCRIPTS_DIR}/do.sh get-pyenv-version)
  29. venv_name="${PWD}/.venv"
  30. if [[ -f "${venv_name}/bin/activate" ]]; then
  31. prompt_text="You have an existing virtualenv. This script will OVERWRITE it. Continue (y/N)?"
  32. echo "$prompt_text"
  33. read resp
  34. case "$resp" in
  35. y|Y ) echo "Okay, let's do this." ;;
  36. * ) echo "Aborted!"; return 1 ;;
  37. esac
  38. fi
  39. deactivate 2>/dev/null || true
  40. rm -rf "$venv_name"
  41. if [[ -z "$SENTRY_PYTHON_VERSION" ]] && ! query-valid-python-version; then
  42. echo "Your python3 version isn't as expected. Please run: make setup-pyenv"
  43. return 1
  44. fi
  45. python3 -m pip install -U pip || { echo "bootstrap failed!"; return 1; }
  46. python3 -m venv "${venv_name}" || { echo "bootstrap failed!"; return 1; }
  47. source "${venv_name}/bin/activate" || { echo "bootstrap failed!"; return 1; }
  48. python3 -m pip install -U pip wheel || { echo "bootstrap failed!"; return 1; }
  49. make setup-git || { echo "bootstrap failed!"; return 1; }
  50. make install-py-dev || { echo "bootstrap failed!"; return 1; }
  51. deactivate || { echo "bootstrap failed!"; return 1; }
  52. direnv allow || { echo "bootstrap failed!"; return 1; }