From 7b61e7e4bc267ca72107b1120d0355a9fd649395 Mon Sep 17 00:00:00 2001 From: Elijah Ahianyo Date: Thu, 18 Apr 2024 20:00:41 -0700 Subject: [PATCH] Use Fallback command on all platforms (#3099) * Use Fallback command on all platforms * precommit fix * obtain the loglevel cmd for fallback as well * address PR comment --- reflex/utils/prerequisites.py | 10 ++++++---- reflex/utils/processes.py | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index cb250b2c1..e69eb3c5a 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -821,14 +821,16 @@ def install_frontend_packages(packages: set[str], config: Config): Example: >>> install_frontend_packages(["react", "react-dom"], get_config()) """ - # unsupported archs will use npm anyway. so we dont have to run npm twice + # unsupported archs(arm and 32bit machines) will use npm anyway. so we dont have to run npm twice fallback_command = ( - get_package_manager() - if constants.IS_WINDOWS and constants.IS_WINDOWS_BUN_SUPPORTED_MACHINE + get_install_package_manager() + if not constants.IS_WINDOWS + or constants.IS_WINDOWS + and constants.IS_WINDOWS_BUN_SUPPORTED_MACHINE else None ) processes.run_process_with_fallback( - [get_install_package_manager(), "install", "--loglevel", "silly"], + [get_install_package_manager(), "install"], # type: ignore fallback=fallback_command, show_status_message="Installing base frontend packages", cwd=constants.Dirs.WEB, diff --git a/reflex/utils/processes.py b/reflex/utils/processes.py index 67887754f..c08901b7e 100644 --- a/reflex/utils/processes.py +++ b/reflex/utils/processes.py @@ -8,6 +8,7 @@ import os import signal import subprocess from concurrent import futures +from pathlib import Path from typing import Callable, Generator, List, Optional, Tuple, Union import psutil @@ -297,6 +298,25 @@ def atexit_handler(): console.log("Reflex app stopped.") +def get_command_with_loglevel(command: list[str]) -> list[str]: + """Add the right loglevel flag to the designated command. + npm uses --loglevel , Bun doesnt use the --loglevel flag and + runs in debug mode by default. + + Args: + command:The command to add loglevel flag. + + Returns: + The updated command list + """ + npm_path = path_ops.get_npm_path() + npm_path = str(Path(npm_path).resolve()) if npm_path else npm_path + + if command[0] == npm_path: + return command + ["--loglevel", "silly"] + return command + + def run_process_with_fallback(args, *, show_status_message, fallback=None, **kwargs): """Run subprocess and retry using fallback command if initial command fails. @@ -306,7 +326,7 @@ def run_process_with_fallback(args, *, show_status_message, fallback=None, **kwa fallback: The fallback command to run. kwargs: Kwargs to pass to new_process function. """ - process = new_process(args, **kwargs) + process = new_process(get_command_with_loglevel(args), **kwargs) if fallback is None: # No fallback given, or this _is_ the fallback command. show_status(show_status_message, process)