From 57f2d1de56baa89a3f93afb1a839d5eaf06eaa96 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Fri, 24 Jan 2025 20:46:40 +0100 Subject: [PATCH] which always return Path object --- reflex/utils/exec.py | 10 +++++----- reflex/utils/path_ops.py | 24 +++++++++++------------- reflex/utils/prerequisites.py | 10 +++------- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/reflex/utils/exec.py b/reflex/utils/exec.py index 9a5b70112..a8b86d30a 100644 --- a/reflex/utils/exec.py +++ b/reflex/utils/exec.py @@ -467,19 +467,19 @@ def output_system_info(): system = platform.system() + fnm_info = f"[FNM {prerequisites.get_fnm_version()} (Expected: {constants.Fnm.VERSION}) (PATH: {constants.Fnm.EXE})]" + if system != "Windows" or ( system == "Windows" and prerequisites.is_windows_bun_supported() ): dependencies.extend( [ - f"[FNM {prerequisites.get_fnm_version()} (Expected: {constants.Fnm.VERSION}) (PATH: {constants.Fnm.EXE})]", - f"[Bun {prerequisites.get_bun_version()} (Expected: {constants.Bun.VERSION}) (PATH: {config.bun_path})]", + fnm_info, + f"[Bun {prerequisites.get_bun_version()} (Expected: {constants.Bun.VERSION}) (PATH: {path_ops.get_bun_path()})]", ], ) else: - dependencies.append( - f"[FNM {prerequisites.get_fnm_version()} (Expected: {constants.Fnm.VERSION}) (PATH: {constants.Fnm.EXE})]", - ) + dependencies.append(fnm_info) if system == "Linux": import distro # type: ignore diff --git a/reflex/utils/path_ops.py b/reflex/utils/path_ops.py index 48ccd545a..b6bb9aade 100644 --- a/reflex/utils/path_ops.py +++ b/reflex/utils/path_ops.py @@ -118,7 +118,7 @@ def ln(src: str | Path, dest: str | Path, overwrite: bool = False) -> bool: return True -def which(program: str | Path) -> str | Path | None: +def which(program: str | Path) -> Path | None: """Find the path to an executable. Args: @@ -127,7 +127,8 @@ def which(program: str | Path) -> str | Path | None: Returns: The path to the executable. """ - return shutil.which(str(program)) + which_result = shutil.which(program) + return Path(which_result) if which_result else None def use_system_node() -> bool: @@ -156,12 +157,12 @@ def get_node_bin_path() -> Path | None: """ bin_path = Path(constants.Node.BIN_PATH) if not bin_path.exists(): - str_path = which("node") - return Path(str_path).parent.resolve() if str_path else None - return bin_path.resolve() + path = which("node") + return path.parent.absolute() if path else None + return bin_path.absolute() -def get_node_path() -> str | None: +def get_node_path() -> Path | None: """Get the node binary path. Returns: @@ -169,9 +170,8 @@ def get_node_path() -> str | None: """ node_path = Path(constants.Node.PATH) if use_system_node() or not node_path.exists(): - system_node_path = which("node") - return str(system_node_path) if system_node_path else None - return str(node_path) + node_path = which("node") + return node_path def get_npm_path() -> Path | None: @@ -182,8 +182,7 @@ def get_npm_path() -> Path | None: """ npm_path = Path(constants.Node.NPM_PATH) if use_system_node() or not npm_path.exists(): - system_npm_path = which("npm") - npm_path = Path(system_npm_path) if system_npm_path else None + npm_path = which("npm") return npm_path.absolute() if npm_path else None @@ -195,8 +194,7 @@ def get_bun_path() -> Path | None: """ bun_path = get_config().bun_path if use_system_bun() or not bun_path.exists(): - system_bun_path = which("bun") - bun_path = Path(system_bun_path) if system_bun_path else None + bun_path = which("bun") return bun_path.absolute() if bun_path else None diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index f829d6c4a..6a623e3eb 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -1077,8 +1077,7 @@ def install_bun(): show_logs=console.is_debug(), ) else: - unzip_path = path_ops.which("unzip") - if unzip_path is None: + if path_ops.which("unzip") is None: raise SystemPackageMissingError("unzip") # Run the bun install script. @@ -1282,11 +1281,8 @@ def validate_bun(): Raises: Exit: If custom specified bun does not exist or does not meet requirements. """ - # if a custom bun path is provided, make sure its valid - # This is specific to non-FHS OS - bun_path = get_config().bun_path - if path_ops.use_system_bun(): - bun_path = path_ops.which("bun") + bun_path = path_ops.get_bun_path() + if bun_path != constants.Bun.DEFAULT_PATH: console.info(f"Using custom Bun path: {bun_path}") bun_version = get_bun_version()