forked from getsentry/sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.envrc
216 lines (166 loc) · 5.78 KB
/
.envrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# 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
# initialization (e.g. activating the venv) or giving recommendations on how to reach the desired state.
# It also sets useful environment variables.
# If you'd like to override or set any custom environment variables, this .envrc will read a .env file at the end.
set -e
bold="$(tput bold)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
reset="$(tput sgr0)"
# 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.
# so need to use set -e, and return 1.
trap notice ERR
notice() {
[ $? -eq 0 ] && return
cat <<EOF
${red}${bold}direnv wasn't able to complete execution.
You may have been given some recommendations in the error message.
Follow them, and then you'll need to redo direnv by running "direnv allow".${reset}
direnv tooling is in an ALPHA state!
If you're having trouble, or have questions, please ask in #discuss-dev-tooling
and/or reach out to @josh.
EOF
}
require() {
command -v "$1" 2>&1 >/dev/null
}
warn() {
cat <<EOF
${yellow}${bold}direnv: ${@}${reset}
EOF
}
info() {
cat <<EOF
${bold}direnv: ${@}${reset}
EOF
}
die() {
cat >&2 <<EOF
${red}${bold}direnv FATAL: ${@}
${reset}
EOF
return 1
}
advice_init_venv() {
python_version="$1"
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.
It's recommended to use pyenv - please refer to https://docs.sentry.io/development/contribute/environment"
return 1
}
advice_install_sentry() {
info "To install sentry, please type: make install-py-dev"
return 1
}
advice_install_pre_commit() {
info "To install pre-commit, please type: make setup-git"
return 1
}
advice_install_yarn_pkgs() {
info "To install yarn packages, please type: make install-js-dev"
return 1
}
### Environment ###
# don't write *.pyc files; using stale python code occasionally causes subtle problems
export PYTHONDONTWRITEBYTECODE=1
# make sure we don't have any conflicting PYTHONPATH
unset PYTHONPATH
# don't check pypi for a potential new pip version; low-hanging fruit to save a bit of time
export PIP_DISABLE_PIP_VERSION_CHECK=on
# increase node's memory limit, required for our webpacking
export NODE_OPTIONS=--max-old-space-size=4096
### System ###
for pkg in \
make \
docker \
chromedriver \
pkg-config \
openssl; do
if ! require "$pkg"; then
die "You seem to be missing the system dependency: ${pkg}
Please install homebrew, and run brew bundle."
fi
done
### Git ###
info "Configuring git..."
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"
if [ "$SENTRY_PYTHON3" = "1" ]; then
venv_name=".venv3"
python_version="python3.6"
warn "Running in EXPERIMENTAL Python 3 mode... Good luck"
fi
info "Activating virtualenv..."
if [ ! -f "${venv_name}/bin/activate" ]; then
info "You don't seem to have a virtualenv."
advice_init_venv "$python_version" "$venv_name"
fi
# The user might be cd'ing into sentry with another non-direnv managed
# (in that it would be automatically deactivated) virtualenv active.
deactivate 2>/dev/null || true
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
unset PS1
# We're explicitly disallowing symlinked venvs (python would resolve to the canonical location)
if [ "$(command -v python)" != "${PWD}/${venv_name}/bin/python" ]; then
info "Failed to activate virtualenv. Your virtualenv's probably symlinked." \
"We want everyone to be on the same page here, so you'll have to recreate your virtualenv."
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
if [ "$(command -v sentry)" != "${PWD}/${venv_name}/bin/sentry" ]; then
info "Your virtual env 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
fi
### pre-commit ###
info "Checking pre-commit..."
if ! require pre-commit; then
info "Looks like you don't have pre-commit installed."
advice_install_pre_commit
fi
### Node ###
info "Checking node..."
if ! require node; then
die "You don't seem to have node installed. Install volta (a node version manager): https://develop.sentry.dev/environment/#javascript"
fi
make node-version-check
if [ ! -x "node_modules/.bin/webpack" ]; then
info "You don't seem to have yarn packages installed."
advice_install_yarn_pkgs
fi
PATH_add node_modules/.bin
### Overrides ###
if [ -f '.env' ]; then
info ".env found. Reading it..."
dotenv .env
fi
cat <<EOF
${green}${bold}direnv: SUCCESS!
${reset}
EOF
if [ ! -n "${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
and/or reach out to @josh.
EOF
fi