From 7d4609ba60b59cd0d24fd56d10e83fa849fe4bcb Mon Sep 17 00:00:00 2001 From: Elijah Ahianyo Date: Wed, 15 May 2024 01:47:08 +0000 Subject: [PATCH] [REF-2814]Throw Warning for Projects Created in OneDrive on Windows (#3304) * Throw Warning for Projects Created in OneDrive on Windows * precommit * remove dead code * REFLEX_USE_NPM escape hatch to opt out of bun In some unsupported environments, we need to just not use bun. Further investigation needed. --------- Co-authored-by: Masen Furer --- reflex/utils/prerequisites.py | 46 +++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index cb83de76c..df282e91e 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -181,7 +181,12 @@ def get_install_package_manager() -> str | None: Returns: The path to the package manager. """ - if constants.IS_WINDOWS and not is_windows_bun_supported(): + if ( + constants.IS_WINDOWS + and not is_windows_bun_supported() + or windows_check_onedrive_in_path() + or windows_npm_escape_hatch() + ): return get_package_manager() return get_config().bun_path @@ -199,6 +204,24 @@ def get_package_manager() -> str | None: return npm_path +def windows_check_onedrive_in_path() -> bool: + """For windows, check if oneDrive is present in the project dir path. + + Returns: + If oneDrive is in the path of the project directory. + """ + return "onedrive" in str(Path.cwd()).lower() + + +def windows_npm_escape_hatch() -> bool: + """For windows, if the user sets REFLEX_USE_NPM, use npm instead of bun. + + Returns: + If the user has set REFLEX_USE_NPM. + """ + return os.environ.get("REFLEX_USE_NPM", "").lower() in ["true", "1", "yes"] + + def get_app(reload: bool = False) -> ModuleType: """Get the app module based on the default config. @@ -737,10 +760,17 @@ def install_bun(): Raises: FileNotFoundError: If required packages are not found. """ - if constants.IS_WINDOWS and not is_windows_bun_supported(): - console.warn( - "Bun for Windows is currently only available for x86 64-bit Windows. Installation will fall back on npm." - ) + win_supported = is_windows_bun_supported() + one_drive_in_path = windows_check_onedrive_in_path() + if constants.IS_WINDOWS and not win_supported or one_drive_in_path: + if not win_supported: + console.warn( + "Bun for Windows is currently only available for x86 64-bit Windows. Installation will fall back on npm." + ) + if one_drive_in_path: + console.warn( + "Creating project directories in OneDrive is not recommended for bun usage on windows. This will fallback to npm." + ) # Skip if bun is already installed. if os.path.exists(get_config().bun_path) and get_bun_version() == version.parse( @@ -843,6 +873,7 @@ def install_frontend_packages(packages: set[str], config: Config): if not constants.IS_WINDOWS or constants.IS_WINDOWS and is_windows_bun_supported() + and not windows_check_onedrive_in_path() else None ) processes.run_process_with_fallback( @@ -929,6 +960,11 @@ def needs_reinit(frontend: bool = True) -> bool: console.warn( f"""On Python < 3.12, `uvicorn==0.20.0` is recommended for improved hot reload times. Found {uvi_ver} instead.""" ) + + if windows_check_onedrive_in_path(): + console.warn( + "Creating project directories in OneDrive may lead to performance issues. For optimal performance, It is recommended to avoid using OneDrive for your reflex app." + ) # No need to reinitialize if the app is already initialized. return False