From 0b73711f806f227759d84229720730379d04cade Mon Sep 17 00:00:00 2001 From: Alek Petuskey Date: Wed, 21 Dec 2022 16:21:00 -0800 Subject: [PATCH 1/6] Check if the min node version is high enough raise and error if not. --- pynecone/constants.py | 2 ++ pynecone/pc.py | 7 +++++++ pynecone/utils.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/pynecone/constants.py b/pynecone/constants.py index 40051cad37..e21b6bbf4b 100644 --- a/pynecone/constants.py +++ b/pynecone/constants.py @@ -12,6 +12,8 @@ PACKAGE_NAME = "pynecone-io" # The current version of Pynecone. VERSION = pkg_resources.get_distribution(PACKAGE_NAME).version +# Minimum version of Node.js required to run Pynecone. +MIN_NODE_VERSION = "12.22.0" # Files and directories used to init a new project. # The root directory of the pynecone library. diff --git a/pynecone/pc.py b/pynecone/pc.py index a503e920cc..df5ea2fed4 100644 --- a/pynecone/pc.py +++ b/pynecone/pc.py @@ -26,6 +26,13 @@ def init(): """ app_name = utils.get_default_app_name() + # Check that the node version is valid. + if not (utils.check_node_version(constants.MIN_NODE_VERSION)): + utils.console.print( + f"[red]Node.js version {constants.MIN_NODE_VERSION} or higher is required to run Pynecone." + ) + raise typer.Exit() + # Make sure they don't name the app "pynecone". if app_name == constants.MODULE_NAME: utils.console.print( diff --git a/pynecone/utils.py b/pynecone/utils.py index 7fb2af001a..96702924cc 100644 --- a/pynecone/utils.py +++ b/pynecone/utils.py @@ -343,6 +343,49 @@ def create_config(app_name: str): f.write(templates.PCCONFIG.format(app_name=app_name)) +def check_node_version(min_version): + """Check the version of Node.js. + + Args: + min_version: The minimum version of Node.js required. + + Raises: + RuntimeError: If the version of Node.js is too low. + + Returns: + Whether the version of Node.js is high enough. + """ + try: + # Run the node -v command and capture the output + result = subprocess.run( + ["node", "-v"], stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + # The output will be in the form "vX.Y.Z", so we can split it on the "v" character and take the second part + version = result.stdout.decode().strip().split("v")[1] + # Split the version string on the "." character and convert each part to an integer + version_parts = [int(x) for x in version.split(".")] + # Split the minimum version string on the "." character and convert each part to an integer + min_version_parts = [int(x) for x in min_version.split(".")] + # Compare the version parts to the minimum version parts + if version_parts[0] < min_version_parts[0] or ( + version_parts[0] == min_version_parts[0] + and ( + version_parts[1] < min_version_parts[1] + or ( + version_parts[1] == min_version_parts[1] + and version_parts[2] < min_version_parts[2] + ) + ) + ): + return False + else: + return True + except Exception as e: + # If an error occurs, print the error message and return False + print("Error checking node version: " + str(e)) + return False + + def initialize_app_directory(app_name: str): """Initialize the app directory on pc init. From 0f8957d29a6156784b2be484f4c4bc8c5a98aa7d Mon Sep 17 00:00:00 2001 From: Alek Petuskey Date: Wed, 21 Dec 2022 16:24:02 -0800 Subject: [PATCH 2/6] Added better error docs --- pynecone/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pynecone/utils.py b/pynecone/utils.py index 96702924cc..e6a587c5d1 100644 --- a/pynecone/utils.py +++ b/pynecone/utils.py @@ -350,7 +350,7 @@ def check_node_version(min_version): min_version: The minimum version of Node.js required. Raises: - RuntimeError: If the version of Node.js is too low. + RuntimeError: If there was a problem running the node -v command. Returns: Whether the version of Node.js is high enough. From 22c2906466b91bbdbc20ec98b9eccef1a49a745b Mon Sep 17 00:00:00 2001 From: Alek Petuskey Date: Wed, 21 Dec 2022 17:13:01 -0800 Subject: [PATCH 3/6] Changed where node version is check. --- pynecone/pc.py | 7 ---- pynecone/utils.py | 91 +++++++++++++++++++++++++---------------------- 2 files changed, 48 insertions(+), 50 deletions(-) diff --git a/pynecone/pc.py b/pynecone/pc.py index df5ea2fed4..a503e920cc 100644 --- a/pynecone/pc.py +++ b/pynecone/pc.py @@ -26,13 +26,6 @@ def init(): """ app_name = utils.get_default_app_name() - # Check that the node version is valid. - if not (utils.check_node_version(constants.MIN_NODE_VERSION)): - utils.console.print( - f"[red]Node.js version {constants.MIN_NODE_VERSION} or higher is required to run Pynecone." - ) - raise typer.Exit() - # Make sure they don't name the app "pynecone". if app_name == constants.MODULE_NAME: utils.console.print( diff --git a/pynecone/utils.py b/pynecone/utils.py index e6a587c5d1..66f74ac55d 100644 --- a/pynecone/utils.py +++ b/pynecone/utils.py @@ -28,6 +28,7 @@ Type, Union, ) +import typer import plotly.graph_objects as go from plotly.io import to_json @@ -298,6 +299,44 @@ def get_config() -> Config: return Config(app_name="") +def check_node_version(min_version): + """Check the version of Node.js. + + Args: + min_version: The minimum version of Node.js required. + + Returns: + Whether the version of Node.js is high enough. + """ + try: + # Run the node -v command and capture the output + result = subprocess.run( + ["node", "-v"], stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + # The output will be in the form "vX.Y.Z", so we can split it on the "v" character and take the second part + version = result.stdout.decode().strip().split("v")[1] + # Split the version string on the "." character and convert each part to an integer + version_parts = [int(x) for x in version.split(".")] + # Split the minimum version string on the "." character and convert each part to an integer + min_version_parts = [int(x) for x in min_version.split(".")] + # Compare the version parts to the minimum version parts + if version_parts[0] < min_version_parts[0] or ( + version_parts[0] == min_version_parts[0] + and ( + version_parts[1] < min_version_parts[1] + or ( + version_parts[1] == min_version_parts[1] + and version_parts[2] < min_version_parts[2] + ) + ) + ): + return False + else: + return True + except Exception as e: + return False + + def get_package_manager() -> str: """Get the package manager executable. @@ -306,7 +345,16 @@ def get_package_manager() -> str: Raises: FileNotFoundError: If bun or npm is not installed. + Exit: If the app directory is invalid. + """ + # Check that the node version is valid. + if not (check_node_version(constants.MIN_NODE_VERSION)): + console.print( + f"[red]Node.js version {constants.MIN_NODE_VERSION} or higher is required to run Pynecone." + ) + raise typer.Exit() + # On Windows, we use npm instead of bun. if platform.system() == "Windows": npm_path = which("npm") @@ -343,49 +391,6 @@ def create_config(app_name: str): f.write(templates.PCCONFIG.format(app_name=app_name)) -def check_node_version(min_version): - """Check the version of Node.js. - - Args: - min_version: The minimum version of Node.js required. - - Raises: - RuntimeError: If there was a problem running the node -v command. - - Returns: - Whether the version of Node.js is high enough. - """ - try: - # Run the node -v command and capture the output - result = subprocess.run( - ["node", "-v"], stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - # The output will be in the form "vX.Y.Z", so we can split it on the "v" character and take the second part - version = result.stdout.decode().strip().split("v")[1] - # Split the version string on the "." character and convert each part to an integer - version_parts = [int(x) for x in version.split(".")] - # Split the minimum version string on the "." character and convert each part to an integer - min_version_parts = [int(x) for x in min_version.split(".")] - # Compare the version parts to the minimum version parts - if version_parts[0] < min_version_parts[0] or ( - version_parts[0] == min_version_parts[0] - and ( - version_parts[1] < min_version_parts[1] - or ( - version_parts[1] == min_version_parts[1] - and version_parts[2] < min_version_parts[2] - ) - ) - ): - return False - else: - return True - except Exception as e: - # If an error occurs, print the error message and return False - print("Error checking node version: " + str(e)) - return False - - def initialize_app_directory(app_name: str): """Initialize the app directory on pc init. From 77ab8c330a0602e0dbee1910d406706729faf9ec Mon Sep 17 00:00:00 2001 From: Alek Petuskey Date: Wed, 21 Dec 2022 17:13:40 -0800 Subject: [PATCH 4/6] Changed where node version is check. --- pynecone/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pynecone/utils.py b/pynecone/utils.py index 66f74ac55d..0e1790b9e4 100644 --- a/pynecone/utils.py +++ b/pynecone/utils.py @@ -354,7 +354,7 @@ def get_package_manager() -> str: f"[red]Node.js version {constants.MIN_NODE_VERSION} or higher is required to run Pynecone." ) raise typer.Exit() - + # On Windows, we use npm instead of bun. if platform.system() == "Windows": npm_path = which("npm") From abb4f7d0b50d4233e9e93dd23f45db7d96deeb57 Mon Sep 17 00:00:00 2001 From: Alek Petuskey Date: Wed, 21 Dec 2022 17:40:53 -0800 Subject: [PATCH 5/6] Add striped to stripe in this commit asweel --- pynecone/components/feedback/progress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pynecone/components/feedback/progress.py b/pynecone/components/feedback/progress.py index bfac78f447..235fb6c8f7 100644 --- a/pynecone/components/feedback/progress.py +++ b/pynecone/components/feedback/progress.py @@ -10,7 +10,7 @@ class Progress(ChakraComponent): tag = "Progress" # If true, the progress bar will show stripe - has_striped: Var[bool] + has_stripe: Var[bool] # If true, and hasStripe is true, the stripes will be animated is_animated: Var[bool] From 56f3d1d197e412d2e9a290c7a05a77fa122bbf95 Mon Sep 17 00:00:00 2001 From: Alek Petuskey Date: Wed, 21 Dec 2022 18:15:54 -0800 Subject: [PATCH 6/6] Fixed pr comments. --- pynecone/utils.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/pynecone/utils.py b/pynecone/utils.py index 0e1790b9e4..5b1dfe4c26 100644 --- a/pynecone/utils.py +++ b/pynecone/utils.py @@ -315,24 +315,8 @@ def check_node_version(min_version): ) # The output will be in the form "vX.Y.Z", so we can split it on the "v" character and take the second part version = result.stdout.decode().strip().split("v")[1] - # Split the version string on the "." character and convert each part to an integer - version_parts = [int(x) for x in version.split(".")] - # Split the minimum version string on the "." character and convert each part to an integer - min_version_parts = [int(x) for x in min_version.split(".")] - # Compare the version parts to the minimum version parts - if version_parts[0] < min_version_parts[0] or ( - version_parts[0] == min_version_parts[0] - and ( - version_parts[1] < min_version_parts[1] - or ( - version_parts[1] == min_version_parts[1] - and version_parts[2] < min_version_parts[2] - ) - ) - ): - return False - else: - return True + # Compare the version numbers + return version.split(".") >= min_version.split(".") except Exception as e: return False @@ -349,7 +333,7 @@ def get_package_manager() -> str: """ # Check that the node version is valid. - if not (check_node_version(constants.MIN_NODE_VERSION)): + if not check_node_version(constants.MIN_NODE_VERSION): console.print( f"[red]Node.js version {constants.MIN_NODE_VERSION} or higher is required to run Pynecone." )