Skip to content

Commit bfed6b7

Browse files
authored
be less whiny about bun version and suggest alternatives (#5106)
* be less whiny about bun version and suggest alternatives * fix tests * only validate on version mismatch * dang it darglint
1 parent 074cddb commit bfed6b7

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

reflex/utils/prerequisites.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,16 @@ def get_node_version() -> version.Version | None:
192192
return None
193193

194194

195-
def get_bun_version() -> version.Version | None:
195+
def get_bun_version(bun_path: Path | None = None) -> version.Version | None:
196196
"""Get the version of bun.
197197
198+
Args:
199+
bun_path: The path to the bun executable.
200+
198201
Returns:
199202
The version of bun.
200203
"""
201-
bun_path = path_ops.get_bun_path()
204+
bun_path = bun_path or path_ops.get_bun_path()
202205
if bun_path is None:
203206
return None
204207
try:
@@ -1153,13 +1156,21 @@ def install_bun():
11531156
"Creating project directories in OneDrive is not recommended for bun usage on windows. This will fallback to npm."
11541157
)
11551158

1159+
bun_path = path_ops.get_bun_path()
1160+
11561161
# Skip if bun is already installed.
1157-
if (current_version := get_bun_version()) and current_version >= version.parse(
1158-
constants.Bun.MIN_VERSION
1162+
if (
1163+
bun_path
1164+
and (current_version := get_bun_version(bun_path=bun_path))
1165+
and current_version >= version.parse(constants.Bun.MIN_VERSION)
11591166
):
11601167
console.debug("Skipping bun installation as it is already installed.")
11611168
return
11621169

1170+
if bun_path and path_ops.use_system_bun():
1171+
validate_bun(bun_path=bun_path)
1172+
return
1173+
11631174
# if unzip is installed
11641175
if constants.IS_WINDOWS:
11651176
processes.new_process(
@@ -1394,13 +1405,16 @@ def is_latest_template() -> bool:
13941405
return app_version == constants.Reflex.VERSION
13951406

13961407

1397-
def validate_bun():
1408+
def validate_bun(bun_path: Path | None = None):
13981409
"""Validate bun if a custom bun path is specified to ensure the bun version meets requirements.
13991410
1411+
Args:
1412+
bun_path: The path to the bun executable. If None, the default bun path is used.
1413+
14001414
Raises:
14011415
Exit: If custom specified bun does not exist or does not meet requirements.
14021416
"""
1403-
bun_path = path_ops.get_bun_path()
1417+
bun_path = bun_path or path_ops.get_bun_path()
14041418

14051419
if bun_path is None:
14061420
return
@@ -1414,14 +1428,12 @@ def validate_bun():
14141428
)
14151429
raise typer.Exit(1)
14161430
elif bun_version < version.parse(constants.Bun.MIN_VERSION):
1417-
console.error(
1431+
console.warn(
14181432
f"Reflex requires bun version {constants.Bun.MIN_VERSION} or higher to run, but the detected version is "
14191433
f"{bun_version}. If you have specified a custom bun path in your config, make sure to provide one "
1420-
f"that satisfies the minimum version requirement."
1434+
f"that satisfies the minimum version requirement. You can upgrade bun by running [bold]bun upgrade[/bold]."
14211435
)
14221436

1423-
raise typer.Exit(1)
1424-
14251437

14261438
def validate_frontend_dependencies(init: bool = True):
14271439
"""Validate frontend dependencies to ensure they meet requirements.
@@ -1438,15 +1450,12 @@ def validate_frontend_dependencies(init: bool = True):
14381450
except FileNotFoundError as e:
14391451
raise typer.Exit(1) from e
14401452

1441-
if prefer_npm_over_bun():
1442-
if not check_node_version():
1443-
node_version = get_node_version()
1444-
console.error(
1445-
f"Reflex requires node version {constants.Node.MIN_VERSION} or higher to run, but the detected version is {node_version}",
1446-
)
1447-
raise typer.Exit(1)
1448-
else:
1449-
validate_bun()
1453+
if prefer_npm_over_bun() and not check_node_version():
1454+
node_version = get_node_version()
1455+
console.error(
1456+
f"Reflex requires node version {constants.Node.MIN_VERSION} or higher to run, but the detected version is {node_version}",
1457+
)
1458+
raise typer.Exit(1)
14501459

14511460

14521461
def ensure_reflex_installation_id() -> int | None:

tests/units/utils/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ def test_validate_bun_path_incompatible_version(mocker):
226226
return_value=version.parse("0.6.5"),
227227
)
228228

229-
with pytest.raises(typer.Exit):
230-
prerequisites.validate_bun()
229+
# This will just warn the user, not raise an error
230+
prerequisites.validate_bun()
231231

232232

233233
def test_remove_existing_bun_installation(mocker):

0 commit comments

Comments
 (0)