Debian Codegraph @

script/run-in-env.sh

raw
1 #!/usr/bin/env sh
2 set -eu
3
4 # Used in venv activate script.
5 # Would be an error if undefined.
6 OSTYPE="${OSTYPE-}"
7
8 # Activate pyenv and virtualenv if present, then run the specified command
9
10 # pyenv, pyenv-virtualenv
11 if [ -s .python-version ]; then
12 PYENV_VERSION=$(head -n 1 .python-version)
13 export PYENV_VERSION
14 fi
15
16 # shellcheck source=/dev/null
17 if [ -n "${VIRTUAL_ENV-}" ] && [ -f "${VIRTUAL_ENV}/bin/activate" ]; then
18 # shellcheck source=/dev/null
19 . "${VIRTUAL_ENV}/bin/activate"
20 else
21 # other common virtualenvs
22 my_path=$(git rev-parse --show-toplevel)
23
24 for venv in venv .venv .; do
25 if [ -f "${my_path}/${venv}/bin/activate" ]; then
26 . "${my_path}/${venv}/bin/activate"
27 break
28 fi
29 done
30 fi
31
32 exec "$@"