forked from mongodb/genny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-genny
executable file
Β·146 lines (120 loc) Β· 4.81 KB
/
run-genny
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
#!/usr/bin/env bash
set -eou pipefail
_pip() {
/usr/bin/env python3 -m pip "$@" --isolated -q -q
}
_genny_venv="genny_venv"
pushd "$(dirname "$0")" >/dev/null
GENNY_REPO_ROOT="$(pwd -P)"
export GENNY_REPO_ROOT
popd >/dev/null
if [ -d "/opt/mongodbtoolchain/v3/bin" ]; then
export PATH="/opt/mongodbtoolchain/v3/bin:$PATH"
fi
if [ -d "/Applications/Xcode10.1.app" ]; then
export DEVELOPER_DIR="/Applications/Xcode10.1.app"
fi
_HAVE_PRINTED_DIAGNOSTICS=
_print_diagnostics() {
if [ -n "$_HAVE_PRINTED_DIAGNOSTICS" ]; then
return
fi
echo >&2 "If you're stuck, please reach out to the #performance-tooling-users MongoDB slack channel and paste this output."
echo >&2 ""
echo >&2 " git rev-parse HEAD: $(git rev-parse HEAD)"
echo >&2 " uname -a: $(uname -a)"
echo >&2 " whoami: $(whoami)"
echo >&2 " command -v python3: $(command -v python3)"
echo >&2 " pwd: $(pwd)"
echo >&2 " PATH: $PATH"
echo >&2 ""
_HAVE_PRINTED_DIAGNOSTICS=1
}
if ! python3 -c 'import sys; sys.exit(1 if sys.version_info < (3, 7) else 0)' >/dev/null 2>&1; then
actual_version=$(python3 -c 'import sys; print(sys.version)')
echo >&2 "You must have python3.7+ installed."
echo >&2 "Detected version $actual_version."
echo >&2 ""
echo >&2 "On macOS you can run:"
echo >&2 ""
echo >&2 " brew install python3"
echo >&2 ""
_print_diagnostics
exit 1
fi
if [ -n "${VIRTUAL_ENV:-}" ] && [ "${VIRTUAL_ENV}" != "${GENNY_REPO_ROOT}/genny_venv" ]; then
echo >&2 "You are already inside a virtual environment $VIRTUAL_ENV."
echo >&2 "This can be problematic. Will try to proceed, but the operation may fail."
echo >&2 "If it does, please deactivate your existing virtualenv first:"
echo >&2 ""
echo >&2 " deactivate"
echo >&2 ""
_print_diagnostics
echo >&2 ""
fi
if which pyenv >/dev/null 2>&1; then
if pyenv version | grep system >/dev/null 2>&1; then
echo >&2 "You have system python setup through pyenv."
echo >&2 "pyenv version: $(pyenv version)"
echo >&2 ""
echo >&2 "This can be problematic. Will try to proceed, but the operation may fail."
echo >&2 "If it does, please change your python version by doing something like this:"
echo >&2 ""
echo >&2 " echo '3.7.0' > ~/.python-version"
echo >&2 " pyenv install"
echo >&2 ""
_print_diagnostics
fi
fi
if ! python3 -c 'import sys; sys.exit(1 if "Python3.framework" in sys.prefix else 0)' >/dev/null 2>&1; then
actual_prefix=$(python3 -c 'import sys; print(sys.prefix)')
echo >&2 "The python built into macOS Catalania is known to be problematic."
echo >&2 "It complains with 'architecture not supported' during setup."
echo >&2 "Detected system prefix: $actual_prefix"
echo >&2 ""
echo >&2 "On macOS you can run:"
echo >&2 ""
echo >&2 " brew install python3"
echo >&2 ""
_print_diagnostics
exit 1
fi
if ! _pip --version >/dev/null 2>&1; then
# ensurepip is built-in as of 3.4.
/usr/bin/env python3 -m ensurepip --upgrade
_pip install --upgrade pip
fi
if ! _pip --version >/dev/null 2>&1; then
echo >&2 "Your installation of python does not contain pip."
echo >&2 "On macOS you can run:"
echo >&2 ""
echo >&2 " brew install python3"
echo >&2 ""
echo >&2 "If this error persists, check that your PATH points to the correct python location."
_print_diagnostics
exit 1
fi
# Check for genny-setup-done-v2 which we create at the end of setup.
# This prevents half-setup environments.
if [[ ! -d "${GENNY_REPO_ROOT}/${_genny_venv}" || ! -e "${GENNY_REPO_ROOT}/${_genny_venv}/genny-setup-done-v2" ]]; then
rm -rf "${GENNY_REPO_ROOT:?}/${_genny_venv}"
python3 -m venv "${GENNY_REPO_ROOT}/${_genny_venv}"
export VIRTUAL_ENV_DISABLE_PROMPT=1 # prevent undefined $PS1 variable
# shellcheck source=/dev/null
source "${GENNY_REPO_ROOT}/${_genny_venv}/bin/activate"
# Install Genny requirements
_pip install -r "${GENNY_REPO_ROOT}/src/lamplib/requirements.txt"
_pip freeze > "pip-requirements.txt" 2>/dev/null
# Record that we've done setup at the current git sha.
# (Don't use the sha for now but might in the future to determine
# if we need to run pip install again or something.)
pushd "${GENNY_REPO_ROOT}" >/dev/null
git rev-parse HEAD > "${GENNY_REPO_ROOT}/${_genny_venv}/genny-setup-done-v2"
popd >/dev/null
fi
declare -a COMMAND
COMMAND=("$@")
export VIRTUAL_ENV_DISABLE_PROMPT=1 # prevent undefined $PS1 variable
# shellcheck source=/dev/null
source "${GENNY_REPO_ROOT}/${_genny_venv}/bin/activate"
PYTHONPATH="${GENNY_REPO_ROOT}/src/lamplib/src:${PYTHONPATH:-}" python3 "${GENNY_REPO_ROOT}/src/lamplib/src/genny/cli.py" "${COMMAND[@]:-}"