Skip to content

Commit 6f4c0b4

Browse files
Support pip options (#607)
* pip2 has been removed for a long time * put repeated code in function * put repeated code in function * Add pip option support * Remove desired pip version of python2 * Bump desired pip version to 22 * Bump version to 1.0.7
1 parent ec1ad98 commit 6f4c0b4

File tree

3 files changed

+124
-62
lines changed

3 files changed

+124
-62
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.6
1+
1.0.7

installer/parse-install-yaml.py

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,28 @@ def main():
3939

4040
commands = []
4141

42+
def commands_append(command: str):
43+
command = command.replace(" ", "^")
44+
commands.append(command)
45+
46+
def get_distro_item(item: dict, key: str, release_version: str, release_type: str):
47+
if key in item:
48+
value = item[key]
49+
if value is None:
50+
raise ValueError(f"'{key}' is defined, but has no value")
51+
else:
52+
if release_version in item:
53+
value = item[release_version][key]
54+
elif "default" in item:
55+
value = item["default"][key]
56+
else:
57+
return show_error(f"{release_type} distro {release_version} or 'default' not specified in install.yaml")
58+
return value
59+
4260
# Combine now calls
4361
now_cache = {
4462
"system-now": [],
4563
"pip-now": [],
46-
"pip2-now": [],
4764
"pip3-now": [],
4865
"ppa-now": [],
4966
"snap-now": [],
@@ -59,20 +76,14 @@ def main():
5976
return 0
6077

6178
elif install_type == "ros":
62-
if "source" in install_item:
63-
source = install_item["source"]
64-
else:
65-
if ros_release in install_item:
66-
source = install_item[ros_release]["source"]
67-
elif "default" in install_item:
68-
source = install_item["default"]["source"]
69-
else:
70-
return show_error(
71-
"ROS distro {} or 'default' not specified in install.yaml".format(ros_release)
72-
)
73-
# Both release and default are allowed to be None
74-
if source is None:
75-
continue
79+
try:
80+
source = get_distro_item(install_item, "source", ros_release, "ROS")
81+
except ValueError as e:
82+
return show_error(f"[{install_type}]: {e.args[0]}")
83+
84+
# Both release and default are allowed to be None
85+
if source is None:
86+
continue
7687

7788
source_type = source["type"]
7889
if source_type == "git":
@@ -95,36 +106,28 @@ def main():
95106
"target",
96107
"system",
97108
"pip",
98-
"pip2",
99109
"pip3",
100110
"ppa",
101111
"snap",
102112
"dpkg",
103113
"target-now",
104114
"system-now",
105115
"pip-now",
106-
"pip2-now",
107116
"pip3-now",
108117
"ppa-now",
109118
"snap-now",
110119
]:
111120
if now and "now" not in install_type:
112121
install_type += "-now"
113122

114-
if "name" in install_item:
115-
pkg_name = install_item["name"]
116-
else:
117-
if ubuntu_release in install_item:
118-
pkg_name = install_item[ubuntu_release]["name"]
119-
elif "default" in install_item:
120-
pkg_name = install_item["default"]["name"]
121-
else:
122-
return show_error(
123-
"Ubuntu distro {} or 'default' not specified in install.yaml".format(ubuntu_release)
124-
)
125-
# Both release and default are allowed to be None
126-
if pkg_name is None:
127-
continue
123+
try:
124+
pkg_name = get_distro_item(install_item, "name", ubuntu_release, "Ubuntu")
125+
except ValueError as e:
126+
return show_error(f"[{install_type}]: {e.args[0]}")
127+
128+
# Both release and default are allowed to be None
129+
if pkg_name is None:
130+
continue
128131

129132
# Cache install types which accept multiple pkgs at once
130133
if install_type in now_cache:
@@ -142,14 +145,12 @@ def main():
142145
if not command:
143146
return show_error("Invalid install.yaml file")
144147

145-
command = command.replace(" ", "^")
146-
commands.append(command)
148+
commands_append(command)
147149

148150
for install_type, pkg_list in now_cache.items():
149151
if pkg_list:
150152
command = "tue-install-{0} {1}".format(install_type, " ".join(pkg_list))
151-
command = command.replace(" ", "^")
152-
commands.append(command)
153+
commands_append(command)
153154

154155
commands = " ".join(commands)
155156

installer/tue-install-impl.bash

Lines changed: 87 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -810,15 +810,18 @@ function _tue-install-pip
810810
local pv=$1
811811
shift
812812
tue-install-debug "tue-install-pip${pv} $*"
813+
local name="$*"
814+
name="${name// /^}"
813815

814816
if [ -z "$1" ]
815817
then
816818
tue-install-error "Invalid tue-install-pip${pv} call: needs package as argument."
817819
fi
818-
tue-install-debug "Adding $1 to pip${pv} list"
820+
821+
tue-install-debug "Adding $name to pip${pv} list"
819822
local list=TUE_INSTALL_PIP"${pv}"S
820823
# shellcheck disable=SC2140
821-
declare -g "$list"="$1 ${!list}"
824+
declare -g "$list"="$name ${!list}"
822825
}
823826

824827
# Needed for backward compatibility
@@ -848,11 +851,7 @@ function _tue-install-pip-now
848851
# Make sure pip is up-to-date before checking version and installing
849852
local pip_version desired_pip_version
850853
pip_version=$(python"${pv}" -m pip --version | awk '{print $2}')
851-
desired_pip_version="21"
852-
if [ "$pv" == 2 ]
853-
then
854-
desired_pip_version="20"
855-
fi
854+
desired_pip_version="22"
856855
if version_gt "$desired_pip_version" "$pip_version"
857856
then
858857
tue-install-debug "pip${pv} not yet version >=$desired_pip_version, but $pip_version"
@@ -863,7 +862,9 @@ function _tue-install-pip-now
863862
fi
864863

