From e3241912f727dbfde39bc1b95207ac96f4bd99d2 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Tue, 19 Aug 2025 12:08:42 +0100 Subject: [PATCH] CI: Factor out .ci/show_python_versions --- .ci/show_python_versions | 33 +++++++++++++++++ .github/workflows/tests.yml | 71 ++----------------------------------- 2 files changed, 36 insertions(+), 68 deletions(-) create mode 100755 .ci/show_python_versions diff --git a/.ci/show_python_versions b/.ci/show_python_versions new file mode 100755 index 00000000..ac219824 --- /dev/null +++ b/.ci/show_python_versions @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -o errexit -o nounset -o pipefail + +INDENT=" " +POSSIBLE_PYTHONS=( + python + python2 + python3 + /usr/bin/python + /usr/bin/python2 + /usr/bin/python3 + # GitHub macOS 12 images: python2.7 is installed, but not on $PATH + /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 +) + +for p in "${POSSIBLE_PYTHONS[@]}"; do + echo "$p" + if [[ ${p:0:1} == "/" && -e $p ]]; then + : + elif type "$p" > /dev/null 2>&1; then + type "$p" 2>&1 | sed -e "s/^/${INDENT}type: /" + else + echo "${INDENT}Not present" + echo + continue + fi + + $p -c "import sys; print('${INDENT}version: %d.%d.%d' % sys.version_info[:3])" + # macOS builders lack a realpath command + $p -c "import os.path; print('${INDENT}realpath: %s' % os.path.realpath('$(type -p "$p")'))" + $p -c "import sys; print('${INDENT}sys.executable: %s' % sys.executable)" + echo +done diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d4a14b66..507802d8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -64,27 +64,7 @@ jobs: echo 1>&2 "Python interpreter $PYTHON not available" exit 1 fi - - name: Show Python versions - run: | - set -o errexit -o nounset -o pipefail - - # macOS builders lack a realpath command - type python && python -c"import os.path;print(os.path.realpath('$(type -p python)'))" && python --version - type python2 && python2 -c"import os.path;print(os.path.realpath('$(type -p python2)'))" && python2 --version - type python3 && python3 -c"import os.path;print(os.path.realpath('$(type -p python3)'))" && python3 --version - echo - - if [ -e /usr/bin/python ]; then - echo "/usr/bin/python: sys.executable: $(/usr/bin/python -c 'import sys; print(sys.executable)')" - fi - - if [ -e /usr/bin/python2 ]; then - echo "/usr/bin/python2: sys.executable: $(/usr/bin/python2 -c 'import sys; print(sys.executable)')" - fi - - if [ -e /usr/bin/python2.7 ]; then - echo "/usr/bin/python2.7: sys.executable: $(/usr/bin/python2.7 -c 'import sys; print(sys.executable)')" - fi + - run: .ci/show_python_versions - name: Install tooling run: | set -o errexit -o nounset -o pipefail @@ -186,27 +166,7 @@ jobs: sudo apt-get update sudo apt-get install -y sshpass virtualenv - - name: Show Python versions - run: | - set -o errexit -o nounset -o pipefail - - # macOS builders lack a realpath command - type python && python -c"import os.path;print(os.path.realpath('$(type -p python)'))" && python --version - type python2 && python2 -c"import os.path;print(os.path.realpath('$(type -p python2)'))" && python2 --version - type python3 && python3 -c"import os.path;print(os.path.realpath('$(type -p python3)'))" && python3 --version - echo - - if [ -e /usr/bin/python ]; then - echo "/usr/bin/python: sys.executable: $(/usr/bin/python -c 'import sys; print(sys.executable)')" - fi - - if [ -e /usr/bin/python2 ]; then - echo "/usr/bin/python2: sys.executable: $(/usr/bin/python2 -c 'import sys; print(sys.executable)')" - fi - - if [ -e /usr/bin/python2.7 ]; then - echo "/usr/bin/python2.7: sys.executable: $(/usr/bin/python2.7 -c 'import sys; print(sys.executable)')" - fi + - run: .ci/show_python_versions - name: Install tooling run: | set -o errexit -o nounset -o pipefail @@ -262,32 +222,7 @@ jobs: with: python-version: ${{ matrix.python_version }} if: ${{ matrix.python_version }} - - name: Show Python versions - run: | - set -o errexit -o nounset -o pipefail - - # macOS builders lack a realpath command - type python && python -c"import os.path;print(os.path.realpath('$(type -p python)'))" && python --version - type python2 && python2 -c"import os.path;print(os.path.realpath('$(type -p python2)'))" && python2 --version - type python3 && python3 -c"import os.path;print(os.path.realpath('$(type -p python3)'))" && python3 --version - echo - - if [ -e /usr/bin/python ]; then - echo "/usr/bin/python: sys.executable: $(/usr/bin/python -c 'import sys; print(sys.executable)')" - fi - - if [ -e /usr/bin/python2 ]; then - echo "/usr/bin/python2: sys.executable: $(/usr/bin/python2 -c 'import sys; print(sys.executable)')" - fi - - if [ -e /usr/bin/python2.7 ]; then - echo "/usr/bin/python2.7: sys.executable: $(/usr/bin/python2.7 -c 'import sys; print(sys.executable)')" - fi - - if [ -e /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 ]; then - # GitHub macOS 12 images: python2.7 is installed, but not on $PATH - echo "/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7: sys.executable: $(/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 -c 'import sys; print(sys.executable)')" - fi + - run: .ci/show_python_versions - run: .ci/install_sshpass ${{ matrix.sshpass_version }} if: ${{ matrix.sshpass_version }} - name: Install tooling