@@ -1093,6 +1093,48 @@ function tue-install-pip3
10931093
10941094# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
10951095
1096+ function _handle_python_sites
1097+ {
1098+ local pv
1099+ pv=$1
1100+ shift
1101+ # requires the parent function to have declared the following local variables:
1102+ # python_exec, site_arg, sudo_cmd, user_arg
1103+ tue-install-debug " _handle_python${pv} _sites $* "
1104+
1105+ local python_site
1106+ python_site=$1
1107+
1108+ case ${python_site} in
1109+ " system" )
1110+ python_exec=/usr/bin/python" ${pv} "
1111+ site_arg=" -s"
1112+ sudo_cmd=" sudo -H"
1113+ user_arg=" "
1114+ ;;
1115+ " user" )
1116+ python_exec=/usr/bin/python" ${pv} "
1117+ site_arg=" "
1118+ sudo_cmd=" "
1119+ user_arg=" --user"
1120+ ;;
1121+ " venv" )
1122+ python_exec=python" ${pv} "
1123+ site_arg=" -s"
1124+ sudo_cmd=" "
1125+ user_arg=" "
1126+ ;;
1127+ * )
1128+ tue-install-error " _handle_python${pv} _sites: Unknown input python_site: ${python_site} " ;;
1129+ esac
1130+
1131+ tue-install-debug " python_site: ${python_site} "
1132+ tue-install-debug " python_exec: ${python_exec} "
1133+ tue-install-debug " site_arg: ${site_arg} "
1134+ tue-install-debug " sudo_cmd: ${sudo_cmd} "
1135+ tue-install-debug " user_arg: ${user_arg} "
1136+ }
1137+
10961138function _tue-install-pip-now
10971139{
10981140 local pv
@@ -1105,25 +1147,41 @@ function _tue-install-pip-now
11051147 tue-install-error " Invalid tue-install-pip${pv} -now call: needs package as argument."
11061148 fi
11071149
1108- local user_arg
1109- [[ -z " ${VIRTUAL_ENV} " ]] && user_arg=" --user"
1150+ local pips python_site
1151+ { [[ -n ${VIRTUAL_ENV} ]] && python_site=" venv" ; } || python_site=" user"
1152+ if [[ -n $1 ]]
1153+ then
1154+ for i in " $@ "
1155+ do
1156+ case $i in
1157+ --python-site=* )
1158+ python_site=" ${i#* =} " ;;
1159+ --* )
1160+ tue-install-error " tue-install-pip${pv} -now: Unknown input variable ${i} " ;;
1161+ * )
1162+ pips+=(" $i " ) ;;
1163+ esac
1164+ done
1165+ fi
1166+
1167+ local python_exec site_arg sudo_cmd user_arg
1168+ _handle_python_sites " ${pv} " " ${python_site} "
11101169
11111170 # Make sure pip is up-to-date before checking version and installing
11121171 local pip_version desired_pip_version
1113- pip_version=$( python " ${pv} " -m pip --version | awk ' {print $2}' )
1172+ pip_version=$( ${python_exec} ${site_arg : + ${site_arg} } -m pip --version | awk ' {print $2}' )
11141173 desired_pip_version=" 23"
11151174 if version_gt " $desired_pip_version " " $pip_version "
11161175 then
11171176 tue-install-debug " pip${pv} not yet version >=$desired_pip_version , but $pip_version "
1118- tue-install-pipe python " ${pv } " -m pip install ${user_arg} --upgrade pip
1177+ tue-install-pipe ${sudo_cmd : + ${sudo_cmd} } " ${python_exec } " ${site_arg : + ${site_arg} } -m pip install ${user_arg: + ${user_arg} } --upgrade pip
11191178 hash -r
11201179 else
11211180 tue-install-debug " Already pip${pv} >=$desired_pip_version "
11221181 fi
11231182
11241183 local pips_to_check pips_to_check_w_options pips_to_install pips_to_install_w_options git_pips_to_install
1125- # shellcheck disable=SC2048
1126- for pkg in $*
1184+ for pkg in " ${pips[@]} "
11271185 do
11281186 if [[ " $pkg " == " git+" * ]]
11291187 then
@@ -1143,7 +1201,7 @@ function _tue-install-pip-now
11431201 then
11441202 local indexes_to_install
11451203 # shellcheck disable=SC2086
1146- _tue-install-pip-check " $pv " $ pips_to_check
1204+ _tue-install-pip-check " ${pv} " --python-site= ${python_site} ${ pips_to_check}
11471205
11481206 read -r -a pips_to_check <<< " $pips_to_check"
11491207
@@ -1165,7 +1223,7 @@ function _tue-install-pip-now
11651223 pips_to_check_options_removed=" $pips_to_check_options_removed ${pkg_split[0]} "
11661224 done
11671225 # shellcheck disable=SC2086
1168- _tue-install-pip-check " $pv " $ pips_to_check_options_removed
1226+ _tue-install-pip-check " ${pv} " --python-site= ${python_site} ${ pips_to_check_options_removed}
11691227
11701228 read -r -a pips_to_check_w_options <<< " $pips_to_check_w_options"
11711229
@@ -1181,15 +1239,15 @@ function _tue-install-pip-now
11811239 if [ -n " $pips_to_install " ]
11821240 then
11831241 # shellcheck disable=SC2048,SC2086
1184- tue-install-pipe python " ${pv } " -m pip install ${user_arg} $pips_to_install <<< yes || tue-install-error " An error occurred while installing pip${pv} packages."
1242+ tue-install-pipe ${sudo_cmd : + ${sudo_cmd} } " ${python_exec } " ${site_arg : + ${site_arg} } -m pip install ${user_arg: + ${user_arg} } $pips_to_install <<< yes || tue-install-error " An error occurred while installing pip${pv} packages."
11851243 fi
11861244
11871245 if [ -n " $pips_to_install_w_options " ]
11881246 then
11891247 for pkg in $pips_to_install_w_options
11901248 do
11911249 # shellcheck disable=SC2048,SC2086
1192- tue-install-pipe python " ${pv } " -m pip install ${user_arg} ${pkg// ^/ } <<< yes || tue-install-error " An error occurred while installing pip${pv} packages with options."
1250+ tue-install-pipe${sudo_cmd : + ${sudo_cmd} } " ${python_exec } " ${site_arg : + ${site_arg} } -m pip install ${user_arg: + ${user_arg} } ${pkg// ^/ } <<< yes || tue-install-error " An error occurred while installing pip${pv} packages with options."
11931251 done
11941252 fi
11951253
@@ -1198,7 +1256,7 @@ function _tue-install-pip-now
11981256 for pkg in $git_pips_to_install
11991257 do
12001258 # shellcheck disable=SC2048,SC2086
1201- tue-install-pipe python " ${pv} " -m pip install ${user_arg} ${pkg} <<< yes || tue-install-error " An error occurred while installing pip${pv} git packages."
1259+ tue-install-pipe ${sudo_cmd : + ${sudo_cmd} } " ${python_exec} " ${site_arg : + ${site_arg} } -m pip install ${user_arg: + ${user_arg} } ${pkg} <<< yes || tue-install-error " An error occurred while installing pip${pv} git packages."
12021260 done
12031261 fi
12041262}
@@ -1210,12 +1268,35 @@ function _tue-install-pip-check
12101268 pv=$1
12111269 shift
12121270
1213- local pips_to_check installed_versions
1214- pips_to_check=(" $@ " )
1271+ local installed_versions python_site pips_to_check
1272+ if [[ -n $1 ]]
1273+ then
1274+ for i in " $@ "
1275+ do
1276+ case $i in
1277+ --python-site=* )
1278+ python_site=" ${i#* =} " ;;
1279+ --* )
1280+ tue-install-error " Unknown input variable ${i} " ;;
1281+ * )
1282+ pips_to_check+=(" $i " ) ;;
1283+ esac
1284+ done
1285+ fi
1286+
1287+ if [[ -z " ${VIRTUAL_ENV} " && " ${python_site} " == " venv" ]]
1288+ then
1289+ tue-install-error " Trying to check pip packages in a virtualenv, but no virtualenv is activated"
1290+ fi
1291+
1292+ # Set by _handle_python_sites
1293+ local python_exec sudo_cmd site_arg user_arg
1294+ _handle_python_sites " ${pv} " " ${python_site} "
1295+
12151296 if [ ${# pips_to_check[@]} -gt 0 ]
12161297 then
12171298 local error_code
1218- installed_versions=$( python " ${pv} " " $ TUE_INSTALL_SCRIPTS_DIR" /check-pip-pkg-installed-version.py " ${pips_to_check[@]} " )
1299+ installed_versions=$( ${python_exec} ${site_arg : + ${site_arg} } " ${ TUE_INSTALL_SCRIPTS_DIR} " /check-pip-pkg-installed-version.py " ${pips_to_check[@]} " )
12191300 error_code=$?
12201301 if [ " $error_code " -gt 1 ]
12211302 then
@@ -1623,7 +1704,8 @@ TUE_INSTALL_INFOS=
16231704# Make sure tools used by this installer are installed
16241705tue-install-system-now curl git jq python-is-python3 python3-pip wget
16251706
1626- tue-install-pip3-now catkin-pkg PyYAML
1707+ # Install in user or system site-packages
1708+ tue-install-pip3-now --python-site=" user" catkin-pkg PyYAML
16271709
16281710
16291711# Handling of targets
0 commit comments