bootstrap-py3-venv 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. # So just going to sprinkle returns everywhere.
  8. SCRIPTS_DIR="$(
  9. cd "$(dirname "${BASH_SOURCE[0]}")"
  10. pwd -P
  11. )"
  12. source "${SCRIPTS_DIR}/lib.sh"
  13. configure-sentry-cli
  14. command -v pyenv >/dev/null || {
  15. echo "You need to install pyenv. https://develop.sentry.dev/environment/#python"
  16. return 1
  17. }
  18. command -v direnv >/dev/null || {
  19. echo "You need to install direnv. https://develop.sentry.dev/environment/#direnv"
  20. return 1
  21. }
  22. # This executes very quickly if the Python versions are already installed
  23. # This calling approach activates pyenv correctly -> eval "$(pyenv init --path)"
  24. . "$SCRIPTS_DIR/pyenv_setup.sh"
  25. venv_name="${PWD}/.venv"
  26. if [[ -f "${venv_name}/bin/activate" ]]; then
  27. echo "You have an existing virtualenv. This script will OVERWRITE it. Continue (y/N)?"
  28. read resp
  29. case "$resp" in
  30. y | Y) echo "Okay, let's do this." ;;
  31. *)
  32. echo "Aborted!"
  33. return 1
  34. ;;
  35. esac
  36. fi
  37. deactivate 2>/dev/null || true
  38. rm -rf "$venv_name"
  39. if [ -z "${SENTRY_PYTHON_VERSION-}" ] && ! query-valid-python-version; then
  40. echo "Your python3 version isn't as expected. Please run: make setup-pyenv"
  41. return 1
  42. fi
  43. python3 -m pip install -U pip || {
  44. echo "bootstrap failed!"
  45. return 1
  46. }
  47. python3 -m venv "${venv_name}" || {
  48. echo "bootstrap failed!"
  49. return 1
  50. }
  51. source "${venv_name}/bin/activate" || {
  52. echo "bootstrap failed!"
  53. return 1
  54. }
  55. python3 -m pip install -U pip wheel || {
  56. echo "bootstrap failed!"
  57. return 1
  58. }
  59. make setup-git || {
  60. echo "bootstrap failed!"
  61. return 1
  62. }
  63. make install-py-dev || {
  64. echo "bootstrap failed!"
  65. return 1
  66. }
  67. deactivate || {
  68. echo "bootstrap failed!"
  69. return 1
  70. }
  71. direnv allow || {
  72. echo "bootstrap failed!"
  73. return 1
  74. }