From 8778a305f48a33846fda59a3d1931b8fada1429b Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Mon, 2 Sep 2024 14:00:24 +0100 Subject: [PATCH] More robust `choco` install and helpful `install_deps.py` messages (#7461) * Only show error/success conditionally * Make choco install more robust * Improve deps script to remind about restarting shells * Add note about Mac Qt * Update ChangeLog --- ChangeLog | 1 + scripts/install_deps.py | 20 +++++++++++++++++++- scripts/lib/colors.py | 4 ++-- scripts/lib/windows.py | 31 +++++++++++++++++++++++++------ 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5528710b9..36fe131da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ Enhancements: - #7445 Update `config.yaml` to support Linux Mint build target - #7453 Change default value for dev thanks message - #7455 Use EI screen when XDG_SESSION_TYPE is "wayland" +- #7461 More robust `choco` install and helpful `install_deps.py` messages # 1.15.1 diff --git a/scripts/install_deps.py b/scripts/install_deps.py index 9cb354173..6713f0c3d 100755 --- a/scripts/install_deps.py +++ b/scripts/install_deps.py @@ -52,9 +52,23 @@ def main(): colors = env.import_colors() print() - print(f"{colors.SUCCESS_TEXT} Dependencies installed") + if error: + print(f"{colors.ERROR_TEXT} Failed to install dependencies") + else: + print(f"{colors.SUCCESS_TEXT} Dependencies installed") + + # On Windows and macOS, we set env vars for cmake, but for them to be picked up, + # either the shell needs to be restarted or the env vars need to be re-sourced. + # Restarting the shell is easier for most people. + if not env.is_linux(): + print(f"{colors.WARNING_TEXT} Please restart your shells for new env vars") + + # Useful on Windows, when elevated, Python is opened in a new window and closes + # immediately after the script finishes. This keeps the script window open so that + # the user can see the output. if args.pause_on_exit: + print() input("Press enter to continue...") if error: @@ -138,6 +152,10 @@ class Dependencies: """Installs dependencies on macOS.""" import lib.mac as mac + # On macOS, brew does have a Qt package available, but it is always built against the + # current macOS version and the brew version also does some really weird stuff with the + # library symbols, which confuses the heck out of `macqtdeploy`. So, using the official + # Qt library binaries seems to be the most reliable option for distribution. qt = qt_utils.MacQt(*self.config.get_qt_config()) qt.install() diff --git a/scripts/lib/colors.py b/scripts/lib/colors.py index b61697ad6..646893992 100644 --- a/scripts/lib/colors.py +++ b/scripts/lib/colors.py @@ -3,7 +3,7 @@ from colorama import Fore # type: ignore colorama.init() -SUCCESS_TEXT = f"{Fore.GREEN}Success:{Fore.RESET}" +SUCCESS_TEXT = f"{Fore.LIGHTGREEN_EX}Success:{Fore.RESET}" ERROR_TEXT = f"{Fore.RED}Error:{Fore.RESET}" -WARNING_TEXT = f"{Fore.YELLOW}Warning:{Fore.RESET}" +WARNING_TEXT = f"{Fore.LIGHTYELLOW_EX}Warning:{Fore.RESET}" HINT_TEXT = f"{Fore.LIGHTBLUE_EX}Hint:{Fore.RESET}" diff --git a/scripts/lib/windows.py b/scripts/lib/windows.py index 72ef6d4a1..dc014671a 100644 --- a/scripts/lib/windows.py +++ b/scripts/lib/windows.py @@ -147,12 +147,8 @@ class WindowsChoco: print_cmd=True, ) else: - cmd_utils.run( - "winget install chocolatey", - check=False, - shell=True, - print_cmd=True, - ) + self.ensure_choco_installed() + cmd_utils.run( command, shell=True, @@ -186,3 +182,26 @@ class WindowsChoco: print(f"Removed package from choco config: {remove}") tree.write(choco_config_file) + + def ensure_choco_installed(self): + if cmd_utils.has_command("choco"): + return + + if not cmd_utils.has_command("winget"): + print("The winget command was not found", file=sys.stderr) + sys.exit(1) + + print("The choco command was not found, installing Chocolatey...") + cmd_utils.run( + "winget install chocolatey", + check=False, + shell=True, + print_cmd=True, + ) + + if not cmd_utils.has_command("choco"): + print( + "The choco command was still not found, please re-run this script...", + file=sys.stderr, + ) + sys.exit(1)