aboutsummarylogtreecommitdiffstats
path: root/libbackend.patch
blob: 0e34c9d03fba86fe125bd08eeb728b492b851610 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
diff --git a/backend/python/common/libbackend.sh b/backend/python/common/libbackend.sh
index 5c5805b9..0fbe409a 100644
--- a/backend/python/common/libbackend.sh
+++ b/backend/python/common/libbackend.sh
@@ -1,7 +1,7 @@
 
 
 # init handles the setup of the library
-# 
+#
 # use the library by adding the following line to a script:
 # source $(dirname $0)/../common/libbackend.sh
 #
@@ -74,15 +74,28 @@ function getBuildProfile() {
 # This function is idempotent, so you can call it as many times as you want and it will
 # always result in an activated virtual environment
 function ensureVenv() {
+    local venv_creation
+    venv_creation=0
     if [ ! -d "${MY_DIR}/venv" ]; then
-        uv venv ${MY_DIR}/venv
+        python3 -m venv --system-site-packages ${MY_DIR}/venv
+        venv_creation=1
         echo "virtualenv created"
     fi
-    
     if [ "x${VIRTUAL_ENV}" != "x${MY_DIR}/venv" ]; then
         source ${MY_DIR}/venv/bin/activate
         echo "virtualenv activated"
     fi
+    if test "$1" = "--install"; then
+        if test "$venv_creation" = "1"; then
+            reqFile="${MY_DIR}/requirements.txt"
+            if [ -f ${reqFile} ]; then
+                sed -ri '/^(torch|torchvision|torchaudio)/d' "${reqFile}"
+                echo "starting requirements install for ${reqFile}"
+                pip install --requirement ${reqFile}
+                echo "finished requirements install for ${reqFile}"
+            fi
+        fi
+    fi
 
     echo "activated virtualenv has been ensured"
 }
@@ -111,21 +124,11 @@ function ensureVenv() {
 function installRequirements() {
     ensureVenv
 
-    # These are the requirements files we will attempt to install, in order
-    declare -a requirementFiles=(
-        "${MY_DIR}/requirements-install.txt"
-        "${MY_DIR}/requirements.txt"
-        "${MY_DIR}/requirements-${BUILD_TYPE}.txt"
-    )
-
-    if [ "x${BUILD_TYPE}" != "x${BUILD_PROFILE}" ]; then
-        requirementFiles+=("${MY_DIR}/requirements-${BUILD_PROFILE}.txt")
-    fi
-
-    for reqFile in ${requirementFiles[@]}; do
+    for reqFile in "${MY_DIR}/requirements.txt"; do
         if [ -f ${reqFile} ]; then
+            sed -ri '/^(torch|torchvision|torchaudio)/d' "${reqFile}"
             echo "starting requirements install for ${reqFile}"
-            uv pip install ${EXTRA_PIP_INSTALL_FLAGS} --requirement ${reqFile}
+            pip install --requirement ${reqFile}
             echo "finished requirements install for ${reqFile}"
         fi
     done
@@ -145,7 +148,7 @@ function installRequirements() {
 #  - backend.py
 #  - ${BACKEND_NAME}.py
 function startBackend() {
-    ensureVenv
+    ensureVenv --install
 
     if [ ! -z ${BACKEND_FILE} ]; then
         python ${BACKEND_FILE} $@
@@ -210,4 +213,4 @@ function checkTargets() {
     echo false
 }
 
-init
\ No newline at end of file
+init