From 7f4103a352f16c8525f013c93ccbcd49be596067 Mon Sep 17 00:00:00 2001 From: vzhd1701 Date: Tue, 19 Oct 2021 16:30:04 +0500 Subject: [PATCH] build(pyinstaller): refactor --- scripts/init_app_vars.sh | 24 ++++++++++++++++++++++++ scripts/pyinstaller/build_mac.sh | 17 +++++++---------- scripts/pyinstaller/build_win.sh | 17 +++++++---------- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/scripts/init_app_vars.sh b/scripts/init_app_vars.sh index bd0a23f..bd6ded0 100644 --- a/scripts/init_app_vars.sh +++ b/scripts/init_app_vars.sh @@ -33,6 +33,30 @@ copy_with_app_vars() { replace_app_vars "$DEST_FILE" } +init_venv() { + VENV_DIR="$1" + + if [ ! -d "$VENV_DIR" ]; then + python -m venv "$VENV_DIR" + + activate_venv "$VENV_DIR" + + python -m pip install --upgrade pip + else + activate_venv "$VENV_DIR" + fi +} + +activate_venv() { + VENV_DIR="$1" + + if [ -f "$VENV_DIR/Scripts/activate" ]; then + . "$VENV_DIR/Scripts/activate" + else + . "$VENV_DIR/bin/activate" + fi +} + #ROOT_DIR="$(realpath $(dirname $( cd "$( dirname $0 )" && pwd ))/..)" export ROOT_DIR="$(realpath $(pwd))" diff --git a/scripts/pyinstaller/build_mac.sh b/scripts/pyinstaller/build_mac.sh index f6345ca..e4a95ed 100644 --- a/scripts/pyinstaller/build_mac.sh +++ b/scripts/pyinstaller/build_mac.sh @@ -12,16 +12,13 @@ PYINSTALLER_VERSION="4.5.1" mkdir -p "$BUILD_DIR" -if [ ! -d "$BUILD_DIR/venv" ]; then - python -m venv "$BUILD_DIR/venv" - . "$BUILD_DIR/venv/bin/activate" - python -m pip install --upgrade pip - - pip install --no-binary pydantic -r "$BUILD_DIR/requirements.txt" - pip install pyinstaller=="$PYINSTALLER_VERSION" -else - . "$BUILD_DIR/venv/bin/activate" -fi +init_venv "$BUILD_DIR/venv-pyinstaller" + +# Reduce size by installing src version of pydantic +export PIP_NO_BINARY="pydantic" + +pip install -r "$BUILD_DIR/requirements.txt" +pip install pyinstaller=="$PYINSTALLER_VERSION" # Copy icons to build dir cp "$RESOURCES_DIR/icons/main/sys/macos.icns" "$BUILD_DIR/main.icns" diff --git a/scripts/pyinstaller/build_win.sh b/scripts/pyinstaller/build_win.sh index 8c682dd..f250bc8 100644 --- a/scripts/pyinstaller/build_win.sh +++ b/scripts/pyinstaller/build_win.sh @@ -12,16 +12,13 @@ PYINSTALLER_VERSION="4.5.1" mkdir -p "$BUILD_DIR" -if [ ! -d "$BUILD_DIR/venv" ]; then - python -m venv "$BUILD_DIR/venv" - . "$BUILD_DIR/venv/Scripts/activate" - python -m pip install --upgrade pip - - pip install --no-binary pydantic -r "$BUILD_DIR/requirements.txt" - pip install pyinstaller=="$PYINSTALLER_VERSION" -else - . "$BUILD_DIR/venv/Scripts/activate" -fi +init_venv "$BUILD_DIR/venv-pyinstaller" + +# Reduce size by installing src version of pydantic +export PIP_NO_BINARY="pydantic" + +pip install -r "$BUILD_DIR/requirements.txt" +pip install pyinstaller=="$PYINSTALLER_VERSION" # Copy icons to build dir cp "$RESOURCES_DIR/icons/main/sys/windows.ico" "$BUILD_DIR/main.ico"