configure 960 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env bash
  2. set -e
  3. set -u
  4. set -o pipefail
  5. prompt_then_exit() {
  6. local prompt=${1-?}
  7. local status=${2-?}
  8. echo $prompt $status
  9. exit $status
  10. }
  11. get_python_version() {
  12. local firstline=
  13. read -r firstline < .python-version
  14. echo ${firstline}
  15. }
  16. drek_configure_main() {
  17. local python_version=$(get_python_version)
  18. local venv="venv"
  19. if [[ "Python ${python_version}" != $(python3 --version) ]]; then
  20. pyenv --version
  21. if [[ ! -d "${HOME}/.pyenv/versions/${python_version}" ]]; then
  22. pyenv install ${python_version}
  23. fi
  24. pyenv local ${python_version}
  25. fi
  26. python3 -m venv ./var/${venv} \
  27. && ./var/${venv}/bin/pip3 install --upgrade pip \
  28. && ./var/${venv}/bin/pip3 install ./ \
  29. || prompt_then_exit "drek configure failed" $?
  30. echo -e "\nActivate your local development environment:"
  31. echo -e "\n source ./var/${venv}/bin/activate"
  32. }
  33. drek_configure_main $@