Skip to content

Commit e324191

Browse files
committed
CI: Factor out .ci/show_python_versions
1 parent 9b6fc11 commit e324191

File tree

2 files changed

+36
-68
lines changed

2 files changed

+36
-68
lines changed

.ci/show_python_versions

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
set -o errexit -o nounset -o pipefail
3+
4+
INDENT=" "
5+
POSSIBLE_PYTHONS=(
6+
python
7+
python2
8+
python3
9+
/usr/bin/python
10+
/usr/bin/python2
11+
/usr/bin/python3
12+
# GitHub macOS 12 images: python2.7 is installed, but not on $PATH
13+
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
14+
)
15+
16+
for p in "${POSSIBLE_PYTHONS[@]}"; do
17+
echo "$p"
18+
if [[ ${p:0:1} == "/" && -e $p ]]; then
19+
:
20+
elif type "$p" > /dev/null 2>&1; then
21+
type "$p" 2>&1 | sed -e "s/^/${INDENT}type: /"
22+
else
23+
echo "${INDENT}Not present"
24+
echo
25+
continue
26+
fi
27+
28+
$p -c "import sys; print('${INDENT}version: %d.%d.%d' % sys.version_info[:3])"
29+
# macOS builders lack a realpath command
30+
$p -c "import os.path; print('${INDENT}realpath: %s' % os.path.realpath('$(type -p "$p")'))"
31+
$p -c "import sys; print('${INDENT}sys.executable: %s' % sys.executable)"
32+
echo
33+
done

.github/workflows/tests.yml

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,7 @@ jobs:
6464
echo 1>&2 "Python interpreter $PYTHON not available"
6565
exit 1
6666
fi
67-
- name: Show Python versions
68-
run: |
69-
set -o errexit -o nounset -o pipefail
70-
71-
# macOS builders lack a realpath command
72-
type python && python -c"import os.path;print(os.path.realpath('$(type -p python)'))" && python --version
73-
type python2 && python2 -c"import os.path;print(os.path.realpath('$(type -p python2)'))" && python2 --version
74-
type python3 && python3 -c"import os.path;print(os.path.realpath('$(type -p python3)'))" && python3 --version
75-
echo
76-
77-
if [ -e /usr/bin/python ]; then
78-
echo "/usr/bin/python: sys.executable: $(/usr/bin/python -c 'import sys; print(sys.executable)')"
79-
fi
80-
81-
if [ -e /usr/bin/python2 ]; then
82-
echo "/usr/bin/python2: sys.executable: $(/usr/bin/python2 -c 'import sys; print(sys.executable)')"
83-
fi
84-
85-
if [ -e /usr/bin/python2.7 ]; then
86-
echo "/usr/bin/python2.7: sys.executable: $(/usr/bin/python2.7 -c 'import sys; print(sys.executable)')"
87-
fi
67+
- run: .ci/show_python_versions
8868
- name: Install tooling
8969
run: |
9070
set -o errexit -o nounset -o pipefail
@@ -186,27 +166,7 @@ jobs:
186166
187167
sudo apt-get update
188168
sudo apt-get install -y sshpass virtualenv
189-
- name: Show Python versions
190-
run: |
191-
set -o errexit -o nounset -o pipefail
192-
193-
# macOS builders lack a realpath command
194-
type python && python -c"import os.path;print(os.path.realpath('$(type -p python)'))" && python --version
195-
type python2 && python2 -c"import os.path;print(os.path.realpath('$(type -p python2)'))" && python2 --version
196-
type python3 && python3 -c"import os.path;print(os.path.realpath('$(type -p python3)'))" && python3 --version
197-
echo
198-
199-
if [ -e /usr/bin/python ]; then
200-
echo "/usr/bin/python: sys.executable: $(/usr/bin/python -c 'import sys; print(sys.executable)')"
201-
fi
202-
203-
if [ -e /usr/bin/python2 ]; then
204-
echo "/usr/bin/python2: sys.executable: $(/usr/bin/python2 -c 'import sys; print(sys.executable)')"
205-
fi
206-
207-
if [ -e /usr/bin/python2.7 ]; then
208-
echo "/usr/bin/python2.7: sys.executable: $(/usr/bin/python2.7 -c 'import sys; print(sys.executable)')"
209-
fi
169+
- run: .ci/show_python_versions
210170
- name: Install tooling
211171
run: |
212172
set -o errexit -o nounset -o pipefail
@@ -262,32 +222,7 @@ jobs:
262222
with:
263223
python-version: ${{ matrix.python_version }}
264224
if: ${{ matrix.python_version }}
265-
- name: Show Python versions
266-
run: |
267-
set -o errexit -o nounset -o pipefail
268-
269-
# macOS builders lack a realpath command
270-
type python && python -c"import os.path;print(os.path.realpath('$(type -p python)'))" && python --version
271-
type python2 && python2 -c"import os.path;print(os.path.realpath('$(type -p python2)'))" && python2 --version
272-
type python3 && python3 -c"import os.path;print(os.path.realpath('$(type -p python3)'))" && python3 --version
273-
echo
274-
275-
if [ -e /usr/bin/python ]; then
276-
echo "/usr/bin/python: sys.executable: $(/usr/bin/python -c 'import sys; print(sys.executable)')"
277-
fi
278-
279-
if [ -e /usr/bin/python2 ]; then
280-
echo "/usr/bin/python2: sys.executable: $(/usr/bin/python2 -c 'import sys; print(sys.executable)')"
281-
fi
282-
283-
if [ -e /usr/bin/python2.7 ]; then
284-
echo "/usr/bin/python2.7: sys.executable: $(/usr/bin/python2.7 -c 'import sys; print(sys.executable)')"
285-
fi
286-
287-
if [ -e /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 ]; then
288-
# GitHub macOS 12 images: python2.7 is installed, but not on $PATH
289-
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)')"
290-
fi
225+
- run: .ci/show_python_versions
291226
- run: .ci/install_sshpass ${{ matrix.sshpass_version }}
292227
if: ${{ matrix.sshpass_version }}
293228
- name: Install tooling

0 commit comments

Comments
 (0)