-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathverify-python-version.sh
executable file
·64 lines (53 loc) · 1.92 KB
/
verify-python-version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash -eu
RECOMMENDED_PYTHON_VERSION="3.9.10"
INSTALL_MESSAGE="We recommend using pyenv to install Python 3 and pip.
Follow the instructions on https://github.com/pyenv/pyenv-installer to install pyenv.
Then install Python 3:
$ pyenv install $RECOMMENDED_PYTHON_VERSION
$ pyenv local $RECOMMENDED_PYTHON_VERSION
Or, if you prefer to set the Python version globally:
$ pyenv global $RECOMMENDED_PYTHON_VERSION"
PYTHON_VERSION=$(python --version 2>&1 || true)
if $(echo "$PYTHON_VERSION" | grep -q -E 'python: (command )?not found'); then
echo "ERROR: Python is not installed."
echo
echo "$INSTALL_MESSAGE"
exit 1
fi
if $(echo "$PYTHON_VERSION" | grep -q -E -v "^Python "); then
echo "ERROR: failed to determine Python version, 'python --version' returned:"
echo " $PYTHON_VERSION"
echo
echo "$INSTALL_MESSAGE"
exit 1
fi
PYTHON_VERSION_NUMBER=$(echo "$PYTHON_VERSION" | sed -E 's/^Python (.+)$/\1/')
if $(echo "$PYTHON_VERSION_NUMBER" | grep -q -E -v '^3\.[6789]'); then
echo "ERROR: Unsupported Python version: $PYTHON_VERSION_NUMBER"
echo "plexiglass requires Python >= 3.6.0"
echo
echo "$INSTALL_MESSAGE"
exit 1
fi
PIP_VERSION=$(pip --version 2>&1 || true)
if $(echo "$PIP_VERSION" | grep -q -E 'pip: (command )?not found'); then
echo "ERROR: pip is not installed."
echo
echo "$INSTALL_MESSAGE"
exit 1
fi
if $(echo "$PIP_VERSION" | grep -q -E -v "pip .*python"); then
echo "ERROR: failed to determine pip version, 'pip --version' returned:"
echo " $PIP_VERSION"
echo
echo "$INSTALL_MESSAGE"
exit 1
fi
PIP_PYTHON_VERSION_NUMBER=$(echo "$PIP_VERSION" | sed -E 's/^pip.*\(python (.+)\)$/\1/')
if $(echo "$PIP_PYTHON_VERSION_NUMBER" | grep -q -E -v '^3\.[6789]'); then
echo "ERROR: Unsupported Python version in pip: $PIP_PYTHON_VERSION_NUMBER"
echo "plexiglass requires pip with Python >= 3.6.0"
echo
echo "$INSTALL_MESSAGE"
exit 1
fi