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
This commit is contained in:
Elijah Ahianyo 2024-04-18 20:00:41 -07:00 committed by GitHub
parent c567334c92
commit 7b61e7e4bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 5 deletions

View File

@ -821,14 +821,16 @@ def install_frontend_packages(packages: set[str], config: Config):
Example: Example:
>>> install_frontend_packages(["react", "react-dom"], get_config()) >>> 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 = ( fallback_command = (
get_package_manager() get_install_package_manager()
if constants.IS_WINDOWS and constants.IS_WINDOWS_BUN_SUPPORTED_MACHINE if not constants.IS_WINDOWS
or constants.IS_WINDOWS
and constants.IS_WINDOWS_BUN_SUPPORTED_MACHINE
else None else None
) )
processes.run_process_with_fallback( processes.run_process_with_fallback(
[get_install_package_manager(), "install", "--loglevel", "silly"], [get_install_package_manager(), "install"], # type: ignore
fallback=fallback_command, fallback=fallback_command,
show_status_message="Installing base frontend packages", show_status_message="Installing base frontend packages",
cwd=constants.Dirs.WEB, cwd=constants.Dirs.WEB,

View File

@ -8,6 +8,7 @@ import os
import signal import signal
import subprocess import subprocess
from concurrent import futures from concurrent import futures
from pathlib import Path
from typing import Callable, Generator, List, Optional, Tuple, Union from typing import Callable, Generator, List, Optional, Tuple, Union
import psutil import psutil
@ -297,6 +298,25 @@ def atexit_handler():
console.log("Reflex app stopped.") 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 <level>, 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): def run_process_with_fallback(args, *, show_status_message, fallback=None, **kwargs):
"""Run subprocess and retry using fallback command if initial command fails. """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. fallback: The fallback command to run.
kwargs: Kwargs to pass to new_process function. 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: if fallback is None:
# No fallback given, or this _is_ the fallback command. # No fallback given, or this _is_ the fallback command.
show_status(show_status_message, process) show_status(show_status_message, process)