-
Notifications
You must be signed in to change notification settings - Fork 0
/
pup
executable file
·64 lines (54 loc) · 1.14 KB
/
pup
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
#!/usr/bin/env bash
PIP_COMMAND=$(which pip3 || which pip)
PYTHON_COMMAND=$(which python3 || which python)
WORKSPACE=$(pwd)
PUP_DIR=${WORKSPACE}/.pup
PUP_PACKAGES_DIR="${PUP_DIR}/packages"
PUP_BIN_DIR="${PUP_DIR}/bin"
PUP_CACHE="${HOME}/.pup_cache"
_create_dir_unless_exists() {
local dir=$1
if [ ! -d ${dir} ]
then
mkdir -p ${dir}
fi
}
_setup() {
_create_dir_unless_exists "${PUP_CACHE}"
_create_dir_unless_exists "${PUP_DIR}"
_create_dir_unless_exists "${PUP_PACKAGES_DIR}"
_create_dir_unless_exists "${PUP_BIN_DIR}"
}
install() {
"${PIP_COMMAND}" install \
--target="${PUP_PACKAGES_DIR}" \
--no-binary :all: \
--cache-dir ${PUP_CACHE} \
--install-option="--install-scripts=${PUP_BIN_DIR}" "${@}"
}
exec() {
local command=$1
shift
PYTHONPATH=${PUP_PACKAGES_DIR} "${PUP_BIN_DIR}/${command}" "${@}"
}
run() {
PYTHONPATH=${PUP_PACKAGES_DIR} "${PYTHON_COMMAND}" "${@}"
}
help() {
echo "Install or run Python packages"
}
command=$1
shift
_setup
if [[ "$command" == "install" ]]
then
install ${@}
elif [[ "$command" == "exec" ]]
then
exec ${@}
elif [[ "$command" == "run" ]]
then
run ${@}
else
help
fi