mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
Get current crewai version from poetry.lock
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import ast
|
||||||
|
|
||||||
from ..authentication.utils import TokenManager
|
from ..authentication.utils import TokenManager
|
||||||
|
|
||||||
@@ -92,32 +93,27 @@ def get_project_name(pyproject_path: str = "pyproject.toml"):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_crewai_version(pyproject_path: str = "pyproject.toml") -> str:
|
def get_crewai_version(poetry_lock_path: str = "poetry.lock") -> str:
|
||||||
"""Get the version number of crewai from the pyproject.toml file."""
|
"""Get the version number of crewai from the poetry.lock file."""
|
||||||
try:
|
try:
|
||||||
# Read the pyproject.toml file
|
with open(poetry_lock_path, "r") as f:
|
||||||
with open(pyproject_path, "rb") as f:
|
lock_content = f.read()
|
||||||
pyproject_content = parse_toml(f.read())
|
|
||||||
|
|
||||||
# Extract the version number of crewai
|
match = re.search(
|
||||||
crewai_version = pyproject_content["tool"]["poetry"]["dependencies"]["crewai"][
|
r'\[\[package\]\]\s*name\s*=\s*"crewai"\s*version\s*=\s*"([^"]+)"',
|
||||||
"version"
|
lock_content,
|
||||||
]
|
re.DOTALL,
|
||||||
|
)
|
||||||
return crewai_version
|
if match:
|
||||||
|
return match.group(1)
|
||||||
|
else:
|
||||||
|
print("crewai package not found in poetry.lock")
|
||||||
|
return "no-version-found"
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(f"Error: {pyproject_path} not found.")
|
print(f"Error: {poetry_lock_path} not found.")
|
||||||
except KeyError:
|
|
||||||
print(f"Error: {pyproject_path} is not a valid pyproject.toml file.")
|
|
||||||
except tomllib.TOMLDecodeError if sys.version_info >= (3, 11) else Exception as e:
|
|
||||||
print(
|
|
||||||
f"Error: {pyproject_path} is not a valid TOML file."
|
|
||||||
if sys.version_info >= (3, 11)
|
|
||||||
else f"Error reading the pyproject.toml file: {e}"
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error reading the pyproject.toml file: {e}")
|
print(f"Error reading the poetry.lock file: {e}")
|
||||||
|
|
||||||
return "no-version-found"
|
return "no-version-found"
|
||||||
|
|
||||||
|
|||||||
@@ -153,21 +153,6 @@ class TestDeployCommand(unittest.TestCase):
|
|||||||
"Crew 'test_project' removed successfully", fake_out.getvalue()
|
"Crew 'test_project' removed successfully", fake_out.getvalue()
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch('crewai.cli.deploy.utils.sys.version_info', (3, 10))
|
|
||||||
def test_parse_toml_python_310(self):
|
|
||||||
toml_content = """
|
|
||||||
[tool.poetry]
|
|
||||||
name = "test_project"
|
|
||||||
version = "0.1.0"
|
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
|
||||||
python = "^3.10"
|
|
||||||
crewai = "^0.1.0"
|
|
||||||
"""
|
|
||||||
parsed = parse_toml(toml_content)
|
|
||||||
self.assertEqual(parsed['tool']['poetry']['name'], 'test_project')
|
|
||||||
self.assertEqual(parsed['tool']['poetry']['dependencies']['crewai'], '^0.1.0')
|
|
||||||
|
|
||||||
@unittest.skipIf(sys.version_info < (3, 11), "Requires Python 3.11+")
|
@unittest.skipIf(sys.version_info < (3, 11), "Requires Python 3.11+")
|
||||||
def test_parse_toml_python_311_plus(self):
|
def test_parse_toml_python_311_plus(self):
|
||||||
toml_content = """
|
toml_content = """
|
||||||
@@ -177,11 +162,10 @@ class TestDeployCommand(unittest.TestCase):
|
|||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.11"
|
python = "^3.11"
|
||||||
crewai = "^0.1.0"
|
crewai = { extras = ["tools"], version = ">=0.51.0,<1.0.0" }
|
||||||
"""
|
"""
|
||||||
parsed = parse_toml(toml_content)
|
parsed = parse_toml(toml_content)
|
||||||
self.assertEqual(parsed['tool']['poetry']['name'], 'test_project')
|
self.assertEqual(parsed['tool']['poetry']['name'], 'test_project')
|
||||||
self.assertEqual(parsed['tool']['poetry']['dependencies']['crewai'], '^0.1.0')
|
|
||||||
|
|
||||||
@patch('builtins.open', new_callable=unittest.mock.mock_open, read_data="""
|
@patch('builtins.open', new_callable=unittest.mock.mock_open, read_data="""
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
@@ -190,7 +174,7 @@ class TestDeployCommand(unittest.TestCase):
|
|||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.10"
|
python = "^3.10"
|
||||||
crewai = "^0.1.0"
|
crewai = { extras = ["tools"], version = ">=0.51.0,<1.0.0" }
|
||||||
""")
|
""")
|
||||||
def test_get_project_name_python_310(self, mock_open):
|
def test_get_project_name_python_310(self, mock_open):
|
||||||
from crewai.cli.deploy.utils import get_project_name
|
from crewai.cli.deploy.utils import get_project_name
|
||||||
@@ -205,9 +189,31 @@ class TestDeployCommand(unittest.TestCase):
|
|||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.11"
|
python = "^3.11"
|
||||||
crewai = "^0.1.0"
|
crewai = { extras = ["tools"], version = ">=0.51.0,<1.0.0" }
|
||||||
""")
|
""")
|
||||||
def test_get_project_name_python_311_plus(self, mock_open):
|
def test_get_project_name_python_311_plus(self, mock_open):
|
||||||
from crewai.cli.deploy.utils import get_project_name
|
from crewai.cli.deploy.utils import get_project_name
|
||||||
project_name = get_project_name()
|
project_name = get_project_name()
|
||||||
self.assertEqual(project_name, 'test_project')
|
self.assertEqual(project_name, 'test_project')
|
||||||
|
|
||||||
|
@patch('builtins.open', new_callable=unittest.mock.mock_open, read_data="""
|
||||||
|
[[package]]
|
||||||
|
name = "crewai"
|
||||||
|
version = "0.51.1"
|
||||||
|
description = "Some description"
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.10,<4.0"
|
||||||
|
""")
|
||||||
|
def test_get_crewai_version(self, mock_open):
|
||||||
|
from crewai.cli.deploy.utils import get_crewai_version
|
||||||
|
version = get_crewai_version()
|
||||||
|
self.assertEqual(version, '0.51.1')
|
||||||
|
|
||||||
|
@patch('builtins.open', side_effect=FileNotFoundError)
|
||||||
|
def test_get_crewai_version_file_not_found(self, mock_open):
|
||||||
|
from crewai.cli.deploy.utils import get_crewai_version
|
||||||
|
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||||
|
version = get_crewai_version()
|
||||||
|
self.assertEqual(version, 'no-version-found')
|
||||||
|
self.assertIn("Error: poetry.lock not found.", fake_out.getvalue())
|
||||||
|
|||||||
Reference in New Issue
Block a user