Skip to content

Commit 2ca7d04

Browse files
Merge pull request #36 from ccdc-opensource/SYS-8273-fix-windows-commit
SYS-8273 confirm real python is being used instead of microsoft store python
2 parents 62e2405 + 7ec79a1 commit 2ca7d04

3 files changed

Lines changed: 51 additions & 24 deletions

File tree

main/commit-msg

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
#!/usr/bin/env bash
22
me=$(basename "$0")
33

4+
is_python3() {
5+
"$@" -c 'import sys; sys.exit(0 if sys.version_info[0] == 3 else 1)' >/dev/null 2>&1
6+
}
7+
48
case "$OSTYPE" in
59
msys*|mingw*|cygwin*|win32*)
610
echo "Running ${me} on Windows"
7-
if command -v python3 > /dev/null 2>&1; then
8-
PYTHON_EXECUTABLE=(python3)
9-
elif command -v python > /dev/null 2>&1; then
10-
PYTHON_EXECUTABLE=(python)
11+
if command -v py >/dev/null 2>&1 && is_python3 py -3; then
12+
PYTHON_EXECUTABLE=(py -3)
1113
else
12-
echo "Error: Python not found or not runnable"
13-
exit 1
14+
python3_path=$(command -v python3 2>/dev/null || true)
15+
if [ -n "$python3_path" ] && [[ "$python3_path" != *WindowsApps* ]] && is_python3 python3; then
16+
PYTHON_EXECUTABLE=(python3)
17+
elif command -v python >/dev/null 2>&1 && is_python3 python; then
18+
PYTHON_EXECUTABLE=(python)
19+
else
20+
echo "Error: Python 3 not found. Please install Python 3 or disable the Microsoft Store python alias."
21+
exit 1
22+
fi
1423
fi
1524
;;
1625
*)
1726
echo "Running ${me} on linux / mac / unix"
18-
if command -v python3 > /dev/null 2>&1; then
27+
if command -v python3 >/dev/null 2>&1 && is_python3 python3; then
1928
PYTHON_EXECUTABLE=(python3)
20-
elif command -v python > /dev/null 2>&1; then
29+
elif command -v python >/dev/null 2>&1 && is_python3 python; then
2130
PYTHON_EXECUTABLE=(python)
2231
else
2332
echo "Error: Python not found or not runnable"

main/pre-commit

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
#!/usr/bin/env bash
22
me=$(basename "$0")
33

4+
is_python3() {
5+
"$@" -c 'import sys; sys.exit(0 if sys.version_info[0] == 3 else 1)' >/dev/null 2>&1
6+
}
7+
48
case "$OSTYPE" in
59
msys*|mingw*|cygwin*|win32*)
610
echo "Running ${me} on Windows"
7-
if command -v python3 > /dev/null 2>&1; then
8-
PYTHON_EXECUTABLE=(python3)
9-
elif command -v python > /dev/null 2>&1; then
10-
PYTHON_EXECUTABLE=(python)
11+
if command -v py >/dev/null 2>&1 && is_python3 py -3; then
12+
PYTHON_EXECUTABLE=(py -3)
1113
else
12-
echo "Error: Python not found or not runnable"
13-
exit 1
14+
python3_path=$(command -v python3 2>/dev/null || true)
15+
if [ -n "$python3_path" ] && [[ "$python3_path" != *WindowsApps* ]] && is_python3 python3; then
16+
PYTHON_EXECUTABLE=(python3)
17+
elif command -v python >/dev/null 2>&1 && is_python3 python; then
18+
PYTHON_EXECUTABLE=(python)
19+
else
20+
echo "Error: Python 3 not found. Please install Python 3 or disable the Microsoft Store python alias."
21+
exit 1
22+
fi
1423
fi
1524
;;
1625
*)
1726
echo "Running ${me} on linux / mac / unix"
18-
if command -v python3 > /dev/null 2>&1; then
27+
if command -v python3 >/dev/null 2>&1 && is_python3 python3; then
1928
PYTHON_EXECUTABLE=(python3)
20-
elif command -v python > /dev/null 2>&1; then
29+
elif command -v python >/dev/null 2>&1 && is_python3 python; then
2130
PYTHON_EXECUTABLE=(python)
2231
else
2332
echo "Error: Python not found or not runnable"

main/pre-merge-commit

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
#!/usr/bin/env bash
22
me=$(basename "$0")
33

4+
is_python3() {
5+
"$@" -c 'import sys; sys.exit(0 if sys.version_info[0] == 3 else 1)' >/dev/null 2>&1
6+
}
7+
48
case "$OSTYPE" in
59
msys*|mingw*|cygwin*|win32*)
610
echo "Running ${me} on Windows"
7-
if command -v python3 > /dev/null 2>&1; then
8-
PYTHON_EXECUTABLE=(python3)
9-
elif command -v python > /dev/null 2>&1; then
10-
PYTHON_EXECUTABLE=(python)
11+
if command -v py >/dev/null 2>&1 && is_python3 py -3; then
12+
PYTHON_EXECUTABLE=(py -3)
1113
else
12-
echo "Error: Python not found or not runnable"
13-
exit 1
14+
python3_path=$(command -v python3 2>/dev/null || true)
15+
if [ -n "$python3_path" ] && [[ "$python3_path" != *WindowsApps* ]] && is_python3 python3; then
16+
PYTHON_EXECUTABLE=(python3)
17+
elif command -v python >/dev/null 2>&1 && is_python3 python; then
18+
PYTHON_EXECUTABLE=(python)
19+
else
20+
echo "Error: Python 3 not found. Please install Python 3 or disable the Microsoft Store python alias."
21+
exit 1
22+
fi
1423
fi
1524
;;
1625
*)
1726
echo "Running ${me} on linux / mac / unix"
18-
if command -v python3 > /dev/null 2>&1; then
27+
if command -v python3 >/dev/null 2>&1 && is_python3 python3; then
1928
PYTHON_EXECUTABLE=(python3)
20-
elif command -v python > /dev/null 2>&1; then
29+
elif command -v python >/dev/null 2>&1 && is_python3 python; then
2130
PYTHON_EXECUTABLE=(python)
2231
else
2332
echo "Error: Python not found or not runnable"

0 commit comments

Comments
 (0)