Skip to content

Commit f36a1cb

Browse files
committed
Enforce use of a virtual environment.
1 parent 01428ac commit f36a1cb

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

install.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ USAGE="./install.sh (--unstable)"
1010
POSITIONAL_ARGS=()
1111
FORCE=false
1212
UNSTABLE=false
13-
PYTHON="/usr/bin/python3"
13+
PYTHON="python"
1414

1515

16+
venv_check() {
17+
PYTHON_BIN=`which $PYTHON`
18+
if [[ $VIRTUAL_ENV == "" ]] || [[ $PYTHON_BIN != $VIRTUAL_ENV* ]]; then
19+
printf "This script should be run in a virtual Python environment.\n"
20+
exit 1
21+
fi
22+
}
23+
1624
user_check() {
1725
if [ $(id -u) -eq 0 ]; then
1826
printf "Script should not be run as root. Try './install.sh'\n"
@@ -126,6 +134,7 @@ while [[ $# -gt 0 ]]; do
126134
done
127135

128136
user_check
137+
venv_check
129138

130139
if [ ! -f "$PYTHON" ]; then
131140
printf "Python path $PYTHON not found!\n"
@@ -179,6 +188,7 @@ printf "It's recommended you run these steps manually.\n"
179188
printf "If you want to run the full script, open it in\n"
180189
printf "an editor and remove 'exit 1' from below.\n"
181190
exit 1
191+
source $VIRTUAL_ENV/bin/activate
182192
EOF
183193
184194
if $UNSTABLE; then

uninstall.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
FORCE=false
44
LIBRARY_NAME=`grep -m 1 name pyproject.toml | awk -F" = " '{print substr($2,2,length($2)-2)}'`
55
RESOURCES_DIR=$HOME/Pimoroni/$LIBRARY_NAME
6-
PYTHON="/usr/bin/python3"
6+
PYTHON="python"
7+
8+
9+
venv_check() {
10+
PYTHON_BIN=`which $PYTHON`
11+
if [[ $VIRTUAL_ENV == "" ]] || [[ $PYTHON_BIN != $VIRTUAL_ENV* ]]; then
12+
printf "This script should be run in a virtual Python environment.\n"
13+
exit 1
14+
fi
15+
}
716

817
user_check() {
918
if [ $(id -u) -eq 0 ]; then
@@ -49,6 +58,7 @@ warning() {
4958
printf "$LIBRARY_NAME Python Library: Uninstaller\n\n"
5059

5160
user_check
61+
venv_check
5262

5363
printf "Uninstalling for Python 3...\n"
5464
$PYTHON -m pip uninstall $LIBRARY_NAME

0 commit comments

Comments
 (0)