which always return Path object

This commit is contained in:
Lendemor 2025-01-24 20:46:40 +01:00
parent 869d3545e3
commit 57f2d1de56
3 changed files with 19 additions and 25 deletions

View File

@ -467,19 +467,19 @@ def output_system_info():
system = platform.system() system = platform.system()
fnm_info = f"[FNM {prerequisites.get_fnm_version()} (Expected: {constants.Fnm.VERSION}) (PATH: {constants.Fnm.EXE})]"
if system != "Windows" or ( if system != "Windows" or (
system == "Windows" and prerequisites.is_windows_bun_supported() system == "Windows" and prerequisites.is_windows_bun_supported()
): ):
dependencies.extend( dependencies.extend(
[ [
f"[FNM {prerequisites.get_fnm_version()} (Expected: {constants.Fnm.VERSION}) (PATH: {constants.Fnm.EXE})]", fnm_info,
f"[Bun {prerequisites.get_bun_version()} (Expected: {constants.Bun.VERSION}) (PATH: {config.bun_path})]", f"[Bun {prerequisites.get_bun_version()} (Expected: {constants.Bun.VERSION}) (PATH: {path_ops.get_bun_path()})]",
], ],
) )
else: else:
dependencies.append( dependencies.append(fnm_info)
f"[FNM {prerequisites.get_fnm_version()} (Expected: {constants.Fnm.VERSION}) (PATH: {constants.Fnm.EXE})]",
)
if system == "Linux": if system == "Linux":
import distro # type: ignore import distro # type: ignore

View File

@ -118,7 +118,7 @@ def ln(src: str | Path, dest: str | Path, overwrite: bool = False) -> bool:
return True return True
def which(program: str | Path) -> str | Path | None: def which(program: str | Path) -> Path | None:
"""Find the path to an executable. """Find the path to an executable.
Args: Args:
@ -127,7 +127,8 @@ def which(program: str | Path) -> str | Path | None:
Returns: Returns:
The path to the executable. 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: def use_system_node() -> bool:
@ -156,12 +157,12 @@ def get_node_bin_path() -> Path | None:
""" """
bin_path = Path(constants.Node.BIN_PATH) bin_path = Path(constants.Node.BIN_PATH)
if not bin_path.exists(): if not bin_path.exists():
str_path = which("node") path = which("node")
return Path(str_path).parent.resolve() if str_path else None return path.parent.absolute() if path else None
return bin_path.resolve() return bin_path.absolute()
def get_node_path() -> str | None: def get_node_path() -> Path | None:
"""Get the node binary path. """Get the node binary path.
Returns: Returns:
@ -169,9 +170,8 @@ def get_node_path() -> str | None:
""" """
node_path = Path(constants.Node.PATH) node_path = Path(constants.Node.PATH)
if use_system_node() or not node_path.exists(): if use_system_node() or not node_path.exists():
system_node_path = which("node") node_path = which("node")
return str(system_node_path) if system_node_path else None return node_path
return str(node_path)
def get_npm_path() -> Path | None: def get_npm_path() -> Path | None:
@ -182,8 +182,7 @@ def get_npm_path() -> Path | None:
""" """
npm_path = Path(constants.Node.NPM_PATH) npm_path = Path(constants.Node.NPM_PATH)
if use_system_node() or not npm_path.exists(): if use_system_node() or not npm_path.exists():
system_npm_path = which("npm") npm_path = which("npm")
npm_path = Path(system_npm_path) if system_npm_path else None
return npm_path.absolute() if npm_path else None 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 bun_path = get_config().bun_path
if use_system_bun() or not bun_path.exists(): if use_system_bun() or not bun_path.exists():
system_bun_path = which("bun") bun_path = which("bun")
bun_path = Path(system_bun_path) if system_bun_path else None
return bun_path.absolute() if bun_path else None return bun_path.absolute() if bun_path else None

View File

@ -1077,8 +1077,7 @@ def install_bun():
show_logs=console.is_debug(), show_logs=console.is_debug(),
) )
else: else:
unzip_path = path_ops.which("unzip") if path_ops.which("unzip") is None:
if unzip_path is None:
raise SystemPackageMissingError("unzip") raise SystemPackageMissingError("unzip")
# Run the bun install script. # Run the bun install script.
@ -1282,11 +1281,8 @@ def validate_bun():
Raises: Raises:
Exit: If custom specified bun does not exist or does not meet requirements. Exit: If custom specified bun does not exist or does not meet requirements.
""" """
# if a custom bun path is provided, make sure its valid bun_path = path_ops.get_bun_path()
# 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")
if bun_path != constants.Bun.DEFAULT_PATH: if bun_path != constants.Bun.DEFAULT_PATH:
console.info(f"Using custom Bun path: {bun_path}") console.info(f"Using custom Bun path: {bun_path}")
bun_version = get_bun_version() bun_version = get_bun_version()