Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF-1202: Upgrade bun version if it differs from reflex set version #2206

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion reflex/utils/prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ def install_bun():
return

# Skip if bun is already installed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe update the comment to include the additional version check

if os.path.exists(get_config().bun_path):
if os.path.exists(get_config().bun_path) and get_bun_version() == version.parse(
constants.Bun.VERSION
):
console.debug("Skipping bun installation as it is already installed.")
return

Expand Down
26 changes: 26 additions & 0 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,32 @@ def test_bun_install_without_unzip(mocker):
prerequisites.install_bun()


@pytest.mark.parametrize("bun_version", [constants.Bun.VERSION, "1.0.0"])
def test_bun_install_version(mocker, bun_version):
"""Test that bun is downloaded when the host version(installed by reflex)
different from the current version set in reflex.

Args:
mocker: Pytest mocker object.
bun_version: the host bun version

"""
mocker.patch("reflex.utils.prerequisites.constants.IS_WINDOWS", False)
mocker.patch("os.path.exists", return_value=True)
mocker.patch(
"reflex.utils.prerequisites.get_bun_version",
return_value=version.parse(bun_version),
)
mocker.patch("reflex.utils.path_ops.which")
mock = mocker.patch("reflex.utils.prerequisites.download_and_run")

prerequisites.install_bun()
if bun_version == constants.Bun.VERSION:
mock.assert_not_called()
else:
mock.assert_called_once()


@pytest.mark.parametrize("is_windows", [True, False])
def test_create_reflex_dir(mocker, is_windows):
"""Test that a reflex directory is created on initializing frontend
Expand Down
Loading