From b5db79da1261cdc3687a035b96a2d83c42b53e73 Mon Sep 17 00:00:00 2001 From: Eduardo Chiarotti Date: Thu, 22 Aug 2024 17:58:03 -0300 Subject: [PATCH] feat: add get crew version to send on header of request --- src/crewai/cli/deploy/utils.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/crewai/cli/deploy/utils.py b/src/crewai/cli/deploy/utils.py index 53cf7dc58..7e6a5feae 100644 --- a/src/crewai/cli/deploy/utils.py +++ b/src/crewai/cli/deploy/utils.py @@ -58,6 +58,31 @@ def get_project_name(pyproject_path: str = "pyproject.toml"): return None + def get_crewai_version(pyproject_path: str = "pyproject.toml") -> str: + """Get the version number of crewai from the pyproject.toml file.""" + try: + # Read the pyproject.toml file + with open("pyproject.toml", "rb") as f: + pyproject_content = tomllib.load(f) + + # Extract the version number of crewai + crewai_version = pyproject_content["tool"]["poetry"]["dependencies"][ + "crewai" + ]["version"] + + return crewai_version + + except FileNotFoundError: + print(f"Error: {pyproject_path} not found.") + except KeyError: + print(f"Error: {pyproject_path} is not a valid pyproject.toml file.") + except tomllib.TOMLDecodeError: + print(f"Error: {pyproject_path} is not a valid TOML file.") + except Exception as e: + print(f"Error reading the pyproject.toml file: {e}") + + return None + def fetch_and_json_env_file(env_file_path: str = ".env") -> dict: """Fetch the environment variables from a .env file and return them as a dictionary."""