Skip to content

Commit

Permalink
Add minimum version check (#30)
Browse files Browse the repository at this point in the history
- Fetch version from API and check against current version
- Display message and prevent CLI from working if version minimum is not
met

Resolve BE-1786
  • Loading branch information
nickpetrovic authored Sep 19, 2024
1 parent 7fdd668 commit 954dcb1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "beam-client"
version = "0.2.75"
version = "0.2.76"
description = ""
authors = ["beam.cloud <[email protected]>"]
packages = [
Expand All @@ -10,7 +10,7 @@ packages = [

[tool.poetry.dependencies]
python = "^3.8"
beta9 = "^0.1.78"
beta9 = "^0.1.79"
requests = "^2.31.0"
websockets = "^12.0"

Expand Down
16 changes: 15 additions & 1 deletion src/beam/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
import sys
from dataclasses import dataclass
from pathlib import Path

from beta9 import config
from beta9.cli.main import load_cli

from . import configure, example, login, logs, quickstart
from . import configure, example, login, logs, quickstart, utils


@dataclass
Expand All @@ -30,3 +31,16 @@ class SDKSettings(config.SDKSettings):
cli.register(logs)
cli.register(example)
cli.load_version("beam-client")


_cli = cli


def cli():
try:
utils.check_version()

if exit_code := _cli(standalone_mode=False):
sys.exit(exit_code)
except Exception:
raise
39 changes: 39 additions & 0 deletions src/beam/cli/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import sys
from importlib import metadata

import click
import requests
from packaging import version

BASE_API_URL = os.getenv("BASE_API_URL", "https://api.beam.cloud")


def check_version():
try:
response = requests.get(f"{BASE_API_URL}/v2/api/minimum-cli-version/", timeout=1)
response.raise_for_status()

data = response.json()
if "version" not in data:
return
except Exception:
return

minimum_version = version.parse(data["version"])
current_version = version.parse(metadata.version("beam-client"))

if current_version >= minimum_version:
return

click.echo(
(
f"{click.style('Update Required', fg='yellow', bold=True)}\n\n"
f"Your current version: {click.style(str(current_version), bold=True)}\n"
f"Minimum required version: {click.style(str(minimum_version), fg='yellow', bold=True)}\n"
"\nPlease upgrade to the latest version.\n"
f" {click.style('pip install --upgrade beam-client', bold=True)}\n"
)
)

sys.exit(1)

0 comments on commit 954dcb1

Please sign in to comment.