From 39888fcb3ba4c3ab83e9d2b3a67a66b76bf55fad Mon Sep 17 00:00:00 2001 From: Kye Date: Thu, 7 Dec 2023 18:09:05 -0800 Subject: [PATCH] [CLI] --- pyproject.toml | 7 +++++- swarms/cli/__init__.py | 0 swarms/cli/_cli.py | 40 ++++++++++++++++++++++++++++++ swarms/memory/pg.py | 6 ++--- swarms/memory/qdrant.py | 2 -- tests/upload_tests_to_issues.py | 43 ++++++++++++++++++++------------- 6 files changed, 75 insertions(+), 23 deletions(-) create mode 100644 swarms/cli/__init__.py create mode 100644 swarms/cli/_cli.py diff --git a/pyproject.toml b/pyproject.toml index 78d8b7ae..6485df3e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "2.6.0" +version = "2.6.1" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] @@ -94,3 +94,8 @@ target-version = ['py38'] preview = true +[tool.poetry.scripts] +swarms = "swarms.cli._cli:run_file" + + + diff --git a/swarms/cli/__init__.py b/swarms/cli/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/swarms/cli/_cli.py b/swarms/cli/_cli.py new file mode 100644 index 00000000..5b4a3ebd --- /dev/null +++ b/swarms/cli/_cli.py @@ -0,0 +1,40 @@ +# import argparse +# import sys + +# def run_file(): +# parser = argparse.ArgumentParser(description='Swarms CLI') +# parser.add_argument('file_name', help='Python file containing Swarms code to run') + +# # Help message for the -h flag is automatically generated by argparse +# parser.add_argument('-v', '--version', action='version', version='%(prog)s 0.1.0') + +# # Check deployments for a given model +# parser.add_argument('-c', '--check', help='Check deployments for a given agent') + +# args = parser.parse_args() + +# # Execute the specified file +# try: +# with open(args.file_name, 'r') as file: +# exec(file.read(), globals()) +# except FileNotFoundError: +# print(f"Error: File '{args.file_name}' not found.") +# sys.exit(1) +# except Exception as e: +# print(f"Error executing file '{args.file_name}': {e}") +# sys.exit(1) + +# if __name__ == '__main__': +# main() + +# swarms/cli/_cli.py +import sys +import subprocess + +def run_file(): + if len(sys.argv) != 3 or sys.argv[1] != "run": + print("Usage: swarms run file_name.py") + sys.exit(1) + + file_name = sys.argv[2] + subprocess.run(["python", file_name], check=True) diff --git a/swarms/memory/pg.py b/swarms/memory/pg.py index 1d44984b..50972d98 100644 --- a/swarms/memory/pg.py +++ b/swarms/memory/pg.py @@ -12,18 +12,18 @@ try: from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import Session except ImportError: - print("The PgVectorVectorStore requires sqlalchemy to be installed") + print( + "The PgVectorVectorStore requires sqlalchemy to be installed" + ) print("pip install sqlalchemy") subprocess.run(["pip", "install", "sqlalchemy"]) try: - from pgvector.sqlalchemy import Vector except ImportError: print("The PgVectorVectorStore requires pgvector to be installed") print("pip install pgvector") subprocess.run(["pip", "install", "pgvector"]) - @define diff --git a/swarms/memory/qdrant.py b/swarms/memory/qdrant.py index 14a63e0b..56596965 100644 --- a/swarms/memory/qdrant.py +++ b/swarms/memory/qdrant.py @@ -3,7 +3,6 @@ from typing import List from httpx import RequestError try: - from sentence_transformers import SentenceTransformer except ImportError: print("Please install the sentence-transformers package") @@ -13,7 +12,6 @@ except ImportError: try: - from qdrant_client import QdrantClient from qdrant_client.http.models import ( Distance, diff --git a/tests/upload_tests_to_issues.py b/tests/upload_tests_to_issues.py index cc2392e3..864fee29 100644 --- a/tests/upload_tests_to_issues.py +++ b/tests/upload_tests_to_issues.py @@ -8,51 +8,60 @@ from dotenv import load_dotenv load_dotenv # Constants -GITHUB_USERNAME = os.getenv('GITHUB_USERNAME') -REPO_NAME = os.getenv('GITHUB_REPO_NAME') -GITHUB_TOKEN = os.getenv('GITHUB_TOKEN') -ISSUES_URL = f'https://api.github.com/repos/{GITHUB_USERNAME}/{REPO_NAME}/issues' +GITHUB_USERNAME = os.getenv("GITHUB_USERNAME") +REPO_NAME = os.getenv("GITHUB_REPO_NAME") +GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") +ISSUES_URL = f"https://api.github.com/repos/{GITHUB_USERNAME}/{REPO_NAME}/issues" # Headers for authentication headers = { - 'Authorization': f'token {GITHUB_TOKEN}', - 'Accept': 'application/vnd.github.v3+json' + "Authorization": f"token {GITHUB_TOKEN}", + "Accept": "application/vnd.github.v3+json", } + def run_pytest(): - result = subprocess.run(['pytest'], capture_output=True, text=True) + result = subprocess.run( + ["pytest"], capture_output=True, text=True + ) return result.stdout + result.stderr + def parse_pytest_output(output): errors = [] current_error = None - for line in output.split('\n'): - if line.startswith('_________________________'): + for line in output.split("\n"): + if line.startswith("_________________________"): if current_error: errors.append(current_error) - current_error = {'title': '', 'body': ''} + current_error = {"title": "", "body": ""} elif current_error is not None: - if not current_error['title']: - current_error['title'] = line.strip() - current_error['body'] += line + '\n' + if not current_error["title"]: + current_error["title"] = line.strip() + current_error["body"] += line + "\n" if current_error: errors.append(current_error) return errors + def create_github_issue(title, body): - issue = {'title': title, 'body': body} + issue = {"title": title, "body": body} response = requests.post(ISSUES_URL, headers=headers, json=issue) return response.json() + def main(): pytest_output = run_pytest() errors = parse_pytest_output(pytest_output) - + for error in errors: - issue_response = create_github_issue(error['title'], error['body']) + issue_response = create_github_issue( + error["title"], error["body"] + ) print(f"Issue created: {issue_response.get('html_url')}") -if __name__ == '__main__': + +if __name__ == "__main__": main()