865864
local pips_to_check=""
865+
local pips_to_check_w_options=""
866866
local pips_to_install=""
867+
local pips_to_install_w_options=""
867868
local git_pips_to_install=""
868869
# shellcheck disable=SC2048
869870
for pkg in $*
@@ -872,19 +873,94 @@ function _tue-install-pip-now
872873
then
873874
git_pips_to_install="$git_pips_to_install $pkg"
874875
else
875-
pips_to_check="$pips_to_check $pkg"
876+
read -r -a pkg_split <<< "${pkg//^/ }"
877+
if [ ${#pkg_split[@]} -gt 1 ]
878+
then
879+
pips_to_check_w_options="$pips_to_check_w_options $pkg"
880+
else
881+
pips_to_check="$pips_to_check $pkg"
882+
fi
876883
fi
877884
done
878885

879-
read -r -a pips_to_check <<< "$pips_to_check"
886+
if [ -n "$pips_to_check" ]
887+
then
888+
local indexes_to_install=""
889+
# shellcheck disable=SC2086
890+
_tue-install-pip-check "$pv" $pips_to_check
891+
892+
read -r -a pips_to_check <<< "$pips_to_check"
893+
894+
for idx in $indexes_to_install
895+
do
896+
local pkg_req="${pips_to_check[$idx]}"
897+
tue-install-debug "Going to install $pkg_req"
898+
pips_to_install="$pips_to_install $pkg_req"
899+
done
900+
fi
901+
902+
if [ -n "$pips_to_check_w_options" ]
903+
then
904+
local indexes_to_install=""
905+
local pips_to_check_options_removed=""
906+
for pkg in $pips_to_check_w_options
907+
do
908+
read -r -a pkg_split <<< "${pkg//^/ }"
909+
pips_to_check_options_removed="$pips_to_check_options_removed ${pkg_split[0]}"
910+
done
911+
# shellcheck disable=SC2086
912+
_tue-install-pip-check "$pv" $pips_to_check_options_removed
913+
914+
read -r -a pips_to_check_w_options <<< "$pips_to_check_w_options"
915+
916+
for idx in $indexes_to_install
917+
do
918+
local pkg_req="${pips_to_check_w_options[$idx]}"
919+
tue-install-debug "Going to install $pkg_req"
920+
pips_to_install_w_options="$pips_to_install_w_options $pkg_req"
921+
done
922+
fi
923+
924+
if [ -n "$pips_to_install" ]
925+
then
926+
# shellcheck disable=SC2048,SC2086
927+
tue-install-pipe python"${pv}" -m pip install --user $pips_to_install <<< yes || tue-install-error "An error occurred while installing pip${pv} packages."
928+
fi
929+
930+
if [ -n "$pips_to_install_w_options" ]
931+
then
932+
for pkg in $pips_to_install_w_options
933+
do
934+
# shellcheck disable=SC2048,SC2086
935+
tue-install-pipe python"${pv}" -m pip install --user ${pkg//^/ } <<< yes || tue-install-error "An error occurred while installing pip${pv} packages with options."
936+
done
937+
fi
938+
939+
if [ -n "$git_pips_to_install" ]
940+
then
941+
for pkg in $git_pips_to_install
942+
do
943+
# shellcheck disable=SC2048,SC2086
944+
tue-install-pipe python"${pv}" -m pip install --user $pkg <<< yes || tue-install-error "An error occurred while installing pip${pv} git packages."
945+
done
946+
fi
947+
}
948+
949+
function _tue-install-pip-check
950+
{
951+
tue-install-debug "_tue-install-pip-check $*"
952+
local pv=$1
953+
shift
954+
955+
local pips_to_check=("$@")
880956
local installed_versions
881957
if [ ${#pips_to_check[@]} -gt 0 ]
882958
then
883959
installed_versions=$(python"${pv}" "$TUE_INSTALL_SCRIPTS_DIR"/check-pip-pkg-installed-version.py "${pips_to_check[@]}")
884960
local error_code=$?
885961
if [ "$error_code" -gt 1 ]
886962
then
887-
tue-install-error "tue-install-pip${pv}-now: $installed_versions"
963+
tue-install-error "_tue-install-pip${pv}-check: $installed_versions"
888964
fi
889965
fi
890966
read -r -a installed_versions <<< "$installed_versions"
@@ -901,26 +977,11 @@ function _tue-install-pip-now
901977
pkg_installed="${pkg_installed//^/ }"
902978
if [[ "$error_code" -eq 1 && "$pkg_installed" == "None" ]]
903979
then
904-
pips_to_install="$pips_to_install $pkg_req"
980+
indexes_to_install="$indexes_to_install $idx" # indexes_to_install is a "global" variable from tue-install-pip-now
905981
else
906982
tue-install-debug "$pkg_req is already installed, $pkg_installed"
907983
fi
908984
done
909-
910-
if [ -n "$pips_to_install" ]
911-
then
912-
# shellcheck disable=SC2048,SC2086
913-
tue-install-pipe python"${pv}" -m pip install --user $pips_to_install <<< yes || tue-install-error "An error occurred while installing pip${pv} packages."
914-
fi
915-
916-
if [ -n "$git_pips_to_install" ]
917-
then
918-
for pkg in $git_pips_to_install
919-
do
920-
# shellcheck disable=SC2048,SC2086
921-
tue-install-pipe python"${pv}" -m pip install --user $pkg <<< yes || tue-install-error "An error occurred while installing pip${pv} packages."
922-
done
923-
fi
924985
}
925986

926987
# Needed for backward compatibility

0 commit comments

Comments
 (0)