bootstrap-py3-venv 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. command -v pyenv >/dev/null || {
  12. echo "You need to install pyenv. https://develop.sentry.dev/environment/#python"
  13. return 1
  14. }
  15. command -v direnv >/dev/null || {
  16. echo "You need to install direnv. https://develop.sentry.dev/environment/#direnv"
  17. return 1
  18. }
  19. gitroot="$(git rev-parse --show-toplevel)"
  20. cd "$gitroot"
  21. export venv_name="${PWD}/.venv"
  22. if [[ -f "${venv_name}/bin/activate" ]]; then
  23. prompt_text="You have an existing virtualenv. This script will OVERWRITE it. Continue (y/N)?"
  24. echo "$prompt_text"
  25. read resp
  26. case "$resp" in
  27. y|Y ) echo "Okay, let's do this." ;;
  28. * ) echo "Aborted!"; return 1 ;;
  29. esac
  30. fi
  31. deactivate 2>/dev/null || true
  32. rm -rf "$venv_name"
  33. # XXX: You'll also need to temporarily pyenv local "$SENTRY_PYTHON_VERSION"
  34. # and then revert changes to the .python-version after bootstrap finishes.
  35. if [[ -z "$SENTRY_PYTHON_VERSION" ]] && ! [[ "$(python3 -V 2>&1)" = "Python $(grep "3.6" .python-version)" ]]; then
  36. echo "Your python3 version isn't as expected. Please run: make setup-pyenv"
  37. return 1
  38. fi
  39. python3 -m pip install -U pip || { echo "bootstrap failed!"; return 1; }
  40. python3 -m venv "${venv_name}" || { echo "bootstrap failed!"; return 1; }
  41. source "${venv_name}/bin/activate" || { echo "bootstrap failed!"; return 1; }
  42. python3 -m pip install -U pip || { echo "bootstrap failed!"; return 1; }
  43. make setup-git || { echo "bootstrap failed!"; return 1; }
  44. make install-py-dev || { echo "bootstrap failed!"; return 1; }
  45. deactivate || { echo "bootstrap failed!"; return 1; }
  46. direnv allow || { echo "bootstrap failed!"; return 1; }