Browse Source

hold back `devenv` rollout, for today (#59444)

@asottile-sentry found several issues that we need to address before
this gets into the wild.
Buck Evan 1 year ago
parent
commit
aa1cf89710
2 changed files with 33 additions and 12 deletions
  1. 15 5
      .envrc
  2. 18 7
      scripts/lib.sh

+ 15 - 5
.envrc

@@ -1,3 +1,4 @@
+#!/not/executable/bash
 # This is the .envrc for sentry, for use with direnv.
 # This is the .envrc for sentry, for use with direnv.
 # It's responsible for enforcing a standard dev environment by checking as much state as possible, and either performing
 # It's responsible for enforcing a standard dev environment by checking as much state as possible, and either performing
 # initialization (e.g. activating the venv) or giving recommendations on how to reach the desired state.
 # initialization (e.g. activating the venv) or giving recommendations on how to reach the desired state.
@@ -188,8 +189,10 @@ make setup-git-config
 
 
 ### Python ###
 ### Python ###
 
 
-if [ ! -x "${HOME}/.local/share/sentry-devenv/bin/devenv" ]; then
+# Use requirements-dev.txt to decide when to cut over to `devenv` tooling.
-    # Old and busted.
+# This also provides us with a clean-cut rollback procedure.
+if ! grep -Eq "^devenv($|>)" requirements-dev.txt; then
+    # Old and busted. (but currently working)
     venv_name=".venv"
     venv_name=".venv"
     if [ ! -f "${venv_name}/bin/activate" ]; then
     if [ ! -f "${venv_name}/bin/activate" ]; then
         prompt_python_venv_creation
         prompt_python_venv_creation
@@ -197,9 +200,16 @@ if [ ! -x "${HOME}/.local/share/sentry-devenv/bin/devenv" ]; then
         source "${SENTRY_ROOT}/scripts/bootstrap-py3-venv"
         source "${SENTRY_ROOT}/scripts/bootstrap-py3-venv"
     fi
     fi
 else
 else
-    # The new hotness (coming soon).
+    # The new hotness. (but not ready yet)
-    venv_name="${HOME}/.local/share/sentry-devenv/virtualenvs/sentry"
+    export SENTRY_DEVENV_HOME="${SENTRY_DEVENV_HOME:-$XDG_DATA_HOME/sentry-devenv}"
-    if [ ! -f "${venv_name}/bin/activate" ]; then
+    PATH_add "${SENTRY_DEVENV_HOME}/bin"
+    venv_name="${SENTRY_DEVENV_HOME}/virtualenvs/sentry"
+    if ! command -v devenv >/dev/null; then
+      die '
+Please install the `devenv` tool:
+    https://github.com/getsentry/devenv#install
+'
+    elif [ ! -f "${venv_name}/bin/activate" ]; then
         devenv sync
         devenv sync
     fi
     fi
 fi
 fi

+ 18 - 7
scripts/lib.sh

@@ -18,6 +18,17 @@ fi
 
 
 venv_name=".venv"
 venv_name=".venv"
 
 
+# XDG paths' standardized defaults:
+# (see https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables )
+export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
+export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
+export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
+export XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}"
+export XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/etc/xdg}"
+export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
+export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/var/run}"
+
+
 # Check if a command is available
 # Check if a command is available
 require() {
 require() {
     command -v "$1" >/dev/null 2>&1
     command -v "$1" >/dev/null 2>&1
@@ -176,10 +187,10 @@ run-dependent-services() {
 create-db() {
 create-db() {
     container_name=${POSTGRES_CONTAINER:-sentry_postgres}
     container_name=${POSTGRES_CONTAINER:-sentry_postgres}
     echo "--> Creating 'sentry' database"
     echo "--> Creating 'sentry' database"
-    docker exec ${container_name} createdb -h 127.0.0.1 -U postgres -E utf-8 sentry || true
+    docker exec "${container_name}" createdb -h 127.0.0.1 -U postgres -E utf-8 sentry || true
     echo "--> Creating 'control' and 'region' database"
     echo "--> Creating 'control' and 'region' database"
-    docker exec ${container_name} createdb -h 127.0.0.1 -U postgres -E utf-8 control || true
+    docker exec "${container_name}" createdb -h 127.0.0.1 -U postgres -E utf-8 control || true
-    docker exec ${container_name} createdb -h 127.0.0.1 -U postgres -E utf-8 region || true
+    docker exec "${container_name}" createdb -h 127.0.0.1 -U postgres -E utf-8 region || true
 }
 }
 
 
 apply-migrations() {
 apply-migrations() {
@@ -232,10 +243,10 @@ clean() {
 drop-db() {
 drop-db() {
     container_name=${POSTGRES_CONTAINER:-sentry_postgres}
     container_name=${POSTGRES_CONTAINER:-sentry_postgres}
     echo "--> Dropping existing 'sentry' database"
     echo "--> Dropping existing 'sentry' database"
-    docker exec ${container_name} dropdb --if-exists -h 127.0.0.1 -U postgres sentry
+    docker exec "${container_name}" dropdb --if-exists -h 127.0.0.1 -U postgres sentry
     echo "--> Dropping 'control' and 'region' database"
     echo "--> Dropping 'control' and 'region' database"
-    docker exec ${container_name} dropdb --if-exists -h 127.0.0.1 -U postgres control
+    docker exec "${container_name}" dropdb --if-exists -h 127.0.0.1 -U postgres control
-    docker exec ${container_name} dropdb --if-exists -h 127.0.0.1 -U postgres region
+    docker exec "${container_name}" dropdb --if-exists -h 127.0.0.1 -U postgres region
 }
 }
 
 
 reset-db() {
 reset-db() {
@@ -243,7 +254,7 @@ reset-db() {
     create-db
     create-db
     apply-migrations
     apply-migrations
     create-superuser
     create-superuser
-    echo "Finished resetting database. To load mock data, run `./bin/load-mocks`"
+    echo 'Finished resetting database. To load mock data, run `./bin/load-mocks`'
 }
 }
 
 
 prerequisites() {
 prerequisites() {