bootstrap-py3-venv 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 venv "${venv_name}" || {
  44. echo "bootstrap failed!"
  45. return 1
  46. }
  47. source "${venv_name}/bin/activate" || {
  48. echo "bootstrap failed!"
  49. return 1
  50. }
  51. make install-py-dev || {
  52. echo "bootstrap failed!"
  53. return 1
  54. }
  55. make setup-git || {
  56. echo "bootstrap failed!"
  57. return 1
  58. }
  59. deactivate || {
  60. echo "bootstrap failed!"
  61. return 1
  62. }
  63. direnv allow || {
  64. echo "bootstrap failed!"
  65. return 1
  66. }