Skip to content

Commit 04d856e

Browse files
hooks: pre-push: Add a python version check, with instructions
1 parent 231e245 commit 04d856e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

.hooks/pre-push

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
set -e
44

5+
# Check if the required Python version is available
6+
PYTHON_VERSION=$(grep -oP 'python\s*=\s*"[^0-9]*\K[0-9]+\.[0-9]+' pyproject.toml)
7+
command -v "python$PYTHON_VERSION" >/dev/null 2>&1 || {
8+
if [ "$(command -v pyenv)" ]; then
9+
echo "Pyenv is available, switching local Python version to $PYTHON_VERSION"
10+
pyenv install -fs "$PYTHON_VERSION"
11+
pyenv local "$PYTHON_VERSION"
12+
else
13+
cat >&2 <<EOF
14+
Python $PYTHON_VERSION is not available. Aborting.
15+
If your Linux distribution doesn't provide it, consider using Pyenv:
16+
1. Install Pyenv using your Linux distribution package manager
17+
2. Run the following commands:
18+
pyenv install $PYTHON_VERSION
19+
pyenv local $PYTHON_VERSION
20+
For more information about pyenv, please visit https://github.com/pyenv/pyenv#readme
21+
EOF
22+
exit 1
23+
fi
24+
}
25+
526
# Check if poetry is installed
627
command -v poetry >/dev/null 2>&1 || {
728
echo >&2 "poetry is not installed. Aborting. Please install it and try again."

0 commit comments

Comments
 (0)