@@ -5,7 +5,7 @@ PACKAGE=${PACKAGE:-""}
5
5
VERSION=${VERSION:- " latest" }
6
6
INJECTIONS=${INJECTIONS:- " " }
7
7
INCLUDEDEPS=${INCLUDEDEPS:- " false" }
8
- INTERPRETER=${INTERPRETER:- " python3 " }
8
+ INTERPRETER=${INTERPRETER:- " " }
9
9
10
10
# PEP 668 compatibility
11
11
export PIP_BREAK_SYSTEM_PACKAGES=1
@@ -45,32 +45,41 @@ install_via_pipx() {
45
45
local VERSION=$3
46
46
local INJECTIONS=$4
47
47
local INCLUDEDEPS=$5
48
- if [ " $INTERPRETER " = " python3" ]; then
49
48
50
- # if no python - install it
51
- if ! type python3 > /dev/null 2>&1 ; then
52
- echo " installing python3-minimal libffi-dev"
53
- apt-get update -y
54
- apt-get -y install python3-minimal
55
- fi
56
-
57
- # if no pip - install it
58
- if ! type pip3 > /dev/null 2>&1 ; then
59
- echo " installing python3-pip"
60
- apt-get update -y
61
- apt-get -y install libffi-dev python3-pip
62
- fi
63
-
64
- if ! python3 -Im ensurepip --version > /dev/null 2>&1 ; then
65
- echo " installing python3-venv"
66
- apt-get update -y
67
- apt-get -y install python3-venv
49
+ if [ -n " $INTERPRETER " ]; then
50
+ if ! type $INTERPRETER > /dev/null 2>&1 ; then
51
+ echo " interpreter given is invalid: $INTERPRETER "
52
+ exit 1
68
53
fi
54
+ local _interpreter=$INTERPRETER
55
+ else
56
+ local _interpreter=" python3"
69
57
fi
70
-
71
- if ! type " $INTERPRETER " ; then
72
- echo " interpreter given is invalid: $INTERPRETER "
73
- exit 1
58
+
59
+ if [ -z " $INTERPRETER " ]; then # if interpreter selected manually - it should exists (validated above)
60
+
61
+ if [ " $_interpreter " = " python3" ]; then
62
+
63
+ # if no python - install it
64
+ if ! type python3 > /dev/null 2>&1 ; then
65
+ echo " installing python3-minimal libffi-dev"
66
+ apt-get update -y
67
+ apt-get -y install python3-minimal
68
+ fi
69
+
70
+ # if no pip - install it
71
+ if ! type pip3 > /dev/null 2>&1 ; then
72
+ echo " installing python3-pip"
73
+ apt-get update -y
74
+ apt-get -y install libffi-dev python3-pip
75
+ fi
76
+
77
+ if ! python3 -Im ensurepip --version > /dev/null 2>&1 ; then
78
+ echo " installing python3-venv"
79
+ apt-get update -y
80
+ apt-get -y install python3-venv
81
+ fi
82
+ fi
74
83
fi
75
84
76
85
export PYTHONUSERBASE=/tmp/pip-tmp
@@ -80,9 +89,7 @@ install_via_pipx() {
80
89
export PIPX_BIN_DIR=" ${PIPX_HOME} /bin"
81
90
mkdir -p " ${PIPX_HOME} "
82
91
83
- # if pipx not exists - install it
84
- if ! $INTERPRETER -m pip list | grep pipx > /dev/null 2>&1 ; then
85
-
92
+ _install_pipx () {
86
93
PATH=" ${PATH} :${PIPX_BIN_DIR} "
87
94
88
95
# Create pipx group, dir, and set sticky bit
@@ -96,18 +103,34 @@ install_via_pipx() {
96
103
chmod -R g+r+w " ${PIPX_HOME} "
97
104
find " ${PIPX_HOME} " -type d -print0 | xargs -0 -n 1 chmod g+s
98
105
99
- $INTERPRETER -m pip install --disable-pip-version-check --no-cache-dir --user pipx 2>&1
100
- /tmp/pip-tmp/ bin/pipx install --pip-args=--no-cache-dir pipx
101
- pipx_bin=/tmp/pip-tmp /bin/pipx
106
+ $_interpreter -m pip install --disable-pip-version-check --no-cache-dir --user pipx 2>&1
107
+ $PYTHONUSERBASE / bin/pipx install --pip-args=--no-cache-dir --force pipx
108
+ pipx_bin=$PYTHONUSERBASE /bin/pipx
102
109
103
110
updaterc " export PIPX_HOME=\" ${PIPX_HOME} \" "
104
111
updaterc " export PIPX_BIN_DIR=\" ${PIPX_BIN_DIR} \" "
105
112
updaterc " if [[ \"\$ {PATH}\" != *\"\$ {PIPX_BIN_DIR}\" * ]]; then export PATH=\"\$ {PATH}:\$ {PIPX_BIN_DIR}\" ; fi"
106
-
113
+ }
114
+
115
+
116
+ if $_interpreter -m pip list | grep pipx > /dev/null 2>&1 ; then
117
+ # if pipx exists in the selected interpreter - use it
118
+ pipx_bin=" $_interpreter -m pipx"
119
+ elif [ -n " $INTERPRETER " ]; then
120
+ # if interpreter was *explicitely* selected,
121
+ # and pipx is not installed with it - install it
122
+ _install_pipx
123
+ pipx_bin=" $_interpreter -m pipx"
124
+ elif type pipx > /dev/null 2>&1 ; then
125
+ # if a global pipx is install - use it
126
+ pipx_bin=" pipx"
107
127
else
108
- pipx_bin=" $INTERPRETER -m pipx"
128
+ # if no pipx installed what so ever - install it
129
+ _install_pipx
130
+ pipx_bin=$PYTHONUSERBASE /bin/pipx
109
131
fi
110
132
133
+
111
134
if [ " $( ${pipx_bin} list --short | grep " $PACKAGE " ) " != " " ]; then
112
135
echo " $PACKAGE already exists - skipping installation"
113
136
else
@@ -130,7 +153,7 @@ install_via_pipx() {
130
153
done
131
154
132
155
# cleaning pipx to save disk space
133
- rm -rf /tmp/pip-tmp
156
+ rm -rf $PYTHONUSERBASE
134
157
fi
135
158
}
136
159
0 commit comments