bootstrap-py3-venv 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. export SENTRY_PYTHON3=1
  20. gitroot="$(git rev-parse --show-toplevel)"
  21. cd "$gitroot"
  22. if [[ -f .venv3/bin/activate ]]; then
  23. echo "You seem to have a virtualenv already. This script is meant to start one from scratch. Continue (y/N)?"
  24. read resp
  25. case "$resp" in
  26. y|Y ) echo "Okay, let's do this." ;;
  27. * ) echo "Aborted!"; return 1 ;;
  28. esac
  29. fi
  30. deactivate 2>/dev/null || true
  31. rm -rf .venv3/
  32. if ! [[ "$(python3 -V 2>&1)" = "Python $(awk -v ORS='' 'FNR == 2' .python-version)" ]]; then
  33. abort "Your python3 version isn't as expected. Please run: make setup-pyenv"
  34. fi
  35. python3 -m pip install -U pip || { echo "bootstrap failed!"; return 1; }
  36. python3 -m pip install -U virtualenv || { echo "bootstrap failed!"; return 1; }
  37. python3 -m virtualenv .venv3 || { echo "bootstrap failed!"; return 1; }
  38. source .venv3/bin/activate || { echo "bootstrap failed!"; return 1; }
  39. make setup-git || { echo "bootstrap failed!"; return 1; }
  40. make install-py-dev || { echo "bootstrap failed!"; return 1; }
  41. deactivate || { echo "bootstrap failed!"; return 1; }
  42. direnv allow || { echo "bootstrap failed!"; return 1; }