reinforce check for bun install process in "pc init" ()

This commit is contained in:
Thomas Brandého 2023-05-04 19:01:14 +02:00 committed by GitHub
parent c344a5c0d7
commit 4f182b3170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View File

@ -71,7 +71,7 @@ API_URL = "http://localhost:8000"
# The default path where bun is installed.
BUN_PATH = "$HOME/.bun/bin/bun"
# Command to install bun.
INSTALL_BUN = "curl -fsSL https://bun.sh/install | bash -s -- bun-v0.5.9"
INSTALL_BUN = f"curl -fsSL https://bun.sh/install | bash -s -- bun-v{MAX_BUN_VERSION}"
# Default host in dev mode.
BACKEND_HOST = "0.0.0.0"
# The default timeout when launching the gunicorn server.

View File

@ -13,6 +13,7 @@ from types import ModuleType
from typing import Optional
import typer
from packaging import version
from redis import Redis
from pynecone import constants
@ -42,7 +43,7 @@ def check_node_version(min_version):
return False
def get_bun_version() -> Optional[str]:
def get_bun_version() -> Optional[version.Version]:
"""Get the version of bun.
Returns:
@ -53,7 +54,7 @@ def get_bun_version() -> Optional[str]:
result = subprocess.run(
["bun", "-v"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
return result.stdout.decode().strip()
return version.parse(result.stdout.decode().strip())
except Exception:
return None
@ -220,16 +221,16 @@ def install_bun():
Exit: If the bun version is not supported.
"""
bun_version = get_bun_version()
if bun_version is not None and bun_version in constants.INVALID_BUN_VERSIONS:
if bun_version is not None and (
bun_version < version.parse(constants.MIN_BUN_VERSION)
or bun_version > version.parse(constants.MAX_BUN_VERSION)
or str(bun_version) in constants.INVALID_BUN_VERSIONS
):
console.print(
f"""[red]Bun version {bun_version} is not supported by Pynecone. Please change your to bun version to be between {constants.MIN_BUN_VERSION} and {constants.MAX_BUN_VERSION}."""
)
console.print(
f"""[red]Upgrade by running the following command:[/red]
curl -fsSL https://bun.sh/install | bash -s -- bun-v{constants.MAX_BUN_VERSION}
"""
f"""[red]Upgrade by running the following command:[/red]\n\n{constants.INSTALL_BUN}"""
)
raise typer.Exit()