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 all 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
63 changes: 26 additions & 37 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@
# 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
fi

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

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

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

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

# SENTRY_ROOT must be used here, not PWD, since getsentry .envrc sources this .envrc.
source "${SENTRY_ROOT}/scripts/lib.sh"

# XXX: we can't trap bash EXIT, because it'll override direnv's finalizing routines.
Expand Down Expand Up @@ -101,9 +112,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 @@ -138,37 +149,15 @@ done
### Git ###

debug "Configuring git..."

make setup-git-config
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
25 changes: 12 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,31 @@ all: develop

PIP := python -m pip --disable-pip-version-check
WEBPACK := yarn build-acceptance
POSTGRES_CONTAINER := sentry_postgres

freeze-requirements:
@python3 -S -m tools.freeze_requirements

bootstrap \
develop \
install-js-dev \
install-py-dev \
apply-migrations: devenv-sync ;

# This is to ensure devenv sync's only called once if the above
# aliases are combined e.g. `make install-js-dev install-py-dev`
.PHONY: devenv-sync
devenv-sync:
devenv sync

build-platform-assets \
clean \
init-config \
run-dependent-services \
drop-db \
create-db \
apply-migrations \
reset-db \
setup-git \
node-version-check \
install-js-dev \
install-py-dev :
node-version-check :
@./scripts/do.sh $@

build-platform-assets \
direnv-help \
upgrade-pip \
setup-git-config :
@SENTRY_NO_VENV_CHECK=1 ./scripts/do.sh $@

build-js-po: node-version-check
mkdir -p build
rm -rf node_modules/.cache/babel-loader
Expand Down
88 changes: 80 additions & 8 deletions devenv/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def main(context: dict[str, str]) -> int:
repo = context["repo"]
reporoot = context["reporoot"]

# don't want this to be accidentally run from getsentry
assert repo == "sentry", repo

venv_dir, python_version, requirements, editable_paths, bins = venv.get(reporoot, repo)
url, sha256 = config.get_python(reporoot, python_version)
print(f"ensuring {repo} venv at {venv_dir}...")
Expand Down Expand Up @@ -112,8 +115,39 @@ def main(context: dict[str, str]) -> int:
reporoot,
venv_dir,
(
("javascript dependencies", ("make", "install-js-dev")),
("python dependencies", ("make", "install-py-dev")),
(
"javascript dependencies",
(
"bash",
"-euo",
"pipefail",
"-c",
"""
NODE_ENV=development ./.devenv/bin/yarn install --frozen-lockfile
yarn check --verify-tree || yarn install --check-files
""",
),
),
(
"python dependencies",
(
"bash",
"-euo",
"pipefail",
"-c",
"""
# install pinned pip
pip install --constraint requirements-dev-frozen.txt pip

# pip doesn't do well with swapping drop-ins
pip uninstall -qqy djangorestframework-stubs django-stubs

pip install -r requirements-dev-frozen.txt

python3 -m tools.fast_editable --path .
""",
),
),
),
):
return 1
Expand All @@ -136,12 +170,12 @@ def main(context: dict[str, str]) -> int:
if not os.path.exists(f"{constants.home}/.sentry/config.yml") or not os.path.exists(
f"{constants.home}/.sentry/sentry.conf.py"
):
proc.run((f"{venv_dir}/bin/sentry", "init", "--dev"))
proc.run((f"{venv_dir}/bin/sentry", "init", "--dev", "--no-clobber"))

# TODO: check healthchecks for redis and postgres to short circuit this
proc.run(
(
f"{venv_dir}/bin/{repo}",
f"{venv_dir}/bin/sentry",
"devservices",
"up",
"redis",
Expand All @@ -151,17 +185,55 @@ def main(context: dict[str, str]) -> int:
exit=True,
)

if run_procs(
if not run_procs(
repo,
reporoot,
venv_dir,
(
(
"python migrations",
("make", "apply-migrations"),
(
"bash",
"-euo",
"pipefail",
"-c",
"""
make create-db
sentry upgrade --noinput
""",
),
),
),
):
return 0
return 1

# Starting sentry is slow.
stdout = proc.run(
(
"docker",
"exec",
"sentry_postgres",
"psql",
"sentry",
"postgres",
"-t",
"-c",
"select exists (select from auth_user where email = 'admin@sentry.io')",
),
stdout=True,
)
if stdout != "t":
proc.run(
(
f"{venv_dir}/bin/sentry",
"createuser",
"--superuser",
"--email",
"admin@sentry.io",
"--password",
"admin",
"--no-input",
)
)

return 1
return 0
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 sentry 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.

Loading
Loading