@@ -168,7 +168,7 @@ function _remove_old_target_dep_recursively
168168 old_dep_dep_file=" ${TUE_INSTALL_DEPENDENCIES_DIR} " /" ${old_dep_target} "
169169 if [[ -f " ${old_dep_dep_file} " ]]
170170 then
171- # Iterate over all depencies of old_dep_target, which is removed.
171+ # Iterate over all dependencies of old_dep_target, which is removed.
172172 while read -r dep_of_old_dep
173173 do
174174 # Actually remove the deps
@@ -183,11 +183,11 @@ function _remove_old_target_dep_recursively
183183 done < " ${old_dep_dep_file} "
184184 rm -f " ${old_dep_dep_file} "
185185 else
186- tue-install-debug " [remove_old_dep] No depencies file exist for target: ${old_dep_target} "
186+ tue-install-debug " [remove_old_dep] No dependencies file exist for target: ${old_dep_target} "
187187 fi
188188
189189 tue-install-debug " [remove_old_dep] Uninstalled '${old_dep_target} ' as a dependency of '${parent_target} '"
190- tue-install-info " [remove_old_dep] '${old_dep_target} ' has been uninstalled, you can remove it from the workspace or deinstall it in another way"
190+ tue-install-info " [remove_old_dep] '${old_dep_target} ' has been uninstalled, you can remove it from the workspace or uninstall it in another way"
191191 return ${error_code}
192192}
193193
@@ -309,7 +309,7 @@ function tue-install-target
309309 [ " $now " == " true" ] && now_cmd=" --now"
310310 # Do not use 'local cmds=' because it does not preserve command output status ($?)
311311 local cmds
312- if cmds=$( " $ TUE_INSTALL_SCRIPTS_DIR" /parse_install_yaml.py " $install_file " .yaml $now_cmd )
312+ if cmds=$( /usr/bin/python " ${ TUE_INSTALL_SCRIPTS_DIR} " /parse_install_yaml.py " ${ install_file} " .yaml ${ now_cmd} )
313313 then
314314 for cmd in $cmds
315315 do
@@ -352,7 +352,7 @@ function tue-install-target
352352 old_deps_removed=$( comm -23 <( echo " ${old_deps} " ) <( echo " ${new_deps} " ) )
353353 if [[ -n ${old_deps_removed} ]]
354354 then
355- tue-install-debug " Following dropped depedencies need to be removed:\n${old_deps_removed} "
355+ tue-install-debug " Following dropped dependencies need to be removed:\n${old_deps_removed} "
356356 else
357357 tue-install-debug " No dropped dependencies to be removed"
358358 fi
@@ -361,7 +361,7 @@ function tue-install-target
361361 do
362362 # Remove this target from dep-on file of dep
363363 # When the dep-on file is now empty, remove it
364- # Recurisvely -> Remove it from the dep-on files of its deps
364+ # Recursively -> Remove it from the dep-on files of its deps
365365 tue-install-debug " Going to remove '${dep} ' as a dependency"
366366 _remove_old_target_dep_recursively " ${target} " " ${dep} " || tue-install-error " Something went wrong while removing '${dep} ' as a dependency"
367367 done
@@ -1093,6 +1093,49 @@ 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 site
1106+ site=$1
1107+
1108+ case ${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 variable ${i} "
1129+ ;;
1130+ esac
1131+
1132+ tue-install-debug " python_site: ${python_site} "
1133+ tue-install-debug " python_exec: ${python_exec} "
1134+ tue-install-debug " site_arg: ${site_arg} "
1135+ tue-install-debug " sudo_cmd: ${sudo_cmd} "
1136+ tue-install-debug " user_arg: ${user_arg} "
1137+ }
1138+
10961139function _tue-install-pip-now
10971140{
10981141 local pv
@@ -1105,25 +1148,42 @@ function _tue-install-pip-now
11051148 tue-install-error " Invalid tue-install-pip${pv} -now call: needs package as argument."
11061149 fi
11071150
1108- local user_arg
1109- [[ -z " ${VIRTUAL_ENV} " ]] && user_arg=" --user"
1151+ local pips python_site
1152+ { [[ -n ${VIRTUAL_ENV} ]] && python_site=" venv" ; } || python_site=" user"
1153+ if [[ -n $1 ]]
1154+ then
1155+ for i in " $@ "
1156+ do
1157+ case $i in
1158+ --python-site=* )
1159+ python_site=" ${i#* =} "
1160+ ;;
1161+ --* )
1162+ tue-install-error " tue-install-pip${pv} -now: Unknown input variable ${i} " ;;
1163+ * )
1164+ pips+=(" $i " ) ;;
1165+ esac
1166+ done
1167+ fi
1168+
1169+ local python_exec site_arg sudo_cmd user_arg
1170+ _handle_python_sites " ${pv} " " ${python_site} "
11101171
11111172 # Make sure pip is up-to-date before checking version and installing
11121173 local pip_version desired_pip_version
1113- pip_version=$( python" ${pv} " -m pip --version | awk ' {print $2}' )
1174+ pip_version=$( python" ${pv} " ${site_arg} -m pip --version | awk ' {print $2}' )
11141175 desired_pip_version=" 23"
11151176 if version_gt " $desired_pip_version " " $pip_version "
11161177 then
11171178 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
1179+ tue-install-pipe python" ${pv} " ${site_arg} -m pip install " ${user_arg} " --upgrade pip
11191180 hash -r
11201181 else
11211182 tue-install-debug " Already pip${pv} >=$desired_pip_version "
11221183 fi
11231184
11241185 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 $*
1186+ for pkg in " ${pips[@]} "
11271187 do
11281188 if [[ " $pkg " == " git+" * ]]
11291189 then
@@ -1143,7 +1203,7 @@ function _tue-install-pip-now
11431203 then
11441204 local indexes_to_install
11451205 # shellcheck disable=SC2086
1146- _tue-install-pip-check " $pv " $ pips_to_check
1206+ _tue-install-pip-check " ${pv} " --python-site= ${python_site} ${ pips_to_check}
11471207
11481208 read -r -a pips_to_check <<< " $pips_to_check"
11491209
@@ -1165,7 +1225,7 @@ function _tue-install-pip-now
11651225 pips_to_check_options_removed=" $pips_to_check_options_removed ${pkg_split[0]} "
11661226 done
11671227 # shellcheck disable=SC2086
1168- _tue-install-pip-check " $pv " $ pips_to_check_options_removed
1228+ _tue-install-pip-check " ${pv} " --python-site= ${python_site} ${ pips_to_check_options_removed}
11691229
11701230 read -r -a pips_to_check_w_options <<< " $pips_to_check_w_options"
11711231
@@ -1181,15 +1241,15 @@ function _tue-install-pip-now
11811241 if [ -n " $pips_to_install " ]
11821242 then
11831243 # 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."
1244+ tue-install-pipe ${sudo_cmd} ${python_exec} ${site_arg} -m pip install ${user_arg} $pips_to_install <<< yes || tue-install-error " An error occurred while installing pip${pv} packages."
11851245 fi
11861246
11871247 if [ -n " $pips_to_install_w_options " ]
11881248 then
11891249 for pkg in $pips_to_install_w_options
11901250 do
11911251 # 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."
1252+ tue-install-pipe ${sudo_cmd} ${python_exec} ${site_arg} -m pip install ${user_arg} ${pkg// ^/ } <<< yes || tue-install-error " An error occurred while installing pip${pv} packages with options."
11931253 done
11941254 fi
11951255
@@ -1198,7 +1258,7 @@ function _tue-install-pip-now
11981258 for pkg in $git_pips_to_install
11991259 do
12001260 # 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."
1261+ tue-install-pipe ${sudo_cmd} ${python_exec} ${site_arg} -m pip install ${user_arg} ${pkg} <<< yes || tue-install-error " An error occurred while installing pip${pv} git packages."
12021262 done
12031263 fi
12041264}
@@ -1210,12 +1270,36 @@ function _tue-install-pip-check
12101270 pv=$1
12111271 shift
12121272
1213- local pips_to_check installed_versions
1214- pips_to_check=(" $@ " )
1273+ local installed_versions python_site pips_to_check
1274+ if [[ -n $1 ]]
1275+ then
1276+ for i in " $@ "
1277+ do
1278+ case $i in
1279+ --python-site=* )
1280+ python_site=" ${i#* =} "
1281+ ;;
1282+ --* )
1283+ tue-install-error " Unknown input variable ${i} " ;;
1284+ * )
1285+ pips_to_check+=(" $i " ) ;;
1286+ esac
1287+ done
1288+ fi
1289+
1290+ if [[ -z " ${VIRTUAL_ENV} " && " ${site} " == " venv" ]]
1291+ then
1292+ tue-install-error " Trying to check pip packages in a virtualenv, but no virtualenv is activated"
1293+ fi
1294+
1295+ # Set by _handle_python_sites
1296+ local python_exec sudo_cmd site_arg user_arg
1297+ _handle_python_sites " ${pv} " " ${python_site} "
1298+
12151299 if [ ${# pips_to_check[@]} -gt 0 ]
12161300 then
12171301 local error_code
1218- installed_versions=$( python " ${pv } " " $ TUE_INSTALL_SCRIPTS_DIR" /check-pip-pkg-installed-version.py " ${pips_to_check[@]} " )
1302+ installed_versions=$( ${sudo_cmd} " ${python_exec } " ${site_arg} " ${ TUE_INSTALL_SCRIPTS_DIR} " /check-pip-pkg-installed-version.py " ${pips_to_check[@]} " )
12191303 error_code=$?
12201304 if [ " $error_code " -gt 1 ]
12211305 then
@@ -1493,10 +1577,11 @@ function tue-install-ros
14931577 local pkg_xml=" $ros_pkg_dir " /package.xml
14941578 if [ -f " $pkg_xml " ]
14951579 then
1496- # Catkin
1580+ # catkin/ament/colcon
14971581 tue-install-debug " Parsing $pkg_xml "
1582+
14981583 local deps
1499- deps=$( " $ TUE_INSTALL_SCRIPTS_DIR" /parse_package_xml.py " $pkg_xml " )
1584+ deps=$( /usr/bin/python " ${ TUE_INSTALL_SCRIPTS_DIR} " /parse_package_xml.py " ${ pkg_xml} " )
15001585 tue-install-debug " Parsed package.xml\n$deps "
15011586
15021587 for dep in $deps
@@ -1636,7 +1721,8 @@ TUE_INSTALL_INFOS=
16361721# Make sure tools used by this installer are installed
16371722tue-install-system-now curl git jq python-is-python3 python3-pip wget
16381723
1639- tue-install-pip3-now catkin-pkg PyYAML
1724+ # Install in user or system site-packages
1725+ tue-install-pip3-now --python-site=" user" catkin-pkg PyYAML
16401726
16411727
16421728# Handling of targets
16741760 tue-install-debug " [$target ] marked as installed after a successful install"
16751761 touch " $TUE_INSTALL_INSTALLED_DIR " /" $target "
16761762 else
1677- tue-install-debug " [$target ] succesfully updated"
1763+ tue-install-debug " [$target ] successfully updated"
16781764 fi
16791765done
16801766
17461832
17471833TUE_INSTALL_CURRENT_TARGET=" main-loop"
17481834
1749- tue-install-echo " Installer completed succesfully "
1835+ tue-install-echo " Installer completed successfully "
17501836
17511837return 0
0 commit comments