From f9d04b4e17f001b568c2a8c476cb7fbd7f578eab Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Tue, 3 Sep 2024 15:05:11 +0200 Subject: [PATCH] small cleanup --- installer/parse_install_yaml.py | 54 ++++++++++++++++----------------- setup/tue-functions.bash | 12 ++++---- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/installer/parse_install_yaml.py b/installer/parse_install_yaml.py index 54490991b..dc8b74b49 100755 --- a/installer/parse_install_yaml.py +++ b/installer/parse_install_yaml.py @@ -17,7 +17,7 @@ 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 @@ -25,7 +25,7 @@ def type_git(install_item: Mapping, allowed_keys: Optional[List[str]] = None) -> 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 """ @@ -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 @@ -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 """ @@ -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: @@ -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: @@ -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()) diff --git a/setup/tue-functions.bash b/setup/tue-functions.bash index b93286956..18aa98c57 100644 --- a/setup/tue-functions.bash +++ b/setup/tue-functions.bash @@ -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 @@ -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