Warning if newer reflex/reflex-hosting-cli available (#2271)

* Check to see if there are new reflex version avaliable if so throw a warning

* precommit

* request -> httpx

* Fix pr comments

* Forgot import

* Generalize check_latest_package_version

---------

Co-authored-by: Alek Petuskey <alekpetuskey@aleks-mbp.lan>
Co-authored-by: Alek Petuskey <alekpetuskey@Aleks-MBP.attlocal.net>
This commit is contained in:
Alek Petuskey 2023-12-08 21:21:12 -08:00 committed by GitHub
parent 96f68cb94d
commit 421be5748b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 0 deletions

View File

@ -15,6 +15,7 @@ from .base import (
Next,
Ping,
Reflex,
ReflexHostingCLI,
Templates,
)
from .compiler import (

View File

@ -72,6 +72,13 @@ class Reflex(SimpleNamespace):
)
class ReflexHostingCLI(SimpleNamespace):
"""Base constants concerning Reflex Hosting CLI."""
# The name of the Reflex Hosting CLI package.
MODULE_NAME = "reflex-hosting-cli"
class Templates(SimpleNamespace):
"""Constants related to Templates."""

View File

@ -78,6 +78,8 @@ def _init(
app_name = prerequisites.get_default_app_name() if name is None else name
console.rule(f"[bold]Initializing {app_name}")
prerequisites.check_latest_package_version(constants.Reflex.MODULE_NAME)
# Set up the web project.
prerequisites.initialize_frontend_dependencies()
@ -171,6 +173,8 @@ def _run(
console.rule("[bold]Starting Reflex App")
prerequisites.check_latest_package_version(constants.Reflex.MODULE_NAME)
if frontend:
prerequisites.update_next_config()
# Get the app module.
@ -489,6 +493,7 @@ def deploy(
# Check if we are set up.
prerequisites.check_initialized(frontend=True)
prerequisites.check_latest_package_version(constants.ReflexHostingCLI.MODULE_NAME)
hosting_cli.deploy(
app_name=app_name,

View File

@ -18,6 +18,7 @@ from pathlib import Path
from types import ModuleType
import httpx
import pkg_resources
import typer
from alembic.util.exc import CommandError
from packaging import version
@ -29,6 +30,26 @@ from reflex.config import get_config
from reflex.utils import console, path_ops, processes
def check_latest_package_version(package_name: str):
"""Check if the latest version of the package is installed.
Args:
package_name: The name of the package.
"""
try:
# Get the latest version from PyPI
current_version = pkg_resources.get_distribution(package_name).version
url = f"https://pypi.org/pypi/{package_name}/json"
response = httpx.get(url)
latest_version = response.json()["info"]["version"]
if version.parse(current_version) < version.parse(latest_version):
console.warn(
f"Your version ({current_version}) of {package_name} is out of date. Upgrade to {latest_version} with 'pip install {package_name} --upgrade'"
)
except Exception:
pass
def check_node_version() -> bool:
"""Check the version of Node.js.