Skip to content

devenv: remove legacy ensure-venv #68224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 22 additions & 38 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@
# If you'd like to override or set any custom environment variables, this .envrc will read a .env file at the end.
set -e

# Upgrading Mac can uninstall the Command Line Tools, thus, removing our access to git
# The message talks about xcrun, however, we can use the lack of git as a way to know that we need this
# xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools),
# missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
if [ "$(uname -s)" == "Darwin" ] && [ ! -f "/Library/Developer/CommandLineTools/usr/bin/git" ]; then
echo -e "$(tput setaf 1)\nERROR: Complete the interactive installation (10+ mins) of the Command Line Tools.$(tput sgr0)"
xcode-select --install
return 1
if [ -f .venv/bin/devenv ]; then
DEVENV=.venv/bin/devenv
else
DEVENV=devenv
fi

export SENTRY_DEVENV_HOME="${SENTRY_DEVENV_HOME:-$HOME/.local/share/sentry-devenv}"
PATH_add "${SENTRY_DEVENV_HOME}/bin"
if ! command -v "$DEVENV" >/dev/null; then
die '
Please install the devenv tool:
https://github.com/getsentry/devenv#install
'
fi

SENTRY_ROOT="$(
cd "$(dirname "${BASH_SOURCE[0]}")"
pwd -P
)"
PATH_add "${PWD}/.venv/bin"
export VIRTUAL_ENV="${PWD}/.venv"

PATH_add "${PWD}/.devenv/bin"

source "${SENTRY_ROOT}/scripts/lib.sh"
source "${PWD}/scripts/lib.sh"

# XXX: we can't trap bash EXIT, because it'll override direnv's finalizing routines.
# consequently, using "exit" anywhere will skip this notice from showing.
Expand Down Expand Up @@ -101,9 +106,9 @@ export SENTRY_UI_HOT_RELOAD=1

### You can override the exported variables with a .env file
# All exports should happen before here unless they're safeguarded (see devenv error reporting below)
if [ -f "${SENTRY_ROOT}/.env" ]; then
info "Loading variables from ${SENTRY_ROOT}/.env"
dotenv "${SENTRY_ROOT}/.env"
if [ -f "${PWD}/.env" ]; then
info "Loading variables from ${PWD}/.env"
dotenv "${PWD}/.env"
fi

## Notify of reporting to Sentry
Expand Down Expand Up @@ -143,32 +148,11 @@ make setup-git-config

### Python ###

if [ -f .venv/bin/devenv ]; then
DEVENV=.venv/bin/devenv
else
DEVENV=devenv
fi

export SENTRY_DEVENV_HOME="${SENTRY_DEVENV_HOME:-$XDG_DATA_HOME/sentry-devenv}"
PATH_add "${SENTRY_DEVENV_HOME}/bin"
if ! command -v "$DEVENV" >/dev/null; then
die '
Please install the devenv tool:
https://github.com/getsentry/devenv#install
'
fi

PATH_add .venv/bin
export VIRTUAL_ENV="$PWD/.venv"

if ! require sentry; then
warn "Your virtualenv is activated, but sentry doesn't seem to be installed."
warn "Sentry doesn't seem to be installed."
commands_to_run+=("devenv sync")
fi

# this is the standard repo-local bin root
PATH_add "${PWD}/.devenv/bin"

### pre-commit ###

debug "Checking pre-commit..."
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ build-platform-assets \
direnv-help \
upgrade-pip \
setup-git-config :
@SENTRY_NO_VENV_CHECK=1 ./scripts/do.sh $@
@./scripts/do.sh $@

build-js-po: node-version-check
mkdir -p build
Expand Down
21 changes: 17 additions & 4 deletions scripts/do.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@
# This script is an interface to any of the methods of lib.sh
# Call this script as "do.sh method_from_lib" to execute any function from that library
set -eu

HERE="$(
cd "$(dirname "${BASH_SOURCE[0]}")"
pwd -P
)"

if ! command -v devenv >/dev/null 2>&1; then
echo '
Please install the devenv tool:
https://github.com/getsentry/devenv#install
'
exit 1
fi

if ! [[ "$VIRTUAL_ENV" -ef "${HERE}/../.venv" ]]; then
echo "
Your virtualenv isn't activated. You need to successfully run 'direnv allow'.
"
exit 1
fi

# shellcheck disable=SC1090
source "${HERE}/lib.sh"

# This guarantees that we're within a venv. A caller that is not within
# a venv can avoid enabling this by setting SENTRY_NO_VENV_CHECK
[ -z "${SENTRY_NO_VENV_CHECK+x}" ] && eval "${HERE}/ensure-venv.sh"
# If you call this script
"$@"
39 changes: 0 additions & 39 deletions scripts/ensure-venv.sh

This file was deleted.

40 changes: 0 additions & 40 deletions scripts/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ if [ -z "${CI+x}" ]; then
reset="$(tput sgr0)"
fi

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}"
Expand All @@ -28,48 +26,10 @@ 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
require() {
command -v "$1" >/dev/null 2>&1
}

query-valid-python-version() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might still be useful -- I think there's still ways people can manually get out of sync ?

python_version=$(python3 -V 2>&1 | awk '{print $2}')
if [[ -n "${SENTRY_PYTHON_VERSION:-}" ]]; then
if [ "$python_version" != "$SENTRY_PYTHON_VERSION" ]; then
cat <<EOF
${red}${bold}
ERROR: You have explicitly set a non-recommended Python version (${SENTRY_PYTHON_VERSION}),
but it doesn't match the value of python's version: ${python_version}
You should create a new ${SENTRY_PYTHON_VERSION} virtualenv by running "rm -rf ${venv_name} && direnv allow".
${reset}
EOF
return 1
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
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 11 ] || [ "$patch" -lt 6 ]; then
cat <<EOF
${red}${bold}
ERROR: You're running a virtualenv with Python ${python_version}.
We only support >= 3.11.6, < 3.12.
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
fi
fi
}

sudo-askpass() {
if [ -z "${sudo-askpass-x}" ]; then
sudo --askpass "$@"
Expand Down