Skip to content

Commit

Permalink
Check expect Python version loaded in test scripts (#26369)
Browse files Browse the repository at this point in the history
Add a check to Python version-pinned test scripts that the expected
version of Python was loaded.

This is analogous to what we already do for LLVM version-pinned tests.

While here, also remove the unused Python 2.7 test script.

Resolves https://github.com/Cray/chapel-private/issues/3717.

[reviewed by @lydia-duncan , thanks!]

Testing:
- [x] manual run of each Python test script gets past check
- [x] error emitted as expected for wrong Python version
  • Loading branch information
riftEmber authored Dec 16, 2024
2 parents 5cf6bdc + 4bd409f commit 72d810c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 46 deletions.
46 changes: 17 additions & 29 deletions util/cron/common-python.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,15 @@

# a helper function to select python versions before running `nightly` but
# *after* sourcing other `common*.bash`
function set_python_version() {
function set_and_check_python_version() {
local ver_str=$1

# make sure the length is OK
if [[ ${#ver_str} -lt 3 ]] || [[ ${#ver_str} -gt 4 ]]; then
echo "Python version string must be in format 'x.y[z]'"
return 1
fi

# make sure the 2nd char is "."
if [[ "${ver_str:1:1}" != "." ]]; then
echo "Python version string must be in format 'x.y[z]'"
return 1
fi

local major_ver=${ver_str:0:1}
local minor_ver=${ver_str:2}
local major_ver=$(echo $ver_str | cut -d. -f1)
local minor_ver=$(echo $ver_str | cut -d. -f2)

# override `python`
export PATH=/hpcdc/project/chapel/no-python:$PATH

if [[ $major_ver -eq 2 ]]; then
# Do some special casing for python2:
# 1. Avoid using chpl_make.py and other python scripts as much as possible
# 2. Override `python3`

export CHPL_NIGHTLY_MAKE=gmake
export PATH=/hpcdc/project/chapel/no-python3:$PATH
fi

local setup_script="/hpcdc/project/chapel/setup_python$major_ver$minor_ver.bash"

if [[ -f "${setup_script}" ]] ; then
Expand All @@ -41,11 +20,20 @@ function set_python_version() {
return 1
fi

if [[ $major_ver -eq 2 ]]; then
echo "Using $(python2 --version 2>&1)"
else
echo "Using $(python3 --version)"
fi
check_python_version $ver_str

echo "Using $(python3 --version)"
}

# Check correct Python version loaded, exiting with error if not
function check_python_version() {
local expected_python_version=$1

local actual_python_version=$(python3 --version | cut -d' ' -f2)

if [ "$actual_python_version" != "$expected_python_version" ]; then
echo "Wrong Python version"
echo "Expected Version: $expected_python_version. Actual Version: $actual_python_version"
exit 2
fi
}
13 changes: 0 additions & 13 deletions util/cron/test-linux64-python27.bash

This file was deleted.

2 changes: 1 addition & 1 deletion util/cron/test-linux64-python35.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ source $UTIL_CRON_DIR/common-python.bash

export CHPL_NIGHTLY_TEST_CONFIG_NAME="linux64-python35"

set_python_version "3.5"
set_and_check_python_version "3.5.2"

$UTIL_CRON_DIR/nightly -cron -pythonDep ${nightly_args}
2 changes: 1 addition & 1 deletion util/cron/test-linux64-python36.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ source $UTIL_CRON_DIR/common-python.bash

export CHPL_NIGHTLY_TEST_CONFIG_NAME="linux64-python36"

set_python_version "3.6"
set_and_check_python_version "3.6.10"

$UTIL_CRON_DIR/nightly -cron -pythonDep ${nightly_args}
2 changes: 1 addition & 1 deletion util/cron/test-linux64-python37.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ source $UTIL_CRON_DIR/common-python.bash

export CHPL_NIGHTLY_TEST_CONFIG_NAME="linux64-python37"

set_python_version "3.7"
set_and_check_python_version "3.7.9"

$UTIL_CRON_DIR/nightly -cron -pythonDep ${nightly_args}
2 changes: 1 addition & 1 deletion util/cron/test-linux64-python39.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ source $UTIL_CRON_DIR/common-python.bash

export CHPL_NIGHTLY_TEST_CONFIG_NAME="linux64-python39"

set_python_version "3.9"
set_and_check_python_version "3.9.13"

$UTIL_CRON_DIR/nightly -cron -hellos ${nightly_args}

0 comments on commit 72d810c

Please sign in to comment.