Skip to content

Commit

Permalink
fix(dev): New Python virtualenvs to install Python 3.8.13 (getsentry#…
Browse files Browse the repository at this point in the history
…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 pyenv/pyenv#2284 for details.
  • Loading branch information
armenzg authored Mar 24, 2022
1 parent 6d0eddc commit 0c27973
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 31 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/development-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.12
3.8.13
9 changes: 6 additions & 3 deletions scripts/ensure-venv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
36 changes: 17 additions & 19 deletions scripts/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
${red}${bold}
Expand All @@ -63,29 +63,27 @@ You should create a new ${SENTRY_PYTHON_VERSION} virtualenv by running "rm -rf
${reset}
EOF
return 1
fi

cat <<EOF
else
cat <<EOF
${yellow}${bold}
You have explicitly set a non-recommended Python version (${SENTRY_PYTHON_VERSION}). You're on your own.
${reset}
EOF
return 0
fi

python_version=$(python3 -V 2>&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 <<EOF
${red}${bold}
ERROR: You're running a virtualenv with Python ${python_version}.
We only support >= 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 <<EOF
${red}${bold}
ERROR: You're running a virtualenv with Python ${python_version}.
We only support >= 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
}

Expand Down
7 changes: 4 additions & 3 deletions scripts/pyenv_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0c27973

Please sign in to comment.