Skip to content

Commit

Permalink
fix stuff with bun_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Lendemor committed Jan 24, 2025
1 parent abc9038 commit 869d354
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 14 additions & 1 deletion reflex/utils/path_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path

from reflex import constants
from reflex.config import environment
from reflex.config import environment, get_config

# Shorthand for join.
join = os.linesep.join
Expand Down Expand Up @@ -187,6 +187,19 @@ def get_npm_path() -> Path | None:
return npm_path.absolute() if npm_path else None


def get_bun_path() -> Path | None:
"""Get bun binary path.
Returns:
The path to the bun binary file.
"""
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
return bun_path.absolute() if bun_path else None


def update_json_file(file_path: str | Path, update_dict: dict[str, int | str]):
"""Update the contents of a json file.
Expand Down
7 changes: 5 additions & 2 deletions reflex/utils/prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,13 @@ def get_bun_version() -> version.Version | None:
Returns:
The version of bun.
"""
bun_path = path_ops.get_bun_path()
if bun_path is None:
return None
try:
# Run the bun -v command and capture the output
result = processes.new_process([str(get_config().bun_path), "-v"], run=True)
return version.parse(result.stdout) # type: ignore
result = processes.new_process([str(bun_path), "-v"], run=True)
return version.parse(str(result.stdout))
except FileNotFoundError:
return None
except version.InvalidVersion as e:
Expand Down

0 comments on commit 869d354

Please sign in to comment.