This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcreate_devel_venv.sh
executable file
·161 lines (135 loc) · 3.53 KB
/
create_devel_venv.sh
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env bash
PYVERSION="3"
INSTALL_JUP_KERNEL=0
PIPENV_EXTRAS=''
BOOTLOADER_ARCH="Linux-32bit-arm"
REQUIRED_PY=( "pipenv" )
# GCC Flags required for building RPi.GPIO v0.7.0 wheels
# see: https://askubuntu.com/a/1330210/903142
export CFLAGS=-fcommon
# Source external file for apt packages
source cd_apt_packages # provides REQUIRED_DEB
function do_exit {
echo "exiting script $0"
echo "reason: $1"
exit 1
}
function check_env {
# check that base python packages are installed
halt=0
echo "checking python environment"
echo ""
for i in "${REQUIRED_PY[@]}"
do
echo "VERIFYING PYTHON PACKAGE: $i"
if ! command -v $i &> /dev/null
then
echo "PYTHON PACKAGE $i NOT INSTALLED. Install with:"
echo "$ pip3 install $i"
halt=$((halt+1))
else
echo "$i ... OK"
fi
done
if [[ $halt -gt 0 ]]
then
echo "$halt required python packages missing. See messages above."
do_exit "stopping."
fi
}
function check_packages {
halt=0
echo "checking for required debian packages"
echo ""
for i in "${REQUIRED_DEB[@]}"
do
echo "VERIFYING DEB PACKAGE: $i"
if [ $(dpkg-query -W -f='${Status}' $i | grep -c "ok installed") -eq 0 ]
then
echo "PACKAGE $i NOT INSTALLED. Install with:"
echo "$ sudo apt install $i"
echo ""
halt=$((halt+1))
else
echo "$i ... OK"
echo ""
fi
done
if [[ $halt -gt 0 ]]
then
echo "$halt critical pakcages missing. See previous messages above."
do_exit "stopping."
fi
}
function build_pipenv {
echo ""
echo "checking pipenv virtual environment"
PIPVENV=$(pipenv --venv)
if [[ -z $PIPVENV ]];
then
echo "creating pip virtual environment"
pipenv --python $PYVERSION || do_exit "failed to create pipenv"
PIPVENV=$(pipenv --venv)
else
echo "virtual env: $PIPVENV"
#do_exit "virtual environment already exists"
fi
pipenv install --skip-lock || do_exit "failed to install modules"
if [[ $INSTALL_JUP_KERNEL -gt 0 ]];
then
echo "installing jupyter kernel"
PROJECT_DIR=$(basename $PIPVENV)
pipenv run python -m ipykernel install --user --name=${PROJECT_DIR} || do_exit "failed to install jupyter kernel"
MY_IP=$(hostname -I | cut -d " " -f 1)
echo "to start a remotely accessible jupyter notebook use:"
echo "$ jupyter notebook --ip=$MY_IP --no-browser"
fi
}
function check_bootloader {
VENV=$(pipenv --venv)
BOOTLOADER=$(find $VENV -path "*/PyInstaller/bootloader")
echo "checking for PyInstaller bootloader: $BOOTLOADER_ARCH"
if [[ -d $BOOTLOADER/$BOOTLOADER_ARCH ]];
then
echo "PyInstaller bootloader found -- no action needed"
else
echo "PyInstaller bootloader not found for $BOOTLOADER_ARCH"
echo "to create build PyInstaller files you must run the following commands:"
echo "$ pipenv shell"
echo "$ ./add_bootloader.sh"
fi
}
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]
do
case $1 in
-j|--jupyter)
JUPYTER_KERNEL=1
echo "Configuring Development Environment for Jupyter"
PIPENV_EXTRAS="$PIPENV_EXTRAS install ipykernel"
INSTALL_JUP_KERNEL=1
REQUIRED_PY+=("jupyter")
shift
shift
;;
-h|--help)
echo $ABOUT
echo "-j|--jupyter Setup Jupyter and install kernel for this project"
echo "-h|--help this help"
exit 1
;;
-*| --*)
echo "Unknown option: $1"
echo "try: $0 -h|--help"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done
check_packages
check_env
build_pipenv
check_bootloader