From 9c5078595c14125c9c1a17074c7fcfbae8c78804 Mon Sep 17 00:00:00 2001 From: ElijahAhianyo Date: Tue, 14 May 2024 13:38:58 +0000 Subject: [PATCH] Throw Warning for Projects Created in OneDrive on Windows --- reflex/utils/prerequisites.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index de4741c1e..7e5f31891 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -181,7 +181,7 @@ 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(): return get_package_manager() return get_config().bun_path @@ -199,6 +199,14 @@ def get_package_manager() -> str | None: return npm_path +def windows_check_onedrive_in_path(): + """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 get_app(reload: bool = False) -> ModuleType: """Get the app module based on the default config. @@ -744,10 +752,15 @@ 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." - ) + if constants.IS_WINDOWS and not (win_supported := is_windows_bun_supported()) or (one_drive_in_path := windows_check_onedrive_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( @@ -850,6 +863,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( @@ -939,6 +953,12 @@ 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." + ) + # print(f"path: {Path.cwd()}") # No need to reinitialize if the app is already initialized. return False