Просмотр исходного кода

dev_env(fix): Drop support for older versions of pyenv (#25413)

pyenv is shipped with a set of Python versions it can install. When we moved to Python 3.6.13
some engineers are not able to update their Python versions without updating pyenv via Brew.

This change drops support for older versions of pyenv and requests anyone upgrading their venv
to update brew and update to the latest pyenv.
Armen Zambrano G 3 лет назад
Родитель
Сommit
c4a5b87219
1 измененных файлов с 42 добавлено и 34 удалено
  1. 42 34
      scripts/pyenv_setup.sh

+ 42 - 34
scripts/pyenv_setup.sh

@@ -5,7 +5,10 @@
 # - This script assumes you're calling from the top directory of the repository
 set -eu
 
-HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)"
+HERE="$(
+  cd "$(dirname "${BASH_SOURCE[0]}")"
+  pwd -P
+)"
 # shellcheck disable=SC1090
 source "${HERE}/lib.sh"
 
@@ -13,18 +16,19 @@ get_shell_startup_script() {
   local _startup_script=''
   if [[ -n "$SHELL" ]]; then
     case "$SHELL" in
-      */bash)
-        _startup_script="${HOME}/.bash_profile"
-        ;;
-      */zsh)
-        _startup_script="${HOME}/.zshrc"
-        ;;
-      */fish)
-        _startup_script="${HOME}/.config/fish/config.fish"
-        ;;
-      *)
-        echo "$SHELL is currently not supported."
-        exit 1
+    */bash)
+      _startup_script="${HOME}/.bash_profile"
+      ;;
+    */zsh)
+      _startup_script="${HOME}/.zshrc"
+      ;;
+    */fish)
+      _startup_script="${HOME}/.config/fish/config.fish"
+      ;;
+    *)
+      echo "$SHELL is currently not supported."
+      exit 1
+      ;;
     esac
   else
     echo "The environment variable \$SHELL needs to be defined."
@@ -36,16 +40,17 @@ get_shell_startup_script() {
 _append_to_startup_script() {
   if [[ -n "$SHELL" ]]; then
     case "$SHELL" in
-      */bash)
-        # shellcheck disable=SC2016
-        echo -e '\nif command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> "${1}"
-        ;;
-      */zsh)
-        # shellcheck disable=SC2016
-        echo -e '\nif command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> "${1}"
-        ;;
-      */fish)
-        echo -e '\n\n# pyenv init\nif command -v pyenv 1>/dev/null 2>&1\n  pyenv init - | source\nend' >> "$1"
+    */bash)
+      # shellcheck disable=SC2016
+      echo -e '\nif command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >>"${1}"
+      ;;
+    */zsh)
+      # shellcheck disable=SC2016
+      echo -e '\nif command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >>"${1}"
+      ;;
+    */fish)
+      echo -e '\n\n# pyenv init\nif command -v pyenv 1>/dev/null 2>&1\n  pyenv init - | source\nend' >>"$1"
+      ;;
     esac
 
     echo "--> Tail of ${1}"
@@ -71,23 +76,26 @@ install_pyenv() {
     echo "Installing Python (if missing) via pyenv"
     local pyenv_version
     pyenv_version=$(pyenv -v | awk '{print $2}')
-    python_version=$(xargs -n1 < .python-version)
+    python_version=$(xargs -n1 <.python-version)
+    # NOTE: Older pyenv does not have access to the latest Python we require
+    if [[ "$pyenv_version" < 1.2.26 ]]; then
+      echo >&2 "!!! Your pyenv is old and does not know how to find the Python we require." \
+        "Run the following (this is slow) and try again."
+      echo >&2 "brew update && brew upgrade pyenv"
+      exit 1
+    fi
 
+    # We need to patch the source code on Big Sur before building Python
+    # We can remove this once we upgrade to newer versions of Python
     if query_big_sur; then
-      local flag
-      # NOTE: pyenv 1.2.22 or greater does not require using LDFLAGS
-      # https://github.com/pyenv/pyenv/pull/1711
-      if [[ "$pyenv_version" < 1.2.22 ]]; then
-        flag="-L$(xcrun --show-sdk-path)/usr/lib ${LDFLAGS}"
-      fi
       # cat is used since pyenv would finish to soon when the Python version is already installed
-      curl -sSL https://github.com/python/cpython/commit/8ea6353.patch | cat | \
-        LDFLAGS="$flag" pyenv install --skip-existing --patch "$python_version"
+      curl -sSL https://github.com/python/cpython/commit/8ea6353.patch | cat |
+        pyenv install --skip-existing --patch "$python_version"
     else
       pyenv install --skip-existing "$python_version"
     fi
   else
-    echo "!!! pyenv not found, try running bootstrap script again or run \`brew bundle\` in the sentry repo"
+    echo >&2 "!!! pyenv not found, try running bootstrap script again or run \`brew bundle\` in the sentry repo"
     exit 1
   fi
 }
@@ -104,7 +112,7 @@ setup_pyenv() {
   echo "Activating pyenv and validating Python version"
   eval "$(pyenv init -)"
   python_version=$(python -V | sed s/Python\ //g)
-  [[ $python_version == $(cat .python-version) ]] || \
+  [[ $python_version == $(cat .python-version) ]] ||
     (echo "Wrong Python version: $python_version. Please report in #discuss-dev-tooling" && exit 1)
 }