2023-01-16 14:52:22 +08:00
#!/bin/bash
2023-01-02 01:54:45 +08:00
2022-12-11 13:37:08 +08:00
# make sure we are not already in a venv
# (don't need to check status)
deactivate >/dev/null 2>& 1
2023-02-04 10:42:00 +08:00
scriptdir = $( dirname " $0 " )
cd $scriptdir
2022-12-11 13:37:08 +08:00
2023-02-04 10:42:00 +08:00
function version { echo " $@ " | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }' ; }
2023-09-28 21:28:41 +08:00
MINIMUM_PYTHON_VERSION = 3.10.0
2023-07-25 05:21:56 +08:00
MAXIMUM_PYTHON_VERSION = 3.11.100
2023-02-04 10:42:00 +08:00
PYTHON = ""
2023-09-28 21:28:41 +08:00
for candidate in python3.11 python3.10 python3 python ; do
2024-10-19 01:05:07 +08:00
if ppath = ` which $candidate 2>/dev/null` ; then
2023-07-28 01:27:58 +08:00
# when using `pyenv`, the executable for an inactive Python version will exist but will not be operational
# we check that this found executable can actually run
if [ $( $candidate --version & >/dev/null; echo ${ PIPESTATUS } ) -gt 0 ] ; then continue ; fi
2023-02-04 10:42:00 +08:00
python_version = $( $ppath -V | awk '{ print $2 }' )
if [ $( version $python_version ) -ge $( version " $MINIMUM_PYTHON_VERSION " ) ] ; then
2023-07-28 01:27:58 +08:00
if [ $( version $python_version ) -le $( version " $MAXIMUM_PYTHON_VERSION " ) ] ; then
PYTHON = $ppath
break
fi
2023-02-04 10:42:00 +08:00
fi
fi
done
if [ -z " $PYTHON " ] ; then
echo "A suitable Python interpreter could not be found"
2023-06-16 21:18:23 +08:00
echo " Please install Python $MINIMUM_PYTHON_VERSION or higher (maximum $MAXIMUM_PYTHON_VERSION ) before running this script. See instructions at $INSTRUCTIONS for help. "
2023-02-04 10:42:00 +08:00
read -p "Press any key to exit"
exit -1
fi
2024-10-19 01:14:46 +08:00
echo "For the best user experience we suggest enlarging or maximizing this window now."
2023-02-08 05:35:22 +08:00
exec $PYTHON ./lib/main.py ${ @ }
2023-02-22 09:03:08 +08:00
read -p "Press any key to exit"