From 0bc09dc961d985a0a962c10f368be937e0f99efa Mon Sep 17 00:00:00 2001 From: Nikhil Rao Date: Wed, 21 Dec 2022 20:05:02 -0800 Subject: [PATCH] Add template version check (#164) --- pynecone/.templates/web/pcversion.txt | 1 + pynecone/constants.py | 5 +++++ pynecone/pc.py | 7 +++++++ pynecone/utils.py | 13 +++++++++++++ pyproject.toml | 2 +- 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 pynecone/.templates/web/pcversion.txt diff --git a/pynecone/.templates/web/pcversion.txt b/pynecone/.templates/web/pcversion.txt new file mode 100644 index 000000000..a34eaa5d0 --- /dev/null +++ b/pynecone/.templates/web/pcversion.txt @@ -0,0 +1 @@ +0.1.11 \ No newline at end of file diff --git a/pynecone/constants.py b/pynecone/constants.py index 881b9c82b..22f17afd9 100644 --- a/pynecone/constants.py +++ b/pynecone/constants.py @@ -50,6 +50,11 @@ WEB_ASSETS_DIR = os.path.join(WEB_DIR, "public") NODE_MODULES = "node_modules" # The package lock file. PACKAGE_LOCK = "package-lock.json" +# The pcversion template file. +PCVERSION_TEMPLATE_FILE = os.path.join(WEB_TEMPLATE_DIR, "pcversion.txt") +# The pcversion app file. +PCVERSION_APP_FILE = os.path.join(WEB_DIR, "pcversion.txt") + # Commands to run the app. # The backend api url. diff --git a/pynecone/pc.py b/pynecone/pc.py index a503e920c..eee69ad44 100644 --- a/pynecone/pc.py +++ b/pynecone/pc.py @@ -70,6 +70,13 @@ def run( ) raise typer.Exit() + # Check that the template is up to date. + if not utils.is_latest_template(): + utils.console.print( + "[red]The base app template has updated. Run [bold]pc init[/bold] again." + ) + raise typer.Exit() + # Get the app module. utils.console.rule("[bold]Starting Pynecone App") app = utils.get_app() diff --git a/pynecone/utils.py b/pynecone/utils.py index 34e7dc04c..591ff92be 100644 --- a/pynecone/utils.py +++ b/pynecone/utils.py @@ -437,6 +437,19 @@ def is_initialized() -> bool: return os.path.exists(constants.CONFIG_FILE) and os.path.exists(constants.WEB_DIR) +def is_latest_template() -> bool: + """Whether the app is using the latest template. + + Returns: + Whether the app is using the latest template. + """ + template_version = open(constants.PCVERSION_TEMPLATE_FILE).read() + if not os.path.exists(constants.PCVERSION_APP_FILE): + return False + app_version = open(constants.PCVERSION_APP_FILE).read() + return app_version >= template_version + + def export_app(app: App, zip: bool = False): """Zip up the app for deployment. diff --git a/pyproject.toml b/pyproject.toml index 5c9821b3e..9cc34af22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pynecone-io" -version = "0.1.10" +version = "0.1.11" description = "The easiest way to build web apps." license = "Apache-2.0" authors = [