git-hooks: Not all OSes ship Python 3 under "python"

macOS doesn't, for instance. Use a shell script to detect which python
to run, which is always available on all OSes due to how git is
packaged on Windows.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5060>
This commit is contained in:
Nirbheek Chauhan 2023-07-18 22:06:32 +05:30 committed by GStreamer Marge Bot
parent 5943f9d669
commit fcf590a86e
3 changed files with 14 additions and 2 deletions

View file

@ -15,7 +15,7 @@
# commit. They are executed in the order in which they are listed. # commit. They are executed in the order in which they are listed.
########################################################### ###########################################################
HOOKS="scripts/git-hooks/pre-commit.hook scripts/git-hooks/pre-commit-python.hook" HOOKS="scripts/git-hooks/pre-commit.hook scripts/git-hooks/pre-commit-invoke-python.hook"
# exit on error # exit on error
set -e set -e

View file

@ -0,0 +1,12 @@
#!/bin/sh
PYTHON="python3"
if [[ $OS =~ Windows ]]; then
if type -p py &>/dev/null; then
PYTHON="py -3"
elif type -p python &>/dev/null; then
PYTHON="python"
fi
fi
$PYTHON "`dirname $0`/pre-commit-python.hook"

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import os import os
import subprocess import subprocess
import sys import sys