[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 <m_github@0x26.net>
This commit is contained in:
Elijah Ahianyo 2024-05-15 01:47:08 +00:00 committed by GitHub
parent 1e9ccecea0
commit ea5a3d44e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -181,7 +181,12 @@ def get_install_package_manager() -> str | None:
Returns: Returns:
The path to the package manager. 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_package_manager()
return get_config().bun_path return get_config().bun_path
@ -199,6 +204,24 @@ def get_package_manager() -> str | None:
return npm_path 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: def get_app(reload: bool = False) -> ModuleType:
"""Get the app module based on the default config. """Get the app module based on the default config.
@ -744,10 +767,17 @@ def install_bun():
Raises: Raises:
FileNotFoundError: If required packages are not found. FileNotFoundError: If required packages are not found.
""" """
if constants.IS_WINDOWS and not is_windows_bun_supported(): win_supported = is_windows_bun_supported()
console.warn( one_drive_in_path = windows_check_onedrive_in_path()
"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 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. # Skip if bun is already installed.
if os.path.exists(get_config().bun_path) and get_bun_version() == version.parse( if os.path.exists(get_config().bun_path) and get_bun_version() == version.parse(
@ -850,6 +880,7 @@ def install_frontend_packages(packages: set[str], config: Config):
if not constants.IS_WINDOWS if not constants.IS_WINDOWS
or constants.IS_WINDOWS or constants.IS_WINDOWS
and is_windows_bun_supported() and is_windows_bun_supported()
and not windows_check_onedrive_in_path()
else None else None
) )
processes.run_process_with_fallback( processes.run_process_with_fallback(
@ -939,6 +970,11 @@ def needs_reinit(frontend: bool = True) -> bool:
console.warn( console.warn(
f"""On Python < 3.12, `uvicorn==0.20.0` is recommended for improved hot reload times. Found {uvi_ver} instead.""" 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. # No need to reinitialize if the app is already initialized.
return False return False