Skip to content

Commit a5422d2

Browse files
committed
ci: test: Install Python packages under virtual environment
This commit updates the CI workflow distribution bundle test job to create a Python virtual environment and install the Python packages required by the checked out Zephyr codebase in it. Installing the Python packages in a virtual environment provides a complete isolation from the runner host environment and prevents any potential version incompatibilities and conflicts with the pre- installed packages in the runner. Note that Python virtual environment is not used for Linux because the Linux build environment uses the CI Docker image that already has all the required dependencies pre-installed. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent fd5b33a commit a5422d2

File tree

1 file changed

+58
-19
lines changed

1 file changed

+58
-19
lines changed

.github/workflows/ci.yml

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,6 @@ jobs:
12331233

12341234
env:
12351235
SUBSET_COUNT: 2
1236-
PYTHON_DEPS: https://raw.githubusercontent.com/zephyrproject-rtos/zephyr/main/scripts/requirements.txt
12371236
ZEPHYR_TOOLCHAIN_VARIANT: zephyr
12381237

12391238
steps:
@@ -1275,15 +1274,6 @@ jobs:
12751274
brew install ccache coreutils dos2unix dtc gperf jq ninja wget
12761275
fi
12771276
1278-
# Upgrade pip
1279-
sudo python3 -m pip install --upgrade pip
1280-
1281-
# Install west
1282-
sudo pip3 install --upgrade west
1283-
1284-
# Install required Python packages
1285-
sudo pip3 install --upgrade -r "${{ env.PYTHON_DEPS }}"
1286-
12871277
# Set environment variables
12881278
echo "TAR=gtar" >> $GITHUB_ENV
12891279
echo "ARTIFACT_ROOT=${GITHUB_WORKSPACE}/artifacts" >> $GITHUB_ENV
@@ -1299,21 +1289,38 @@ jobs:
12991289
# Install required system packages
13001290
choco install ccache dtc-msys2 gperf jq ninja wget 7zip
13011291
1302-
# Upgrade pip
1303-
python3 -m pip install --upgrade pip
1304-
1305-
# Install west
1306-
pip3 install --upgrade west
1307-
1308-
# Install required Python packages
1309-
pip3 install --upgrade -r "${{ env.PYTHON_DEPS }}"
1310-
13111292
# Enable long paths support for Git
13121293
git config --system core.longpaths true
13131294
13141295
# Set environment variables
13151296
echo "ARTIFACT_ROOT=${GITHUB_WORKSPACE}/artifacts" >> $GITHUB_ENV
13161297
1298+
- name: Create Python virtual environment
1299+
if: ${{ runner.os != 'Linux' }}
1300+
run: |
1301+
# Create Python virtual environment
1302+
python3 -m venv ${GITHUB_WORKSPACE}/venv
1303+
1304+
# Resolve activation script path
1305+
if [ "${{ runner.os }}" == "Windows" ]; then
1306+
VENV_ACTIVATE="${GITHUB_WORKSPACE}/venv/Scripts/activate"
1307+
else
1308+
VENV_ACTIVATE="${GITHUB_WORKSPACE}/venv/bin/activate"
1309+
fi
1310+
1311+
# Test Python virtual environment
1312+
source ${VENV_ACTIVATE}
1313+
which python3
1314+
which pip3
1315+
1316+
# Install core components
1317+
python3 -m pip install --upgrade pip
1318+
pip3 install --upgrade setuptools wheel
1319+
1320+
# Set environment variables
1321+
echo "VENV=${GITHUB_WORKSPACE}/venv" >> $GITHUB_ENV
1322+
echo "VENV_ACTIVATE=${VENV_ACTIVATE}" >> $GITHUB_ENV
1323+
13171324
- name: Download version information
13181325
uses: actions/download-artifact@v3
13191326
with:
@@ -1379,8 +1386,23 @@ jobs:
13791386
13801387
popd
13811388
1389+
- name: Install west
1390+
run: |
1391+
# Activate Python virtual environment
1392+
if [ ! -z "${VENV_ACTIVATE}" ]; then
1393+
source ${VENV_ACTIVATE}
1394+
fi
1395+
1396+
# Install or upgrade west
1397+
pip3 install --upgrade west
1398+
13821399
- name: Set up Zephyr repository
13831400
run: |
1401+
# Activate Python virtual environment
1402+
if [ ! -z "${VENV_ACTIVATE}" ]; then
1403+
source ${VENV_ACTIVATE}
1404+
fi
1405+
13841406
# Create Zephyr workspace
13851407
ZEPHYR_WORKSPACE=${GITHUB_WORKSPACE}/zephyrproject
13861408
west init ${ZEPHYR_WORKSPACE}
@@ -1406,8 +1428,25 @@ jobs:
14061428
echo "ZEPHYR_WORKSPACE=${ZEPHYR_WORKSPACE}" >> $GITHUB_ENV
14071429
echo "ZEPHYR_ROOT=${ZEPHYR_WORKSPACE}/zephyr" >> $GITHUB_ENV
14081430
1431+
- name: Install Python dependencies
1432+
run: |
1433+
# Activate Python virtual environment
1434+
if [ ! -z "${VENV_ACTIVATE}" ]; then
1435+
source ${VENV_ACTIVATE}
1436+
1437+
# Install Python dependencies from the checked out Zephyr repository
1438+
# if running inside a virtual environment; otherwise, it is assumed
1439+
# that the host already provides all the required dependencies.
1440+
pip3 install -r ${ZEPHYR_ROOT}/scripts/requirements.txt
1441+
fi
1442+
14091443
- name: Run test suites
14101444
run: |
1445+
# Activate Python virtual environment
1446+
if [ ! -z "${VENV_ACTIVATE}" ]; then
1447+
source ${VENV_ACTIVATE}
1448+
fi
1449+
14111450
# Create working directory
14121451
mkdir -p test
14131452
cd test

0 commit comments

Comments
 (0)