-
Notifications
You must be signed in to change notification settings - Fork 0
/
.envrc
46 lines (40 loc) · 1.02 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
#!/bin/bash
use_python() {
if [ -n "$(which pyenv)" ]; then
local pyversion=$1
pyenv local ${pyversion}
fi
}
layout_virtualenv() {
local pyversion=$1
local pvenv=$2
if [ -n "$(which pyenv-virtualenv)" ]; then
pyenv virtualenv --force --quiet ${pyversion} ${pvenv}-${pyversion}
fi
}
layout_activate() {
if [ -n "$(which pyenv)" ]; then
local pyenvprefix=$(pyenv prefix)
local pyversion=$(pyenv version-name)
local pvenv="$1"
source ${pyenvprefix}/envs/${pvenv}-${pyversion}/bin/activate
fi
}
if [ -f ".python-version" ]; then
echo "Reading .python-version..."
py_ver=$(head .python-version)
use python ${py_ver}
pyenv shell ${py_ver}
fi
if [ -f ".python-virtualenv" ]; then
echo "Reading .python-virtualenv..."
py_venv=$(head .python-virtualenv)
venv_name="${py_venv}-${py_ver}"
count=$(pyenv virtualenvs | grep "$venv_name" | wc -l)
if [ "$count" == 0 ]; then
layout virtualenv ${py_ver} ${py_venv}
layout activate ${py_venv}
else
layout activate ${py_venv}
fi
fi