Browse Source

dev: default to Python 3 (#22330)

josh 4 years ago
parent
commit
2ff256d53b

+ 13 - 22
.envrc

@@ -31,7 +31,7 @@ EOF
 }
 
 require() {
-    command -v "$1" 2>&1 >/dev/null
+    command -v "$1" >/dev/null 2>&1
 }
 
 warn() {
@@ -59,9 +59,9 @@ advice_init_venv() {
     venv_name="$2"
 
     deactivate 2>/dev/null || true
-    info "To create a virtualenv, please type: ${python_version} -m virtualenv ${venv_name}"
-    require ${python_version} ||
-        die "You'll need to install ${python_version}, or make it available on your PATH.
+    info "To create a virtualenv, please type: python${python_version} -m virtualenv ${venv_name}"
+    require "python${python_version}" ||
+        die "You'll need to install python${python_version}, or make it available on your PATH.
 It's recommended to use pyenv - please refer to https://docs.sentry.io/development/contribute/environment"
     return 1
 }
@@ -121,16 +121,12 @@ make setup-git-config
 
 ### Python ###
 
-# we're enforcing that virtualenv be in .venv{,3}, since future tooling e.g.
-# venv-update will rely on this.
 venv_name=".venv"
-python_version="python2.7"
+python_version="3.6"
 
-if [ "$SENTRY_PYTHON3" = "1" ]; then
-    venv_name=".venv3"
-    python_version="python3.6"
-
-    warn "Running in EXPERIMENTAL Python 3 mode... Good luck"
+if [ "$SENTRY_PYTHON2" = "1" ]; then
+    venv_name=".venv2"
+    python_version="2.7"
 fi
 
 info "Activating virtualenv..."
@@ -144,7 +140,7 @@ fi
 # (in that it would be automatically deactivated) virtualenv active.
 deactivate 2>/dev/null || true
 
-source ${venv_name}/bin/activate
+source "${venv_name}/bin/activate"
 
 # XXX: ideally, direnv is able to export PS1 as modified by sourcing venvs
 #      but we'd have to patch direnv, and ".venv" isn't descriptive anyways
@@ -157,16 +153,11 @@ if [ "$(command -v python)" != "${PWD}/${venv_name}/bin/python" ]; then
     advice_init_venv "$python_version" "$venv_name"
 fi
 
-if [ "$SENTRY_PYTHON3"  = "1" ]; then
-    python -c "import sys; sys.exit(sys.version_info[:2] != (3, 6))" ||
-        die "For some reason, the virtualenv isn't Python 3.6."
-else
-    python -c "import sys; sys.exit(sys.version_info[:2] != (2, 7))" ||
-        die "For some reason, the virtualenv isn't Python 2.7."
-fi
+info "Ensuring proper virtualenv..."
+${PWD}/scripts/ensure-venv.sh
 
 if [ "$(command -v sentry)" != "${PWD}/${venv_name}/bin/sentry" ]; then
-    info "Your virtual env is activated, but sentry doesn't seem to be installed."
+    info "Your virtualenv is activated, but sentry doesn't seem to be installed."
     # XXX: if direnv fails, the venv won't be activated outside of direnv execution...
     # So, it is critical that make install-py-dev is guarded by scripts/ensure-venv.
     advice_install_sentry
@@ -210,7 +201,7 @@ ${green}${bold}direnv: SUCCESS!
 ${reset}
 EOF
 
-if [ ! -n "${SENTRY_SILENCE_DIRENV_NOTICE:-}" ]; then
+if [ -z "${SENTRY_SILENCE_DIRENV_NOTICE:-}" ]; then
     cat <<EOF
 direnv tooling is in an ALPHA state!
 If you're having trouble, or have questions, please ask in #discuss-dev-tooling

+ 1 - 1
.github/actions/setup-sentry/action.yml

@@ -44,7 +44,7 @@ runs:
         echo "SENTRY_LIGHT_BUILD=1" >> $GITHUB_ENV
         echo "SENTRY_SKIP_BACKEND_VALIDATION=1" >> $GITHUB_ENV
 
-        [ "$PYTHON_VERSION" = "3" ] && echo "SENTRY_PYTHON3=1" >> $GITHUB_ENV || true
+        [ "$PYTHON_VERSION" = "2" ] && echo "SENTRY_PYTHON2=1" >> $GITHUB_ENV || true
 
         ### node configuration ###
         echo "NODE_ENV=development" >> $GITHUB_ENV

+ 1 - 2
.github/workflows/acceptance-py3.6.yml

@@ -44,7 +44,7 @@ jobs:
         id: python-version
         if: steps.changes.outputs.backend == 'true'
         run: |
-          echo "::set-output name=python-version::$(awk 'FNR == 2' .python-version)"
+          echo "::set-output name=python-version::$(grep "3.6" .python-version)"
 
       # Until GH composite actions can use `uses`, we need to setup python here
       - uses: actions/setup-python@v2
@@ -71,7 +71,6 @@ jobs:
         id: setup
         if: steps.changes.outputs.backend == 'true'
         with:
-          python: 3
           snuba: true
 
       - name: yarn cache

+ 1 - 2
.github/workflows/api-docs-test.yml

@@ -30,7 +30,7 @@ jobs:
         id: python-version
         if: steps.changes.outputs.api_docs == 'true'
         run: |
-          echo "::set-output name=python-version::$(awk 'FNR == 2' .python-version)"
+          echo "::set-output name=python-version::$(grep "3.6" .python-version)"
 
       # Until GH composite actions can use `uses`, we need to setup python here
       - uses: actions/setup-python@v2
@@ -57,7 +57,6 @@ jobs:
         id: setup
         if: steps.changes.outputs.api_docs == 'true'
         with:
-          python: 3
           snuba: true
 
       - name: Install Javascript Dependencies

+ 1 - 1
.github/workflows/backend-lint.yml

@@ -34,7 +34,7 @@ jobs:
         id: python-version
         if: steps.changes.outputs.backend == 'true'
         run: |
-          echo "::set-output name=python-version::$(awk 'FNR == 2' .python-version)"
+          echo "::set-output name=python-version::$(grep "3.6" .python-version)"
 
       # Until GH composite actions can use `uses`, we need to setup python here
       - uses: actions/setup-python@v2

+ 1 - 2
.github/workflows/backend-test-py3.6.yml

@@ -40,7 +40,7 @@ jobs:
         id: python-version
         if: steps.changes.outputs.backend == 'true'
         run: |
-          echo "::set-output name=python-version::$(awk 'FNR == 2' .python-version)"
+          echo "::set-output name=python-version::$(grep "3.6" .python-version)"
 
       # Until GH composite actions can use `uses`, we need to setup python here
       - uses: actions/setup-python@v2
@@ -67,7 +67,6 @@ jobs:
         if: steps.changes.outputs.backend == 'true'
         id: setup
         with:
-          python: 3
           snuba: true
 
       - name: Run backend test [py3.6] (${{ steps.setup.outputs.matrix-instance-number }} of ${{ strategy.job-total }})

+ 1 - 2
.github/workflows/snuba-integration-test-py3.6.yml

@@ -41,7 +41,7 @@ jobs:
         id: python-version
         if: steps.changes.outputs.backend == 'true'
         run: |
-          echo "::set-output name=python-version::$(awk 'FNR == 2' .python-version)"
+          echo "::set-output name=python-version::$(grep "3.6" .python-version)"
 
       # Until GH composite actions can use `uses`, we need to setup python here
       - uses: actions/setup-python@v2
@@ -68,7 +68,6 @@ jobs:
         if: steps.changes.outputs.backend == 'true'
         id: setup
         with:
-          python: 3
           snuba: true
           kafka: true
 

+ 1 - 1
.python-version

@@ -1,2 +1,2 @@
-2.7.16
 3.6.10
+2.7.16

+ 1 - 1
Makefile

@@ -2,7 +2,7 @@ PIP := python -m pip --disable-pip-version-check
 WEBPACK := yarn build-acceptance
 
 # Currently, this is only required to install black via pre-commit.
-REQUIRED_PY3_VERSION := $(shell awk 'FNR == 2' .python-version)
+REQUIRED_PY3_VERSION := $(shell grep "3.6" .python-version)
 
 bootstrap: develop init-config run-dependent-services create-db apply-migrations build-platform-assets
 

+ 7 - 6
scripts/bootstrap-py2-venv

@@ -22,12 +22,13 @@ command -v direnv >/dev/null || {
     return 1
 }
 
-unset SENTRY_PYTHON3
+export SENTRY_PYTHON2=1
 
 gitroot="$(git rev-parse --show-toplevel)"
 cd "$gitroot"
+export venv_name="${PWD}/.venv2"
 
-if [[ -f .venv/bin/activate ]]; then
+if [[ -f "${venv_name}/bin/activate" ]]; then
     echo "You seem to have a virtualenv already. This script is meant to start one from scratch. Continue (y/N)?"
     read resp
     case "$resp" in
@@ -37,16 +38,16 @@ if [[ -f .venv/bin/activate ]]; then
 fi
 
 deactivate 2>/dev/null || true
-rm -rf .venv/
+rm -rf "$venv_name"
 
-if ! [[ "$(python2.7 -V 2>&1)" = "Python $(awk -v ORS='' 'FNR == 1' .python-version)" ]]; then
+if ! [[ "$(python2.7 -V 2>&1)" = "Python $(grep "2.7" .python-version)" ]]; then
     abort "Your python2.7 version isn't as expected. Please run: make setup-pyenv"
 fi
 
 python2.7 -m pip install -U pip         || { echo "bootstrap failed!"; return 1; }
 python2.7 -m pip install -U virtualenv  || { echo "bootstrap failed!"; return 1; }
-python2.7 -m virtualenv .venv           || { echo "bootstrap failed!"; return 1; }
-source .venv/bin/activate               || { echo "bootstrap failed!"; return 1; }
+python2.7 -m virtualenv "${venv_name}"  || { echo "bootstrap failed!"; return 1; }
+source "${venv_name}/bin/activate"      || { echo "bootstrap failed!"; return 1; }
 make setup-git                          || { echo "bootstrap failed!"; return 1; }
 make install-py-dev                     || { echo "bootstrap failed!"; return 1; }
 deactivate                              || { echo "bootstrap failed!"; return 1; }

Some files were not shown because too many files changed in this diff