Use Python3 virtual environments

Try to Fix 
This commit is contained in:
Howard Wu 2023-05-12 00:07:27 +08:00
parent ad396d6810
commit 285d43c601
4 changed files with 29 additions and 7 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
download
output
python3-env

View file

@ -8,10 +8,10 @@
The following dependencies are required:
| DistrOS | | | |
|:-------------------:|--------------------------------------------------------------------------------|------------|--------------|
| Debian | `lzip patchelf e2fsprogs python3 python3-pip aria2 p7zip-full attr unzip sudo` | `whiptail` | `qemu-utils` |
| openSUSE Tumbleweed | Same as above | `dialog` | `qemu-tools` |
| DistrOS | | | | |
|:-------------------:|--------------------------------------------------------------------------------|------------|--------------|--------------------|
| Debian | `lzip patchelf e2fsprogs python3 python3-pip aria2 p7zip-full attr unzip sudo` | `whiptail` | `qemu-utils` | `python3-venv` |
| openSUSE Tumbleweed | Same as above | `dialog` | `qemu-tools` | `python3-venvctrl` |
The python3 library `requests` is used.

View file

@ -40,6 +40,7 @@ PRODUCT_MNT="$ROOT_MNT/product"
SYSTEM_EXT_MNT="$ROOT_MNT/system_ext"
DOWNLOAD_DIR=../download
DOWNLOAD_CONF_NAME=download.list
PYTHON_VENV_DIR="$(dirname "$PWD")/python3-env"
umount_clean() {
if [ -d "$ROOT_MNT" ]; then
echo "Cleanup Mount Directory"
@ -64,6 +65,10 @@ umount_clean() {
unset TMPDIR
fi
rm -f "${DOWNLOAD_DIR:?}/$DOWNLOAD_CONF_NAME"
if [ "$(which python)" == "$PYTHON_VENV_DIR/bin/python" ]; then
echo "deactivate python3 venv"
deactivate
fi
}
trap umount_clean EXIT
OUTPUT_DIR=../output
@ -362,7 +367,10 @@ require_su() {
fi
fi
}
# shellcheck disable=SC1091
[ -f "$PYTHON_VENV_DIR/bin/activate" ] && {
source "$PYTHON_VENV_DIR/bin/activate" || abort "Failed to activate virtual environment, please re-run install_deps.sh"
}
declare -A RELEASE_NAME_MAP=(["retail"]="Retail" ["RP"]="Release Preview" ["WIS"]="Insider Slow" ["WIF"]="Insider Fast")
declare -A ANDROID_API_MAP=(["30"]="11.0" ["32"]="12.1" ["33"]="13.0")
RELEASE_NAME=${RELEASE_NAME_MAP[$RELEASE_TYPE]} || abort

View file

@ -25,6 +25,7 @@ fi
cd "$(dirname "$0")" || exit 1
SUDO="$(which sudo 2>/dev/null)"
abort() {
[ "$1" ] && echo "ERROR: $1"
echo "Dependencies: an error has occurred, exit"
exit 1
}
@ -49,6 +50,7 @@ check_dependencies() {
command -v unzip >/dev/null 2>&1 || NEED_INSTALL+=("unzip")
command -v qemu-img >/dev/null 2>&1 || NEED_INSTALL+=("qemu-utils")
command -v sudo >/dev/null 2>&1 || NEED_INSTALL+=("sudo")
python3 -c "import venv" >/dev/null 2>&1 || NEED_INSTALL+=("python3-venv")
}
check_dependencies
osrel=$(sed -n '/^ID_LIKE=/s/^.*=//p' /etc/os-release)
@ -116,6 +118,7 @@ if [ -n "${NEED_INSTALL[*]}" ]; then
NEED_INSTALL_FIX=${NEED_INSTALL_FIX//setools/setools-console} 2>&1
NEED_INSTALL_FIX=${NEED_INSTALL_FIX//whiptail/dialog} 2>&1
NEED_INSTALL_FIX=${NEED_INSTALL_FIX//qemu-utils/qemu-tools} 2>&1
NEED_INSTALL_FIX=${NEED_INSTALL_FIX//python3-venv/python3-venvctrl} 2>&1
} >>/dev/null
readarray -td ' ' NEED_INSTALL <<<"$NEED_INSTALL_FIX "
@ -128,5 +131,15 @@ if [ -n "${NEED_INSTALL[*]}" ]; then
if ! ($SUDO "$PM" "${INSTALL_OPTION[@]}" "${NEED_INSTALL[@]}"); then abort; fi
fi
python3 -m pip install -r requirements.txt -q
PYTHON_VENV_DIR="$(dirname "$PWD")/python3-env"
[ -f "$PYTHON_VENV_DIR/bin/activate" ] || {
echo "Creating python3 virtual env"
python3 -m venv "$PYTHON_VENV_DIR" || abort "Failed to create python3 virtual env"
}
# shellcheck disable=SC1091
source "$PYTHON_VENV_DIR"/bin/activate || abort "Failed to activate python3 virtual env"
python3 -c "import pkg_resources; pkg_resources.require(open('requirements.txt',mode='r'))" &>/dev/null || {
echo "Installing Python3 dependencies"
python3 -m pip install -r requirements.txt || abort "Failed to install python3 dependencies"
}
deactivate