From dc3af743ac6858217a3074a9fa85ef8b66c9b0ec Mon Sep 17 00:00:00 2001 From: bishoy-at-pieces Date: Wed, 8 Jan 2025 17:40:35 +0200 Subject: [PATCH 1/2] fix onboarding if PiecesOS is not running --- README.md | 8 +++---- poetry.lock | 2 +- pyproject.toml | 2 +- src/pieces/app.py | 23 +++++++++++++------ src/pieces/commands/cli_loop.py | 2 +- src/pieces/commands/install_pieces_os.py | 10 ++++---- src/pieces/commands/onboarding.py | 13 +++++++---- src/pieces/gui.py | 10 ++++---- src/pieces/settings.py | 6 ++--- src/pieces/wrapper/basic_identifier/tag.py | 2 +- src/pieces/wrapper/basic_identifier/user.py | 4 ++-- .../wrapper/basic_identifier/website.py | 4 ++-- src/pieces/wrapper/client.py | 12 ++++++---- src/pieces/wrapper/version_compatibility.py | 2 +- 14 files changed, 58 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 9c42267b..aa290186 100644 --- a/README.md +++ b/README.md @@ -3,18 +3,18 @@ #

Pieces Python CLI Tool -

This is a comprehensive command-line interface (CLI) tool designed to interact seamlessly with Pieces OS. It provides a range of functionalities such as asset management, application interaction, and integration with various Pieces OS features. +

This is a comprehensive command-line interface (CLI) tool designed to interact seamlessly with PiecesOS. It provides a range of functionalities such as asset management, application interaction, and integration with various PiecesOS features.

-#####

