From ee84d892b8d2fe9c3b42044bdd4d7856eec6c1a7 Mon Sep 17 00:00:00 2001 From: kingbri Date: Wed, 27 Dec 2023 23:53:14 -0500 Subject: [PATCH] Start: Add shell script Same as the batch file. Also edit the python script to work when a venv is clean. Signed-off-by: kingbri --- start.py | 7 ++++--- start.sh | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) mode change 100644 => 100755 start.sh diff --git a/start.py b/start.py index 7bb80408..47c55268 100644 --- a/start.py +++ b/start.py @@ -3,7 +3,6 @@ import os import pathlib import subprocess -from main import entrypoint def get_requirements_file(): @@ -44,7 +43,7 @@ def get_argparser(): if __name__ == "__main__": - subprocess.run("pip -V") + subprocess.run(["pip", "-V"]) parser = get_argparser() args = parser.parse_args() @@ -55,6 +54,8 @@ def get_argparser(): requirements_file = ( "requirements-nowheel" if args.nowheel else get_requirements_file() ) - subprocess.run(f"pip install -U -r {requirements_file}.txt") + subprocess.run(["pip", "install", "-U", "-r", f"{requirements_file}.txt"]) + # Import entrypoint after installing all requirements + from main import entrypoint entrypoint() diff --git a/start.sh b/start.sh old mode 100644 new mode 100755 index 4aa922f2..9318931c --- a/start.sh +++ b/start.sh @@ -1,5 +1,19 @@ #!/bin/bash -cd "$(dirname "$0")" -source ./venv/bin/activate -pip -V -python main.py + +cd "$(dirname "$0")" || exit + +if [ -n "$CONDA_PREFIX" ]; then + echo "It looks like you're in a conda environment. Skipping venv check." +else + if [ ! -d "venv" ]; then + echo "Venv doesn't exist! Creating one for you." + python3 -m venv venv + fi + + echo "Activating venv" + + # shellcheck source=/dev/null + source venv/bin/activate +fi + +python3 start.py "$@"