Skip to content

Commit 285d43c

Browse files
committed
Use Python3 virtual environments
Try to Fix LSPosed#508
1 parent ad396d6 commit 285d43c

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
download
22
output
3+
python3-env

docs/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
The following dependencies are required:
1010

11-
| DistrOS | | | |
12-
|:-------------------:|--------------------------------------------------------------------------------|------------|--------------|
13-
| Debian | `lzip patchelf e2fsprogs python3 python3-pip aria2 p7zip-full attr unzip sudo` | `whiptail` | `qemu-utils` |
14-
| openSUSE Tumbleweed | Same as above | `dialog` | `qemu-tools` |
11+
| DistrOS | | | | |
12+
|:-------------------:|--------------------------------------------------------------------------------|------------|--------------|--------------------|
13+
| Debian | `lzip patchelf e2fsprogs python3 python3-pip aria2 p7zip-full attr unzip sudo` | `whiptail` | `qemu-utils` | `python3-venv` |
14+
| openSUSE Tumbleweed | Same as above | `dialog` | `qemu-tools` | `python3-venvctrl` |
1515

1616
The python3 library `requests` is used.
1717

scripts/build.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ PRODUCT_MNT="$ROOT_MNT/product"
4040
SYSTEM_EXT_MNT="$ROOT_MNT/system_ext"
4141
DOWNLOAD_DIR=../download
4242
DOWNLOAD_CONF_NAME=download.list
43+
PYTHON_VENV_DIR="$(dirname "$PWD")/python3-env"
4344
umount_clean() {
4445
if [ -d "$ROOT_MNT" ]; then
4546
echo "Cleanup Mount Directory"
@@ -64,6 +65,10 @@ umount_clean() {
6465
unset TMPDIR
6566
fi
6667
rm -f "${DOWNLOAD_DIR:?}/$DOWNLOAD_CONF_NAME"
68+
if [ "$(which python)" == "$PYTHON_VENV_DIR/bin/python" ]; then
69+
echo "deactivate python3 venv"
70+
deactivate
71+
fi
6772
}
6873
trap umount_clean EXIT
6974
OUTPUT_DIR=../output
@@ -362,7 +367,10 @@ require_su() {
362367
fi
363368
fi
364369
}
365-
370+
# shellcheck disable=SC1091
371+
[ -f "$PYTHON_VENV_DIR/bin/activate" ] && {
372+
source "$PYTHON_VENV_DIR/bin/activate" || abort "Failed to activate virtual environment, please re-run install_deps.sh"
373+
}
366374
declare -A RELEASE_NAME_MAP=(["retail"]="Retail" ["RP"]="Release Preview" ["WIS"]="Insider Slow" ["WIF"]="Insider Fast")
367375
declare -A ANDROID_API_MAP=(["30"]="11.0" ["32"]="12.1" ["33"]="13.0")
368376
RELEASE_NAME=${RELEASE_NAME_MAP[$RELEASE_TYPE]} || abort

scripts/install_deps.sh

+15-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fi
2525
cd "$(dirname "$0")" || exit 1
2626
SUDO="$(which sudo 2>/dev/null)"
2727
abort() {
28+
[ "$1" ] && echo "ERROR: $1"
2829
echo "Dependencies: an error has occurred, exit"
2930
exit 1
3031
}
@@ -49,6 +50,7 @@ check_dependencies() {
4950
command -v unzip >/dev/null 2>&1 || NEED_INSTALL+=("unzip")
5051
command -v qemu-img >/dev/null 2>&1 || NEED_INSTALL+=("qemu-utils")
5152
command -v sudo >/dev/null 2>&1 || NEED_INSTALL+=("sudo")
53+
python3 -c "import venv" >/dev/null 2>&1 || NEED_INSTALL+=("python3-venv")
5254
}
5355
check_dependencies
5456
osrel=$(sed -n '/^ID_LIKE=/s/^.*=//p' /etc/os-release)
@@ -116,6 +118,7 @@ if [ -n "${NEED_INSTALL[*]}" ]; then
116118
NEED_INSTALL_FIX=${NEED_INSTALL_FIX//setools/setools-console} 2>&1
117119
NEED_INSTALL_FIX=${NEED_INSTALL_FIX//whiptail/dialog} 2>&1
118120
NEED_INSTALL_FIX=${NEED_INSTALL_FIX//qemu-utils/qemu-tools} 2>&1
121+
NEED_INSTALL_FIX=${NEED_INSTALL_FIX//python3-venv/python3-venvctrl} 2>&1
119122
} >>/dev/null
120123

121124
readarray -td ' ' NEED_INSTALL <<<"$NEED_INSTALL_FIX "
@@ -128,5 +131,15 @@ if [ -n "${NEED_INSTALL[*]}" ]; then
128131
if ! ($SUDO "$PM" "${INSTALL_OPTION[@]}" "${NEED_INSTALL[@]}"); then abort; fi
129132

130133
fi
131-
132-
python3 -m pip install -r requirements.txt -q
134+
PYTHON_VENV_DIR="$(dirname "$PWD")/python3-env"
135+
[ -f "$PYTHON_VENV_DIR/bin/activate" ] || {
136+
echo "Creating python3 virtual env"
137+
python3 -m venv "$PYTHON_VENV_DIR" || abort "Failed to create python3 virtual env"
138+
}
139+
# shellcheck disable=SC1091
140+
source "$PYTHON_VENV_DIR"/bin/activate || abort "Failed to activate python3 virtual env"
141+
python3 -c "import pkg_resources; pkg_resources.require(open('requirements.txt',mode='r'))" &>/dev/null || {
142+
echo "Installing Python3 dependencies"
143+
python3 -m pip install -r requirements.txt || abort "Failed to install python3 dependencies"
144+
}
145+
deactivate

0 commit comments

Comments
 (0)