From 0c2797391a6d628876dd532cc004026eaf634642 Mon Sep 17 00:00:00 2001 From: Armen Zambrano G Date: Thu, 24 Mar 2022 12:36:40 -0400 Subject: [PATCH] fix(dev): New Python virtualenvs to install Python 3.8.13 (#32883) This version bump is only for new development environments. If you run Monterrey and need a Python version via pyenv, the lowest version you can get is 3.8.13. Existing Python venvs do not need to be upgraded. See https://github.com/pyenv/pyenv/issues/2284 for details. --- .github/workflows/development-environment.yml | 16 ++++++--- .python-version | 2 +- scripts/ensure-venv.sh | 9 +++-- scripts/lib.sh | 36 +++++++++---------- scripts/pyenv_setup.sh | 7 ++-- 5 files changed, 39 insertions(+), 31 deletions(-) diff --git a/.github/workflows/development-environment.yml b/.github/workflows/development-environment.yml index 36e53e3b8f4b7b..e99d30f64685cc 100644 --- a/.github/workflows/development-environment.yml +++ b/.github/workflows/development-environment.yml @@ -4,14 +4,15 @@ on: paths: - '.pre-commit-config.yaml' - 'Makefile' - - '.github/actions/setup-python' - '.github/workflows/development-environment.yml' + - 'requirements-*.txt' + - '.python-version' + - '.github/actions/setup-python' - '.envrc' - 'Brewfile' - 'scripts/*' - 'src/sentry/runner/commands/devserver.py' - 'src/sentry/runner/commands/devservices.py' - - 'requirements-*.txt' - 'bin/load-mocks' jobs: @@ -29,7 +30,7 @@ jobs: - name: Checkout sentry uses: actions/checkout@v2 - - name: Set variables for caches + - name: Set up id: info run: | echo "::set-output name=yarn-cache-dir::$(yarn cache dir)" @@ -54,6 +55,10 @@ jobs: # This handles Python's cache - name: Setup Python & cache uses: ./.github/actions/setup-python + # Remove this block when 3.8.13 becomes available in: + # https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json + with: + python-version: 3.8.12 - name: Cache (yarn) uses: actions/cache@v1 # We are explicitly using v1 due to perf reasons @@ -75,7 +80,7 @@ jobs: pyenv-setup: name: pyenv set up runs-on: macos-11 - timeout-minutes: 15 + timeout-minutes: 25 env: # This is to support this code https://github.com/getsentry/sentry/blob/47b837a69c38e190a7555de81e6d7d216498b854/scripts/pyenv_setup.sh#L17-L40 SHELL: /bin/zsh @@ -84,9 +89,10 @@ jobs: - name: Checkout sentry uses: actions/checkout@v2 + # We update brew because we need a newer version of pyenv which has access to 3.8.13 - name: Install pyenv run: | - HOMEBREW_NO_AUTO_UPDATE=1 brew install pyenv + brew update && brew install pyenv # Only after we source ~/.zprofile that the right Python will be selected - name: Set up pyenv diff --git a/.python-version b/.python-version index 89a1ad7ad3cad1..6a801ce542c823 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.8.12 +3.8.13 diff --git a/scripts/ensure-venv.sh b/scripts/ensure-venv.sh index ad0b3afebd41fb..9dc0278ce75582 100755 --- a/scripts/ensure-venv.sh +++ b/scripts/ensure-venv.sh @@ -20,9 +20,6 @@ EOF } if [[ -n "$VIRTUAL_ENV" ]]; then - # The developer is inside a virtualenv *and* has set a SENTRY_PYTHON_VERSION - # Let's assume that they know what they're doing - # Let's make sure they know that they're not using a different version by mistake query-valid-python-version || exit 1 else @@ -32,5 +29,11 @@ else die "You have a virtualenv, but it doesn't seem to be activated. Please run: source ${venv_name}/bin/activate" fi + +if [ -L "${venv_name}/bin/python3" ] && [ ! -e "${venv_name}/bin/python3" ]; then + die "Your symlink ${venv_name}/bin/python3 seems to be pointing to a non-existing Python binary. Try: rm -rf ${venv_name} && direnv allow" +fi + + # Somehow it does not succeed unless I exit with 0 exit 0 diff --git a/scripts/lib.sh b/scripts/lib.sh index 5e76ca3064c603..c27e5d25480bab 100755 --- a/scripts/lib.sh +++ b/scripts/lib.sh @@ -52,8 +52,8 @@ query-apple-m1() { } query-valid-python-version() { + python_version=$(python3 -V 2>&1 | awk '{print $2}') if [[ -n "${SENTRY_PYTHON_VERSION:-}" ]]; then - python_version=$(python3 -V 2>&1 | awk '{print $2}') if [ "$python_version" != "$SENTRY_PYTHON_VERSION" ]; then cat <&1 | awk '{print $2}') - minor=$(echo "${python_version}" | sed 's/[0-9]*\.\([0-9]*\)\.\([0-9]*\)/\1/') - patch=$(echo "${python_version}" | sed 's/[0-9]*\.\([0-9]*\)\.\([0-9]*\)/\2/') - - if [ "$minor" -ne 8 ] || [ "$patch" -lt 10 ]; then - cat <= 3.8.10, < 3.9. -Either run "rm -rf ${venv_name} && direnv allow" to -OR set SENTRY_PYTHON_VERSION=${python_version} to an .env file to bypass this check." + return 0 + fi + else + minor=$(echo "${python_version}" | sed 's/[0-9]*\.\([0-9]*\)\.\([0-9]*\)/\1/') + patch=$(echo "${python_version}" | sed 's/[0-9]*\.\([0-9]*\)\.\([0-9]*\)/\2/') + if [ "$minor" -ne 8 ] || [ "$patch" -lt 10 ]; then + cat <= 3.8.10, < 3.9. + Either run "rm -rf ${venv_name} && direnv allow" to + OR set SENTRY_PYTHON_VERSION=${python_version} to an .env file to bypass this check." EOF - return 1 + return 1 + fi fi } diff --git a/scripts/pyenv_setup.sh b/scripts/pyenv_setup.sh index 82e632b1373912..8b78e8991ea581 100755 --- a/scripts/pyenv_setup.sh +++ b/scripts/pyenv_setup.sh @@ -82,10 +82,11 @@ append_to_config() { install_pyenv() { if require pyenv; then + pyenv_version=$(pyenv -v | awk '{print $2}') # NOTE: We're dropping support for older pyenv versions - if [[ "$(pyenv -v | awk '{print $2}')" < 2.0.0 ]]; then - echo >&2 "!!! We've dropped support for pyenv v1." \ - "Run the following (this is slow) and try again." + if [[ "${pyenv_version}" < 2.2.5 ]]; then + echo >&2 "!!! We've dropped support for pyenv version ${pyenv_version}." \ + "Run the following steps (this is slow) and try again." # brew upgrade does not quite do the right thing # > ~/.pyenv/shims/python: line 8: /usr/local/Cellar/pyenv/1.2.26/libexec/pyenv: No such file or directory echo >&2 "brew update && brew uninstall pyenv && brew install pyenv"