From 6c4a4a9e79415752077a73c2f74d9416a1f35a6c Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Thu, 9 Jan 2025 11:58:08 -0800 Subject: [PATCH] run bun from cached path --- reflex/utils/exec.py | 28 +++++++--------------------- reflex/utils/prerequisites.py | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/reflex/utils/exec.py b/reflex/utils/exec.py index 72e615ce5..565f099bd 100644 --- a/reflex/utils/exec.py +++ b/reflex/utils/exec.py @@ -18,7 +18,7 @@ from reflex import constants from reflex.config import environment, get_config from reflex.constants.base import LogLevel from reflex.utils import console, path_ops -from reflex.utils.prerequisites import get_web_dir +from reflex.utils.prerequisites import get_package_list, get_web_dir # For uvicorn windows bug fix (#2335) frontend_process = None @@ -85,14 +85,7 @@ def run_process_and_launch_url(run_command: list[str], backend_present=True): console.print( f"DETECT_PACKAGE_CHANGE init {last_hash}, {json.dumps(json.loads(json_file_path.read_text()))}" ) - last_packages = ( - processes.new_process( - ["bun", "pm", "ls"], - cwd=get_web_dir(), - ) - .stdout.read() - .strip() - ) + last_packages = get_package_list() console.print( f"DETECT_PACKAGE_CHANGE init {last_packages}", ) @@ -145,20 +138,13 @@ def run_process_and_launch_url(run_command: list[str], backend_present=True): f"DETECT_PACKAGE_CHANGE hit {last_hash} != {new_hash} (new), {new_content}" ) last_hash = new_hash - new_packages = ( - processes.new_process( - ["bun", "pm", "ls"], - cwd=get_web_dir(), - ) - .stdout.read() - .strip() - ) - console.print( - f"DETECT_PACKAGE_CHANGE init {new_packages}", - ) + new_packages = get_package_list() if new_packages != last_packages: - last_packages = new_packages console.print("Reloading app due to new content...") + console.print( + f"DETECT_PACKAGE_CHANGE init {new_packages}", + ) + last_packages = new_packages kill(process.pid) process = None break # for line in process.stdout diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index d838c0eea..9ed2c02e8 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -267,6 +267,30 @@ def windows_npm_escape_hatch() -> bool: return environment.REFLEX_USE_NPM.get() +def get_package_list() -> str: + """Get the list of installed packages in the current environment. + + Returns: + The list of user and framework installed packages. + """ + package_manager = get_package_manager() + install_package_manager = get_install_package_manager() + if package_manager == install_package_manager: + # npm + cmd = [install_package_manager, "list"] + else: + # bun + cmd = [install_package_manager, "pm", "ls"] + return ( + processes.new_process( + cmd, + cwd=get_web_dir(), + ) + .stdout.read() + .strip() + ) + + def get_app(reload: bool = False) -> ModuleType: """Get the app module based on the default config.