Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small cleanup #750

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.27.0
1.27.1
54 changes: 27 additions & 27 deletions installer/parse_install_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def show_error(error: str) -> int:

def type_git(install_item: Mapping, allowed_keys: Optional[List[str]] = None) -> str:
"""
Function to check the parsed yaml for install type git and generate the command string.
Function to check the parsed YAML for install type git and generate the command string.

The structure of a git install type is:
- type: git
url: <REPOSITORY_URL>
path: [LOCAL_CLONE_PATH]
version: [BRANCH_COMMIT_TAG]

:param install_item: Extracted yaml component corresponding to install type git
:param install_item: Extracted YAML component corresponding to install type git
:param allowed_keys: Additional keys to allow apart from the keys defined in install type git
:return: Command string containing repository url and optional arguments target-dir and version
"""
Expand Down Expand Up @@ -94,7 +94,7 @@ def type_apt_key_source(install_item: Mapping) -> str:

def catkin_git(source: Mapping) -> str:
"""
Function to generate installation command for catkin git targets from the extracted yaml
Function to generate installation command for catkin git targets from the extracted YAML

The structure of a catkin git install type is:
- type: catkin/ros
Expand All @@ -105,7 +105,7 @@ def catkin_git(source: Mapping) -> str:
version: [BRANCH_COMMIT_TAG]
sub-dir: [PACKAGE_SUB_DIRECTORY]

:param source: Extracted yaml component for the key 'source' corresponding to install type catkin/ros
:param source: Extracted YAML component for the key 'source' corresponding to install type catkin/ros
:return: Command string containing arguments to the primary catkin target installation command
"""

Expand All @@ -119,28 +119,6 @@ def catkin_git(source: Mapping) -> str:
return command


def main() -> int:
if not 2 <= len(sys.argv) <= 3:
return show_error("Usage: parse_install_yaml install.yaml [--now]")

now = False
if len(sys.argv) == 3:
if sys.argv[2] == "--now":
now = True
else:
return show_error(f"Unknown option: {sys.argv[2]}")

try:
result = install_yaml_parser(sys.argv[1], now)
except Exception as e:
return show_error(str(e))

if result["commands"]:
print(result["commands"])

return 0


def install_yaml_parser(path: str, now: bool = False) -> Mapping[str, str]:
with open(path) as f:
try:
Expand Down Expand Up @@ -202,7 +180,7 @@ def get_distro_item(
# TODO(anyone): Remove the use of TUE_XXX, when migration to TUE_ENV_XXX is complete
try:
ros_release = environ["TUE_ENV_ROS_DISTRO"]
except KeyError as e:
except KeyError:
try:
ros_release = environ["TUE_ROS_DISTRO"]
except KeyError:
Expand Down Expand Up @@ -311,5 +289,27 @@ def get_distro_item(
return {"system_packages": system_packages, "commands": " ".join(commands)}


def main() -> int:
if not 2 <= len(sys.argv) <= 3:
return show_error("Usage: parse_install_yaml install.yaml [--now]")

now: bool = False
if len(sys.argv) == 3:
if sys.argv[2] == "--now":
now = True
else:
return show_error(f"Unknown option: {sys.argv[2]}")

try:
result = install_yaml_parser(sys.argv[1], now)
except Exception as e:
return show_error(str(e))

if result["commands"]:
print(result["commands"])

return 0


if __name__ == "__main__":
sys.exit(main())
6 changes: 4 additions & 2 deletions setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function _tue-check-env-vars
}
export -f _tue-check-env-vars

function main
function _tue-env-main
{
# -----------------------------------------
# Set the TUE_DIR variable
Expand Down Expand Up @@ -108,4 +108,6 @@ function main
fi
}

main "$@"
_tue-env-main "$@"

unset -f _tue-env-main
12 changes: 6 additions & 6 deletions setup/tue-functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -873,18 +873,18 @@ function _remove_recursively
return 1
fi

local target tue_dependencies_dir tue_dependencies_on_dir error_code
target=$1
tue_dependencies_dir="$TUE_ENV_DIR"/.env/dependencies
tue_dependencies_on_dir="$TUE_ENV_DIR"/.env/dependencies-on
local error_code target tue_dependencies_dir tue_dependencies_on_dir
error_code=0
target=$1
tue_dependencies_dir="${TUE_ENV_DIR}"/.env/dependencies
tue_dependencies_on_dir="${TUE_ENV_DIR}"/.env/dependencies-on

# If packages depend on the target to be removed, just remove the installed status.
if [ -f "$tue_dependencies_on_dir"/"$target" ]
then
if [[ -n $(cat "$tue_dependencies_on_dir"/"$target") ]]
then
# depend-on is not empty, so removing the installed status
# depend-on is not empty, so only removing the installed status
echo "[tue-get] Other targets still depend on $target, so ignoring it"
return 0
else
Expand All @@ -909,7 +909,7 @@ function _remove_recursively
while read -r line
do
[[ $line != "$target" ]] && echo "$line"
done <"$dep_dep_on_file" >"$tmp_file"
done < "${dep_dep_on_file}" > "${tmp_file}"
mv "$tmp_file" "$dep_dep_on_file"
echo "[tue-get] Removed '$target' from depend-on file of '$dep'"
else
Expand Down