Selaa lähdekoodia

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

Thomas Brandého 2 vuotta sitten
vanhempi
säilyke
4f182b3170
2 muutettua tiedostoa jossa 10 lisäystä ja 9 poistoa
  1. 1 1
      pynecone/constants.py
  2. 9 8
      pynecone/utils/prerequisites.py

+ 1 - 1
pynecone/constants.py

@@ -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.

+ 9 - 8
pynecone/utils/prerequisites.py

@@ -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()