diff --git a/poetry.lock b/poetry.lock index fe7e159..1f4f3af 100644 --- a/poetry.lock +++ b/poetry.lock @@ -55,13 +55,13 @@ tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"] [[package]] name = "beta9" -version = "0.1.77" +version = "0.1.79" description = "" optional = false python-versions = "<4.0,>=3.8" files = [ - {file = "beta9-0.1.77-py3-none-any.whl", hash = "sha256:d556007c43977f56c2da073ee945fa32b4b163fe7df1d203a85ccb105ba8eb82"}, - {file = "beta9-0.1.77.tar.gz", hash = "sha256:daf8d32fae64d1c5a031d84c3cec2c1f419e33dbc446214c3ef80b56accb32bd"}, + {file = "beta9-0.1.79-py3-none-any.whl", hash = "sha256:25ff2e2c59952c698fa4490cf0a46c3267ba5b627319d75ecb1c3a9c71b07d24"}, + {file = "beta9-0.1.79.tar.gz", hash = "sha256:1fde42caeb001dff3647876061230445e7417b27a1312b102ff3e55cb6c45ab8"}, ] [package.dependencies] @@ -1317,4 +1317,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "dd7927b2b4551addeba12d13b54e1f0ba777066940da91d85fe2886acaaf0f2c" +content-hash = "b3be94ae030b91cc4e37b7561d3947a574c649d0adc1927d3b77106eafce0f17" diff --git a/pyproject.toml b/pyproject.toml index 85d738c..3aeb9ef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "beam-client" -version = "0.2.75" +version = "0.2.76" description = "" authors = ["beam.cloud "] packages = [ @@ -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" diff --git a/src/beam/cli/main.py b/src/beam/cli/main.py index 87eedb5..9882e5c 100644 --- a/src/beam/cli/main.py +++ b/src/beam/cli/main.py @@ -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 @@ -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 diff --git a/src/beam/cli/utils.py b/src/beam/cli/utils.py new file mode 100644 index 0000000..53c2ee5 --- /dev/null +++ b/src/beam/cli/utils.py @@ -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)