Skip to content

Commit

Permalink
Merge pull request #117 from Bishoy-at-pieces/pieces_version_check
Browse files Browse the repository at this point in the history
feat: add version restriction for compatibility (issue: #114)
  • Loading branch information
Bishoy-at-pieces authored May 20, 2024
2 parents 826184e + e6f5b2c commit a26ed77
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
13 changes: 12 additions & 1 deletion poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
prompt-toolkit = "^3.0.43"
rich = "^13.7.1"
platformdirs = "^4.2.0"
semver = "^3.0.2"

[tool.poetry.group.dev.dependencies]
pytest = "^8.0.0"
Expand Down
4 changes: 2 additions & 2 deletions src/pieces/commands/version_command.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pieces.settings import Settings
from pieces import __version__
from pieces.gui import print_version_details

def version(**kwargs):
if Settings.pieces_os_version:
print(f"Pieces Version: {Settings.pieces_os_version}")
print(f"Cli Version: {__version__}")
print_version_details(Settings.pieces_os_version,__version__)
else:
pass
11 changes: 10 additions & 1 deletion src/pieces/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ def server_startup_failed():
print("Please make sure Pieces OS is running and up-to-date")
print()
print("Or, to install Pieces OS, please visit this link:")
print("https://docs.pieces.app/installation-getting-started/what-am-i-installing")
print_pieces_os_link()
print()
print("############################")
print()


def print_version_details(pos_version,cli_version):
print(f"Pieces OS Version: {pos_version}")
print(f"CLI Version: {cli_version}")

def print_pieces_os_link():
print("https://docs.pieces.app/installation-getting-started/what-am-i-installing")


def double_space(text):
print()
print(text)
Expand Down
37 changes: 35 additions & 2 deletions src/pieces/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import sys
import threading
from platformdirs import user_data_dir

import semver
from pieces import __version__
from pieces.gui import server_startup_failed
from pieces.gui import server_startup_failed, print_pieces_os_link,print_version_details

from pieces_os_client.api.well_known_api import WellKnownApi
from pieces_os_client.api.connector_api import ConnectorApi
Expand All @@ -24,8 +24,12 @@
from pieces_os_client.models.seeded_tracked_application import SeededTrackedApplication
from pieces_os_client.models.application_name_enum import ApplicationNameEnum



class Settings:
"""Settings class for the CLI Agent"""
PIECES_OS_MIN_VERSION = "9.0.0" # Minium version (9.0.0)
PIECES_OS_MAX_VERSION = "10.0.0" # Maxium version (10.0.0)

TIMEOUT = 10 # Websocket ask timeout

Expand Down Expand Up @@ -144,6 +148,7 @@ def get_models_ids(cls) -> Dict[str, Dict[str, Union[str, int]]]:
def startup(cls):
pieces_os_version = cls.open_pieces_os()
if pieces_os_version:
cls.version_check() # Check the version first
model_thread = threading.Thread(target=cls.load_models)
connector_thread = threading.Thread(target=cls.connect_api)
model_thread.start()
Expand All @@ -154,6 +159,34 @@ def startup(cls):
server_startup_failed()
sys.exit(0) # Exit the program


@classmethod
def version_check(cls):
"""Check the version of the pieces os in the within range"""
pieces_os_version = cls.get_version()

# Parse version numbers
os_version_parsed = semver.VersionInfo.parse(pieces_os_version)
min_version_parsed = semver.VersionInfo.parse(cls.PIECES_OS_MIN_VERSION)
max_version_parsed = semver.VersionInfo.parse(cls.PIECES_OS_MAX_VERSION)

# Check compatibility
if os_version_parsed >= max_version_parsed:
print("Please update your cli-agent tool. It is not compatible with the current Pieces OS version")
print()
print("https://pypi.org/project/pieces-cli/")
print()
print_version_details(pieces_os_version, __version__)
sys.exit(0)
elif os_version_parsed < min_version_parsed:
print("Please update your Pieces OS. It is not compatible with the current cli-agent version")
print()
print_pieces_os_link()
print()
print_version_details(pieces_os_version, __version__)
sys.exit(0)


@classmethod
def open_pieces_os(cls) -> Optional[str]:
"""Open pieces os and return its version"""
Expand Down

0 comments on commit a26ed77

Please sign in to comment.