Skip to content

Commit 3e9c261

Browse files
SYS-8273 catch more window cases, add python and python 3 cases and test with import sys and add error if not found
1 parent b255ac3 commit 3e9c261

3 files changed

Lines changed: 61 additions & 28 deletions

File tree

main/commit-msg

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
#!/usr/bin/env bash
2-
me=`basename "$0"`
2+
me=$(basename "$0")
33

44
case "$OSTYPE" in
5-
msys)
6-
echo "Running ${me} in MinGW"
7-
PYTHON_EXECUTABLE=python
8-
;;
5+
msys*|mingw*|cygwin*|win32*)
6+
echo "Running ${me} on Windows"
7+
if command -v python3 >/dev/null 2>&1 && python3 -c "import sys" >/dev/null 2>&1; then
8+
PYTHON_EXECUTABLE=(python3)
9+
elif command -v python >/dev/null 2>&1 && python -c "import sys" >/dev/null 2>&1; then
10+
PYTHON_EXECUTABLE=(python)
11+
else
12+
echo "Error: Python not found or not runnable"
13+
exit 1
14+
fi
15+
;;
916
*)
1017
echo "Running ${me} on linux / mac / unix"
11-
if command -v python3 > /dev/null 2>&1; then
12-
PYTHON_EXECUTABLE=python3
18+
if command -v python3 >/dev/null 2>&1 && python3 -c "import sys" >/dev/null 2>&1; then
19+
PYTHON_EXECUTABLE=(python3)
20+
elif command -v python >/dev/null 2>&1 && python -c "import sys" >/dev/null 2>&1; then
21+
PYTHON_EXECUTABLE=(python)
1322
else
14-
PYTHON_EXECUTABLE=python
23+
echo "Error: Python not found or not runnable"
24+
exit 1
1525
fi
26+
;;
1627
esac
1728

18-
${PYTHON_EXECUTABLE} "${BASH_SOURCE[0]%.*}.py" "$@"
29+
"${PYTHON_EXECUTABLE[@]}" "${BASH_SOURCE[0]%.*}.py" "$@"

main/pre-commit

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
#!/usr/bin/env bash
2-
me=`basename "$0"`
2+
me=$(basename "$0")
33

44
case "$OSTYPE" in
5-
msys)
6-
echo "Running ${me} in MinGW"
7-
PYTHON_EXECUTABLE=python
8-
;;
5+
msys*|mingw*|cygwin*|win32*)
6+
echo "Running ${me} on Windows"
7+
if command -v python3 >/dev/null 2>&1 && python3 -c "import sys" >/dev/null 2>&1; then
8+
PYTHON_EXECUTABLE=(python3)
9+
elif command -v python >/dev/null 2>&1 && python -c "import sys" >/dev/null 2>&1; then
10+
PYTHON_EXECUTABLE=(python)
11+
else
12+
echo "Error: Python not found or not runnable"
13+
exit 1
14+
fi
15+
;;
916
*)
1017
echo "Running ${me} on linux / mac / unix"
11-
if command -v python3 > /dev/null 2>&1; then
12-
PYTHON_EXECUTABLE=python3
18+
if command -v python3 >/dev/null 2>&1 && python3 -c "import sys" >/dev/null 2>&1; then
19+
PYTHON_EXECUTABLE=(python3)
20+
elif command -v python >/dev/null 2>&1 && python -c "import sys" >/dev/null 2>&1; then
21+
PYTHON_EXECUTABLE=(python)
1322
else
14-
PYTHON_EXECUTABLE=python
23+
echo "Error: Python not found or not runnable"
24+
exit 1
1525
fi
26+
;;
1627
esac
1728

18-
${PYTHON_EXECUTABLE} "${BASH_SOURCE[0]%.*}.py" "$@"
29+
"${PYTHON_EXECUTABLE[@]}" "${BASH_SOURCE[0]%.*}.py" "$@"

main/pre-merge-commit

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
#!/usr/bin/env bash
2-
me=`basename "$0"`
2+
me=$(basename "$0")
33

44
case "$OSTYPE" in
5-
msys)
6-
echo "Running ${me} in MinGW"
7-
PYTHON_EXECUTABLE=python
8-
;;
5+
msys*|mingw*|cygwin*|win32*)
6+
echo "Running ${me} on Windows"
7+
if command -v python3 >/dev/null 2>&1 && python3 -c "import sys" >/dev/null 2>&1; then
8+
PYTHON_EXECUTABLE=(python3)
9+
elif command -v python >/dev/null 2>&1 && python -c "import sys" >/dev/null 2>&1; then
10+
PYTHON_EXECUTABLE=(python)
11+
else
12+
echo "Error: Python not found or not runnable"
13+
exit 1
14+
fi
15+
;;
916
*)
10-
echo "Running ${me} linux / mac / unix"
11-
if command -v python3 > /dev/null 2>&1; then
12-
PYTHON_EXECUTABLE=python3
17+
echo "Running ${me} on linux / mac / unix"
18+
if command -v python3 >/dev/null 2>&1 && python3 -c "import sys" >/dev/null 2>&1; then
19+
PYTHON_EXECUTABLE=(python3)
20+
elif command -v python >/dev/null 2>&1 && python -c "import sys" >/dev/null 2>&1; then
21+
PYTHON_EXECUTABLE=(python)
1322
else
14-
PYTHON_EXECUTABLE=python
23+
echo "Error: Python not found or not runnable"
24+
exit 1
1525
fi
26+
;;
1627
esac
1728

18-
${PYTHON_EXECUTABLE} "${BASH_SOURCE[0]%.*}.py" "$@"
29+
"${PYTHON_EXECUTABLE[@]}" "${BASH_SOURCE[0]%.*}.py" "$@"

0 commit comments

Comments
 (0)