[Website](https://pieces.app/) • [Pieces OS Documentation](https://docs.pieces.app/) • [Pieces Python CLI Documentation](https://docs.pieces.app/extensions-plugins/cli) +#####

[Website](https://pieces.app/) • [PiecesOS Documentation](https://docs.pieces.app/) • [Pieces Python CLI Documentation](https://docs.pieces.app/extensions-plugins/cli)

[![Introducing CLI](https://img.youtube.com/vi/kAgwHMxWY8c/0.jpg)](https://www.youtube.com/watch?v=kAgwHMxWY8c) ## Important -Make sure you have [**Pieces OS**](https://docs.pieces.app/installation-getting-started/what-am-i-installing) installed in order to run the Pieces CLI tool. +Make sure you have [**PiecesOS**](https://docs.pieces.app/installation-getting-started/what-am-i-installing) installed in order to run the Pieces CLI tool. #### Operating System Support The Pieces Python CLI Tool is compatible with various operating systems, ensuring a wide range of usage and adaptability. While it offers full support across most systems, specific features might have varied performance based on the OS environment. @@ -27,7 +27,7 @@ The CLI Supports ## Installing To get started with the Pieces Python CLI Tool, you need to: -1. Ensure Pieces OS is installed and running on your system. +1. Ensure PiecesOS is installed and running on your system. 2. Install the Python package: ```bash diff --git a/poetry.lock b/poetry.lock index 3d071db9..b7a8e246 100644 --- a/poetry.lock +++ b/poetry.lock @@ -119,7 +119,7 @@ files = [ [[package]] name = "pieces-os-client" version = "4.1.0" -description = "A powerful code engine package for writing applications on top of Pieces OS" +description = "A powerful code engine package for writing applications on top of PiecesOS" optional = false python-versions = "<4.0,>=3.8" files = [ diff --git a/pyproject.toml b/pyproject.toml index b26ed957..2d014694 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "pieces-cli" version = "1.3.1" - description = "A powerful cli tool to interact with the Pieces OS " + description = "A powerful cli tool to interact with the PiecesOS " authors = ["Pieces "] readme = "README.md" homepage = "https://pieces.app" diff --git a/src/pieces/app.py b/src/pieces/app.py index 50ed9026..563f017e 100644 --- a/src/pieces/app.py +++ b/src/pieces/app.py @@ -67,7 +67,7 @@ def add_subparsers(self): ask_parser.set_defaults(func=ask_stream.ask) # Subparser for the 'version' command - version_parser = self.command_parser.add_parser('version', help='Gets version of Pieces OS') + version_parser = self.command_parser.add_parser('version', help='Gets version of PiecesOS') version_parser.set_defaults(func=version) # Subparser for Search @@ -82,11 +82,11 @@ def add_subparsers(self): help_parser.set_defaults(func=lambda **kwargs: print_help()) # Subparser for the 'login' command - login_parser = self.command_parser.add_parser('login', help='Login to pieces os') + login_parser = self.command_parser.add_parser('login', help='Login to PiecesOS') login_parser.set_defaults(func=sign_in) # Subparser for the 'logout' command - logout_parser = self.command_parser.add_parser('logout', help='Logout from pieces os') + logout_parser = self.command_parser.add_parser('logout', help='Logout from PiecesOS') logout_parser.set_defaults(func=sign_out) @@ -126,9 +126,13 @@ def add_subparsers(self): contribute_parser.set_defaults(func=contribute) # Subparser for the 'install' command - install_parser = self.command_parser.add_parser('install', help='Install the Pieces OS') + install_parser = self.command_parser.add_parser('install', help='Install the PiecesOS') install_parser.set_defaults(func=install_pieces_os) + # Subparser for the 'install' command + install_parser = self.command_parser.add_parser('open', help='Opens PiecesOS') + install_parser.set_defaults(func=lambda **kwargs:Settings.pieces_client.open_pieces_os()) + def run(self): try: @@ -138,8 +142,12 @@ def run(self): return config = ConfigCommands.load_config() + + + onboarded = config.get("onboarded", False) - if not config.get("skip_onboarding", False) and not Settings.pieces_client.application.onboarded: + + if not config.get("skip_onboarding", False) and not onboarded: res = input("It looks like this is your first time using the Pieces CLI.\nWould you like to start onboarding (y/n/skip)? ") if res.lower() == "y": return onboarding_command() @@ -147,8 +155,9 @@ def run(self): config["skip_onboarding"] = True ConfigCommands.save_config(config) - # Check if the command needs Pieces OS or not - if arg not in ['help',"-v","--version","onboarding","install", "feedback", "contribute"]: + + # Check if the command needs PiecesOS or not + if arg not in ['help',"-v","--version","install","onboarding", "feedback", "contribute","open"]: Settings.startup() args = self.parser.parse_args() diff --git a/src/pieces/commands/cli_loop.py b/src/pieces/commands/cli_loop.py index a51acd41..15493269 100644 --- a/src/pieces/commands/cli_loop.py +++ b/src/pieces/commands/cli_loop.py @@ -26,7 +26,7 @@ def loop(**kwargs): print( f"Operating System: {platform.platform()}\n", f"Python Version: {sys.version.split()[0]}\n", - f"Pieces OS Version: {Settings.pieces_os_version}\n", + f"PiecesOS Version: {Settings.pieces_os_version}\n", f"Pieces CLI Version: {__version__}\n", f"Application: {Settings.pieces_client.application.name.value if Settings.pieces_client.application else 'Unknown'}" ) diff --git a/src/pieces/commands/install_pieces_os.py b/src/pieces/commands/install_pieces_os.py index 4f33f004..6bfe29ab 100644 --- a/src/pieces/commands/install_pieces_os.py +++ b/src/pieces/commands/install_pieces_os.py @@ -4,7 +4,7 @@ def install_pieces_os(**kwargs): """ - Install Pieces OS based on the platform + Install PiecesOS based on the platform """ if Settings.pieces_client.local_os == "WINDOWS": @@ -33,14 +33,14 @@ def install_pieces_os(**kwargs): ) script = f""" TMP_PKG_PATH="/tmp/Pieces-OS-Launch.pkg" - echo "Downloading Pieces OS .pkg file from {pkg_url}..." + echo "Downloading PiecesOS .pkg file from {pkg_url}..." curl -L "{pkg_url}" -o "$TMP_PKG_PATH" if [ -f "$TMP_PKG_PATH" ]; then - echo "Pieces OS Download successful, installing the package..." + echo "PiecesOS Download successful, installing the package..." open "$TMP_PKG_PATH" - echo "Pieces OS Installation complete." + echo "PiecesOS Installation complete." else - echo "Failed to download and install Pieces OS." + echo "Failed to download and install PiecesOS." fi """ os.system(script) diff --git a/src/pieces/commands/onboarding.py b/src/pieces/commands/onboarding.py index e458505c..99d12786 100644 --- a/src/pieces/commands/onboarding.py +++ b/src/pieces/commands/onboarding.py @@ -1,4 +1,5 @@ from abc import ABC +from logging import config from typing import Callable import pyperclip from rich.markdown import Markdown @@ -13,6 +14,7 @@ import sys from pieces.commands.cli_loop import run_command, extract_text +from pieces.commands.config_command import ConfigCommands from pieces.settings import Settings def get_prompt(): @@ -148,10 +150,10 @@ def onboarding_command(**kwargs): console.print("Whenever you want to exit the onboarding flow type `exit`.") if not Settings.pieces_client.open_pieces_os(): - console.print("❌ Pieces OS is not running") + console.print("❌ PiecesOS is not running") console.print( Markdown( - "**Pieces OS** is a **required** background service" + "**PiecesOS** is a **required** background service" " that powers the Pieces CLI and all other Pieces Integrations such as:\n\n" "- **VS Code**\n" "- **JetBrains**\n" @@ -171,12 +173,12 @@ def onboarding_command(**kwargs): ) OnboardingCommandStep( - "To install Pieces OS run `pieces install`", + "To install PiecesOS run `pieces install`", "pieces install" ).run(console) else: - console.print("✅ Pieces OS is running") + console.print("✅ PiecesOS is running") Settings.startup() @@ -193,5 +195,8 @@ def onboarding_command(**kwargs): console.print(Markdown("You are now a `10x` more productive developer with Pieces.")) console.print("For more information visit https://docs.pieces.app/extensions-plugins/cli") Settings.pieces_client.connector_api.onboarded(Settings.pieces_client.application.id, True) + config = ConfigCommands.load_config() + config["onboarded"] = True + ConfigCommands.save_config(config) diff --git a/src/pieces/gui.py b/src/pieces/gui.py index b8fe0468..2b0192bd 100644 --- a/src/pieces/gui.py +++ b/src/pieces/gui.py @@ -32,9 +32,9 @@ def server_startup_failed(): print() print("############################") print() - print("Please make sure Pieces OS is running and up-to-date") + print("Please make sure PiecesOS is running and up-to-date") print() - print("Or, to install Pieces OS, please visit this link:") + print("Or, to install PiecesOS, please visit this link:") print_pieces_os_link() print() print("############################") @@ -42,7 +42,7 @@ def server_startup_failed(): def print_version_details(pos_version,cli_version): - print(f"Pieces OS Version: {pos_version}") + print(f"PiecesOS Version: {pos_version}") print(f"CLI Version: {cli_version}") def print_pieces_os_link(): @@ -109,12 +109,12 @@ def print_help(): print(" Login - Login to pieces") print(" Logout - Logout from pieces") print() - print(" version - Gets version of Pieces OS and the version of the cli tool") + print(" version - Gets version of PiecesOS and the version of the cli tool") print(" help - Show this help message") print(" onboarding - Start the onboarding process") print(" feedback - Send feedback to Pieces") print(" contribute - Contribute to Pieces CLI") - print(" install - Install Pieces OS") + print(" install - Install PiecesOS") print() def print_asset_details(asset:"BasicAsset"): diff --git a/src/pieces/settings.py b/src/pieces/settings.py index e23e3ebb..cc129e22 100644 --- a/src/pieces/settings.py +++ b/src/pieces/settings.py @@ -105,20 +105,20 @@ def startup(cls): @classmethod def version_check(cls): - """Check the version of the pieces os in the within range""" + """Check the version of the PiecesOS in the within range""" cls.pieces_os_version = cls.pieces_client.version result = VersionChecker(cls.PIECES_OS_MIN_VERSION,cls.PIECES_OS_MAX_VERSION,cls.pieces_os_version).version_check() # Check compatibility if result.update == UpdateEnum.Plugin: - print("Please update your cli-agent tool. It is not compatible with the current Pieces OS version") + print("Please update your cli-agent tool. It is not compatible with the current PiecesOS version") print() print("https://pypi.org/project/pieces-cli/") print() print_version_details(cls.pieces_os_version, __version__) sys.exit(2) elif result.update == UpdateEnum.PiecesOS: - print("Please update Pieces OS. It is not compatible with the current cli-agent version") + print("Please update PiecesOS. It is not compatible with the current cli-agent version") print() print_pieces_os_link() print() diff --git a/src/pieces/wrapper/basic_identifier/tag.py b/src/pieces/wrapper/basic_identifier/tag.py index a40f880f..4ea84dab 100644 --- a/src/pieces/wrapper/basic_identifier/tag.py +++ b/src/pieces/wrapper/basic_identifier/tag.py @@ -21,7 +21,7 @@ def __init__(self, pieces_client: "PiecesClient", tag: "Tag") -> None: Initializes a BasicTag instance. Args: - - tag (Tag): Pieces OS tag object + - tag (Tag): PiecesOS tag object """ self.tag = tag self.pieces_client = pieces_client diff --git a/src/pieces/wrapper/basic_identifier/user.py b/src/pieces/wrapper/basic_identifier/user.py index 29194bbf..f83645a7 100644 --- a/src/pieces/wrapper/basic_identifier/user.py +++ b/src/pieces/wrapper/basic_identifier/user.py @@ -13,7 +13,7 @@ class BasicUser(Basic): Attributes: user_profile: The profile of the user. - pieces_client: The client used to interact with the pieces OS API. + pieces_client: The client used to interact with the PiecesOS API. """ user_profile: Optional["UserProfile"] = None @@ -23,7 +23,7 @@ def __init__(self, pieces_client) -> None: Initializes the BasicUser with a pieces client. Args: - pieces_client: The client used to interact with the pieces OS API. + pieces_client: The client used to interact with the PiecesOS API. """ self.pieces_client = pieces_client diff --git a/src/pieces/wrapper/basic_identifier/website.py b/src/pieces/wrapper/basic_identifier/website.py index b1d4708e..40c82c1b 100644 --- a/src/pieces/wrapper/basic_identifier/website.py +++ b/src/pieces/wrapper/basic_identifier/website.py @@ -222,13 +222,13 @@ def disassociate_chat(self, chat: "BasicChat"): def delete(self): """ - Deletes the website from the Pieces OS. + Deletes the website from the PiecesOS. """ self.pieces_client.websites_api.websites_delete_specific_website(self.website.id) def _edit_website(self, website: "Website"): """ - Edits the website in the Pieces OS. + Edits the website in the PiecesOS. Args: - website: The Website object to edit. diff --git a/src/pieces/wrapper/client.py b/src/pieces/wrapper/client.py index 37c6d765..eb15bc84 100644 --- a/src/pieces/wrapper/client.py +++ b/src/pieces/wrapper/client.py @@ -179,7 +179,7 @@ def close(cls): @property def version(self) -> str: """ - Returns Pieces OS Version + Returns PiecesOS Version """ return self.well_known_api.get_well_known_version() @@ -194,9 +194,9 @@ def health(self) -> str: def open_pieces_os(self) -> bool: """ - Open Pieces OS + Open PiecesOS - Returns (bool): true if Pieces OS runned successfully else false + Returns (bool): true if PiecesOS runned successfully else false """ if self.is_pieces_running(): return True if self.local_os == "WINDOWS": @@ -210,15 +210,17 @@ def open_pieces_os(self) -> bool: def is_pieces_running(self,maxium_retries=1) -> bool: """ - Checks if Pieces OS is running or not + Checks if PiecesOS is running or not - Returns (bool): true if Pieces OS is running + Returns (bool): true if PiecesOS is running """ for _ in range(maxium_retries): try: with urllib.request.urlopen(f"{self.host}/.well-known/health", timeout=1) as response: return response.status == 200 except: + if maxium_retries == 1: + return False time.sleep(1) return False diff --git a/src/pieces/wrapper/version_compatibility.py b/src/pieces/wrapper/version_compatibility.py index 14e6c8f0..ee02b1ca 100644 --- a/src/pieces/wrapper/version_compatibility.py +++ b/src/pieces/wrapper/version_compatibility.py @@ -50,7 +50,7 @@ def compare(cls, version1: str, version2: str) -> int: return 0 def version_check(self) -> 'VersionCheckResult': - """Check if the Pieces OS version is within the supported range.""" + """Check if the PiecesOS version is within the supported range.""" if self.compare(self.pieces_os_version, self.min_version) < 0: return VersionCheckResult(False, UpdateEnum.PiecesOS) elif self.compare(self.pieces_os_version, self.max_version) >= 0: From 2f5d66271d77a9a2f70238c179be03239e641dc9 Mon Sep 17 00:00:00 2001 From: bishoy-at-pieces Date: Thu, 9 Jan 2025 16:39:32 +0200 Subject: [PATCH 2/2] fix doc strings typos --- pyproject.toml | 3 +-- src/pieces/app.py | 2 +- src/pieces/settings.py | 2 +- src/pieces/wrapper/basic_identifier/website.py | 4 ++-- src/pieces/wrapper/client.py | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2d014694..d1514001 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "pieces-cli" version = "1.3.1" - description = "A powerful cli tool to interact with the PiecesOS " + description = "A powerful cli tool to interact with PiecesOS " authors = ["Pieces "] readme = "README.md" homepage = "https://pieces.app" @@ -22,7 +22,6 @@ [tool.poetry.group.dev.dependencies] pytest = "^8.0.0" pyinstaller = "^6.3.0" -# pieces_os_client = {path = "../pieces-os-client-sdk-for-python/dist/pieces_os_client-1.2.7-py3-none-any.whl"} [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/src/pieces/app.py b/src/pieces/app.py index 563f017e..99a3a6ff 100644 --- a/src/pieces/app.py +++ b/src/pieces/app.py @@ -126,7 +126,7 @@ def add_subparsers(self): contribute_parser.set_defaults(func=contribute) # Subparser for the 'install' command - install_parser = self.command_parser.add_parser('install', help='Install the PiecesOS') + install_parser = self.command_parser.add_parser('install', help='Install PiecesOS') install_parser.set_defaults(func=install_pieces_os) # Subparser for the 'install' command diff --git a/src/pieces/settings.py b/src/pieces/settings.py index cc129e22..587c157c 100644 --- a/src/pieces/settings.py +++ b/src/pieces/settings.py @@ -105,7 +105,7 @@ def startup(cls): @classmethod def version_check(cls): - """Check the version of the PiecesOS in the within range""" + """Check if the version of PiecesOS is compatible""" cls.pieces_os_version = cls.pieces_client.version result = VersionChecker(cls.PIECES_OS_MIN_VERSION,cls.PIECES_OS_MAX_VERSION,cls.pieces_os_version).version_check() diff --git a/src/pieces/wrapper/basic_identifier/website.py b/src/pieces/wrapper/basic_identifier/website.py index 40c82c1b..9821cdbb 100644 --- a/src/pieces/wrapper/basic_identifier/website.py +++ b/src/pieces/wrapper/basic_identifier/website.py @@ -222,13 +222,13 @@ def disassociate_chat(self, chat: "BasicChat"): def delete(self): """ - Deletes the website from the PiecesOS. + Deletes the website from PiecesOS """ self.pieces_client.websites_api.websites_delete_specific_website(self.website.id) def _edit_website(self, website: "Website"): """ - Edits the website in the PiecesOS. + Edits the website in PiecesOS. Args: - website: The Website object to edit. diff --git a/src/pieces/wrapper/client.py b/src/pieces/wrapper/client.py index ad04eaaa..43b29965 100644 --- a/src/pieces/wrapper/client.py +++ b/src/pieces/wrapper/client.py @@ -218,7 +218,7 @@ def open_pieces_os(self) -> bool: """ Open PiecesOS - Returns (bool): true if PiecesOS runned successfully else false + Returns (bool): true if PiecesOS launches successfully """ if self.is_pieces_running(): return True if self.local_os == "WINDOWS":