mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-28 10:01:58 +00:00
* Add tools/bootstrap/python * Add dependencies.sh entry for Python * Use bootstrapped Python for HitboxExpander * Use bootstrapped Python when installing hooks Also: - Adds tools/hooks/Uninstall.bat - Removes the need to re-run Install.bat when a .hook file changes Python path temporarily includes tools/mapmerge2 as before: - PYTHONPATH in tools/hooks/python.sh handles Linux/virtualenv - python36._pth handles Windows portable * Move DMI merge driver to its own directory * Use bootstrapped Python for makeChangelog.bat * Set window title in bootstrap PS scripts * Use slashes in hook paths * Use relative imports in mapmerge2 * Use bootstrapped Python for mapmerge * Update mapmerge2 readme * Skip non-3way conflicts * Fix relative path issue in posthoc merger * Add missing call and %* to .bat files * When installing hooks, don't uninstall them all first * Make dependencies.sh POSIX * Move update_paths.py to its own folder * Use line buffering for Python stdout/stderr It was switching to fully-buffered mode due to being piped, meaning we wouldn't see output until the script ended. This is undesirable. * Use new path to dmi.test in CI suite * Validate system Python version in bootstrap script * Add install advice to bootstrap script * Update path to requirements.txt in CI * Add upgrader for existing installations
118 lines
4.0 KiB
Bash
Executable File
118 lines
4.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# bootstrap/python
|
|
#
|
|
# Python-finding script for all `sh` environments, including Linux, MSYS2,
|
|
# Git for Windows, and GitHub Desktop. Invokable from CLI or automation.
|
|
#
|
|
# If a python.exe installed by `python_.ps1` is present, it will be used.
|
|
# Otherwise, this script requires a system `python3` and `pip` to be provided,
|
|
# and will create a standard virtualenv in which to install `requirements.txt`.
|
|
set -e
|
|
|
|
# Convenience variables
|
|
Bootstrap="$(dirname "$0")"
|
|
Sdk="$(dirname "$Bootstrap")"
|
|
Cache="$Bootstrap/.cache"
|
|
if [ "$TG_BOOTSTRAP_CACHE" ]; then
|
|
Cache="$TG_BOOTSTRAP_CACHE"
|
|
fi
|
|
OldPWD="$PWD"
|
|
cd "$Bootstrap/../.."
|
|
. ./dependencies.sh # sets PYTHON_VERSION
|
|
cd "$OldPWD"
|
|
PythonVersion="$PYTHON_VERSION"
|
|
PythonDir="$Cache/python-$PythonVersion"
|
|
PythonExe="$PythonDir/python.exe"
|
|
Log="$Cache/last-command.log"
|
|
|
|
# If a portable Python for Windows is not present, search on $PATH.
|
|
if [ "$(uname)" = "Linux" ] || [ ! -f "$PythonExe" ]; then
|
|
# Strip the "App Execution Aliases" from $PATH. Even if the user installed
|
|
# Python using the Windows Store on purpose, these aliases always generate
|
|
# "Permission denied" errors when sh.exe tries to invoke them.
|
|
PATH=$(echo "$PATH" | tr ":" "\n" | grep -v "AppData/Local/Microsoft/WindowsApps" | tr "\n" ":")
|
|
|
|
# Try to find a Python executable.
|
|
if command -v python3 >/dev/null 2>&1; then
|
|
PythonExe=python3
|
|
elif command -v python >/dev/null 2>&1; then
|
|
PythonExe=python
|
|
elif command -v py >/dev/null 2>&1; then
|
|
PythonExe="py -3"
|
|
else
|
|
echo
|
|
if command -v apt-get >/dev/null 2>&1; then
|
|
echo "Please install Python using your system's package manager:"
|
|
echo " sudo apt-get install python3 python3-pip"
|
|
elif [ "$(uname -o)" = "Msys" ]; then
|
|
echo "Please run tools/bootstrap/python.bat instead of tools/bootstrap/python once to"
|
|
echo "install Python automatically, or install it from https://www.python.org/downloads/"
|
|
# TODO: give MSYS pacman advice?
|
|
elif command -v pacman >/dev/null 2>&1; then
|
|
echo "Please install Python using your system's package manager:"
|
|
echo " sudo pacman -S python python-pip"
|
|
else
|
|
echo "Please install Python from https://www.python.org/downloads/ or using your system's package manager."
|
|
fi
|
|
echo
|
|
exit 1
|
|
fi
|
|
|
|
# Create a venv and activate it
|
|
PythonDir="$Cache/venv"
|
|
if [ ! -d "$PythonDir" ]; then
|
|
echo "Creating virtualenv..."
|
|
"$PythonExe" -m venv "$PythonDir"
|
|
fi
|
|
if [ -f "$PythonDir/bin/python" ]; then
|
|
PythonExe="$PythonDir/bin/python"
|
|
elif [ -f "$PythonDir/scripts/python3.exe" ]; then
|
|
PythonExe="$PythonDir/scripts/python3.exe";
|
|
else
|
|
echo "bootstrap/python failed to find the python executable inside its virtualenv"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Use pip to install our requirements
|
|
if [ ! -f "$PythonDir/requirements.txt" ] || [ "$(b2sum < "$Sdk/requirements.txt")" != "$(b2sum < "$PythonDir/requirements.txt")" ]; then
|
|
echo "Updating dependencies..."
|
|
"$PythonExe" -m pip install -U pip -r "$Sdk/requirements.txt"
|
|
cp "$Sdk/requirements.txt" "$PythonDir/requirements.txt"
|
|
echo "---"
|
|
fi
|
|
|
|
# Verify version and deduce the path separator
|
|
PythonMajor=${PythonVersion%%.*}
|
|
PythonMinor=${PythonVersion#*.}
|
|
PythonMinor=${PythonMinor%.*}
|
|
PATHSEP=$("$PythonExe" - "$PythonMajor" "$PythonMinor" <<'EOF'
|
|
import sys, os
|
|
if sys.version_info.major != int(sys.argv[1]) or sys.version_info.minor < int(sys.argv[2]):
|
|
print("Error: Python ", sys.argv[1], ".", sys.argv[2], " or later is required, but you have:\n", sys.version, sep="", file=sys.stderr)
|
|
exit(1)
|
|
print(os.pathsep)
|
|
EOF
|
|
)
|
|
|
|
# Cheap shell function if tee.exe is not available
|
|
if ! command -v tee >/dev/null 2>&1; then
|
|
tee() {
|
|
# Fudge: assume $1 is always "-a"
|
|
while read -r line; do
|
|
echo "$line" >> "$2"
|
|
echo "$line"
|
|
done
|
|
}
|
|
fi
|
|
|
|
# Invoke python with all command-line arguments
|
|
export PYTHONPATH="$Sdk$PATHSEP${PYTHONPATH:-}"
|
|
mkdir -p "$Cache"
|
|
printf '%s\n' "$PythonExe" "$@" > "$Log"
|
|
printf -- '---\n' >> "$Log"
|
|
exec 4>&1
|
|
exitstatus=$({ { set +e; "$PythonExe" -u "$@" 2>&1 3>&-; printf %s $? >&3; } 4>&- | tee -a "$Log" 1>&4; } 3>&1)
|
|
exec 4>&-
|
|
exit "$exitstatus"
|