Skip to content

Commit d9710f7

Browse files
committed
Drop an auto venv script into ~/Pimoroni, update venv prompt
1 parent c8b2011 commit d9710f7

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

install.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ warning() {
5555
echo -e "$(tput setaf 1)$1$(tput sgr0)"
5656
}
5757

58+
venv_bash_snippet() {
59+
if [ ! -f $BASH_SNIPPET ]; then
60+
cat << EOF > $BASH_SNIPPET
61+
# Add `source $RESOURCES_DIR/auto_venv.sh` to your ~/.bashrc to activate
62+
# the Pimoroni virtual environment automagically!
63+
PY_ENV_DIR=~/Pimoroni/venv
64+
if [ ! -f \$PY_ENV_DIR/bin/activate ]; then
65+
printf "Creating user Python environment in \$PY_ENV_DIR, please wait...\n"
66+
mkdir -p \$PY_ENV_DIR
67+
python3 -m venv --system-site-packages --prompt Pimoroni \$PY_ENV_DIR
68+
fi
69+
printf " ↓ ↓ ↓ ↓ Hello, we've activated a Python venv for you. To exit, type \"deactivate\".\n"
70+
source \$PY_ENV_DIR/bin/activate
71+
EOF
72+
fi
73+
}
74+
5875
venv_check() {
5976
PYTHON_BIN=`which $PYTHON`
6077
if [[ $VIRTUAL_ENV == "" ]] || [[ $PYTHON_BIN != $VIRTUAL_ENV* ]]; then
@@ -63,7 +80,8 @@ venv_check() {
6380
if [ ! -f $PY_VENV_DIR/bin/activate ]; then
6481
inform "Creating virtual Python environment in $PY_VENV_DIR, please wait...\n"
6582
mkdir -p $PY_VENV_DIR
66-
/usr/bin/python3 -m venv $PY_VENV_DIR --system-site-packages
83+
/usr/bin/python3 -m venv $PY_VENV_DIR --system-site-packages --prompt Pimoroni
84+
venv_bash_snippet()
6785
else
6886
inform "Found existing virtual Python environment in $PY_VENV_DIR\n"
6987
fi
@@ -188,6 +206,7 @@ eval $CONFIG_VARS
188206
189207
RESOURCES_DIR=$RESOURCES_TOP_DIR/$LIBRARY_NAME
190208
UNINSTALLER=$RESOURCES_DIR/uninstall.sh
209+
BASH_SNIPPET=$RESOURCES_DIR/auto_venv.sh
191210
192211
RES_DIR_OWNER=`stat -c "%U" $RESOURCES_TOP_DIR`
193212

0 commit comments

Comments
 (0)