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

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. # The default path where bun is installed.
BUN_PATH = "$HOME/.bun/bin/bun" BUN_PATH = "$HOME/.bun/bin/bun"
# Command to install 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. # Default host in dev mode.
BACKEND_HOST = "0.0.0.0" BACKEND_HOST = "0.0.0.0"
# The default timeout when launching the gunicorn server. # The default timeout when launching the gunicorn server.

View File

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