-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdirenvrc
91 lines (79 loc) · 2.18 KB
/
direnvrc
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
# required for things to work - copied directly from direnv
direnv_layout_dir() {
echo "${direnv_layout_dir:-$PWD/.direnv}"
}
########## https://github.com/direnv/direnv/pull/376
# Usage: layout virtualenv [options] [-- [virtualenv-options]]
# opts]
#
# Creates and loads a virtualenv environment under
# "$direnv_layout_dir/python-$python_version".
# This forces the installation of any egg into the project's sub-folder.
#
# Options:
# -v <virtualenv-bin>: specifies the name of the virtualenv executable (default: virtualenv)
# -p <python-bin>: specifies the name of the python executable (default: python)
layout_virtualenv() {
local opt
local python_bin=python
local python_version
local virtualenv_bin=virtualenv
while getopts ":p:v:" opt; do
case "${opt}" in
p)
python_bin=${OPTARG}
;;
v)
virtualenv_bin=${OPTARG}
;;
*)
log_error "unknown option ${opt}"
echo
echo "Usage: layout virtualenv [-p PYTHON_BIN] [-v VIRTUALENV_BIN]"
return 1
;;
esac
done
shift $((OPTIND - 1))
##
unset PYTHONHOME # why?
python_version=$("$python_bin" -c "import platform as p;print(p.python_version())")
if [[ -z $python_version ]]; then
log_error "Could not find python's version"
return 1
fi
export VIRTUAL_ENV=$(direnv_layout_dir)/python-$python_version
PATH_add "$VIRTUAL_ENV/bin"
# auto-create
if [[ ! -d $VIRTUAL_ENV ]]; then
"$virtualenv_bin" "--python=$python_bin" "$@" "$VIRTUAL_ENV"
fi
}
# Usage: layout python <python_exe>
#
# Creates and loads a virtualenv environment under
# "$direnv_layout_dir/python-$python_version".
# This forces the installation of any egg into the project's sub-folder.
#
# It's possible to specify the python executable if you want to use different
# versions of python.
#
layout_python() {
local python=${1:-python}
[[ $# -gt 0 ]] && shift
layout_virtualenv -p $python "$@"
}
# Usage: layout python2
#
# A shortcut for $(layout virtualenv -p python2)
#
layout_python2() {
layout_virtualenv -p python2 "$@"
}
# Usage: layout python3
#
# A shortcut for $(layout virtualenv -p python3)
#
layout_python3() {
layout_virtualenv -p python3 "$@"
}