Skip to content

Commit

Permalink
Use Python3 virtual environments
Browse files Browse the repository at this point in the history
Try to Fix LSPosed#508
  • Loading branch information
Howard20181 committed May 11, 2023
1 parent ad396d6 commit 285d43c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
download
output
python3-env
8 changes: 4 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 9 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions scripts/install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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 "
Expand All @@ -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

0 comments on commit 285d43c

Please sign in to comment.