Skip to content

Commit a9e33ee

Browse files
authored
add functionality to auto-activate venv (FujiNetWIFI#967)
* add functionality to auto-activate venv * add condition to check before running deactivate * fixes to feedback
1 parent 258c6d7 commit a9e33ee

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

build.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# CONFIGURATION INI FILE USAGE
77

88
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
9+
PIO_VENV_ROOT="${HOME}/.platformio/penv"
910

1011
BUILD_ALL=0
1112
RUN_BUILD=0
@@ -96,6 +97,7 @@ function show_help {
9697
echo "other options:"
9798
echo " -y # answers any questions with Y automatically, for unattended builds"
9899
echo " -h # this help"
100+
echo " -V # Override default Python virtual environment location (e.g. \"-V ~/.platformio/penv\")"
99101
echo ""
100102
echo "Additional Args can be accepted to pass values onto sub processes where supported."
101103
echo " e.g. ./build.sh -p APPLE -- -DFOO=BAR"
@@ -116,7 +118,7 @@ if [ $# -eq 0 ] ; then
116118
show_help
117119
fi
118120

119-
while getopts "abcde:fgG:hi:l:mnp:s:St:uyz" flag
121+
while getopts "abcde:fgG:hi:l:mnp:s:St:uyzV:" flag
120122
do
121123
case "$flag" in
122124
a) BUILD_ALL=1 ;;
@@ -138,6 +140,7 @@ do
138140
G) CMAKE_GENERATOR=${OPTARG} ;;
139141
y) ANSWER_YES=1 ;;
140142
z) ZIP_MODE=1 ;;
143+
V) PIO_VENV_ROOT=${OPTARG} ;;
141144
h) show_help ;;
142145
*) show_help ;;
143146
esac
@@ -156,6 +159,15 @@ if [ $BUILD_ALL -eq 1 ] ; then
156159
exit $?
157160
fi
158161

162+
# Set up the virtual environment if it exists
163+
if [[ -d "$PIO_VENV_ROOT" && "$VIRTUAL_ENV" != "$PIO_VENV_ROOT" ]] ; then
164+
echo "Activating virtual environment"
165+
[[ -z "$VIRTUAL_ENV" ]] && deactivate &>/dev/null
166+
source "$PIO_VENV_ROOT/bin/activate"
167+
else
168+
echo "Warning: Virtual environment not found in $PIO_VENV_ROOT. Continuing without it."
169+
fi
170+
159171
##############################################################
160172
# PC BUILD using cmake
161173
if [ ! -z "$PC_TARGET" ] ; then

0 commit comments

Comments
 (0)