mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-09-21 18:36:47 +00:00
Merge branch 'main' into my-crewAI
This commit is contained in:
@@ -246,7 +246,7 @@ def _list_json(location: str) -> list[dict[str, Any]]:
|
||||
):
|
||||
name = os.path.basename(path)
|
||||
try:
|
||||
with open(path) as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
raw = f.read()
|
||||
meta = _parse_checkpoint_json(raw, source=name)
|
||||
meta["name"] = name
|
||||
@@ -267,7 +267,7 @@ def _info_json_latest(location: str) -> dict[str, Any] | None:
|
||||
if not files:
|
||||
return None
|
||||
path = files[0]
|
||||
with open(path) as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
raw = f.read()
|
||||
meta = _parse_checkpoint_json(raw, source=os.path.basename(path))
|
||||
meta["name"] = os.path.basename(path)
|
||||
@@ -278,7 +278,7 @@ def _info_json_latest(location: str) -> dict[str, Any] | None:
|
||||
|
||||
|
||||
def _info_json_file(path: str) -> dict[str, Any]:
|
||||
with open(path) as f:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
raw = f.read()
|
||||
meta = _parse_checkpoint_json(raw, source=os.path.basename(path))
|
||||
meta["name"] = os.path.basename(path)
|
||||
|
||||
@@ -89,7 +89,7 @@ def migrate_pyproject(input_file: str, output_file: str) -> None:
|
||||
lock_file = "poetry.lock"
|
||||
lock_backup = "poetry-old.lock"
|
||||
if os.path.exists(lock_file):
|
||||
os.rename(lock_file, lock_backup)
|
||||
os.replace(lock_file, lock_backup)
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
63
lib/cli/tests/test_update_crew.py
Normal file
63
lib/cli/tests/test_update_crew.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""Tests for the ``crewai update`` pyproject migration."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from crewai_cli.update_crew import migrate_pyproject
|
||||
|
||||
|
||||
_POETRY_PYPROJECT = """\
|
||||
[tool.poetry]
|
||||
name = "demo"
|
||||
version = "0.1.0"
|
||||
description = "demo crew"
|
||||
authors = ["Demo Author <demo@example.com>"]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.10,<3.14"
|
||||
crewai = "^1.0.0"
|
||||
"""
|
||||
|
||||
|
||||
def _write_project(tmp_path: Path) -> None:
|
||||
"""Create a minimal Poetry-style project with a lock file in ``tmp_path``."""
|
||||
(tmp_path / "pyproject.toml").write_text(_POETRY_PYPROJECT, encoding="utf-8")
|
||||
(tmp_path / "poetry.lock").write_text("current lock\n", encoding="utf-8")
|
||||
|
||||
|
||||
def test_migrate_pyproject_backs_up_lock_file(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""The migration renames ``poetry.lock`` to ``poetry-old.lock`` and backs up pyproject."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
_write_project(tmp_path)
|
||||
|
||||
migrate_pyproject("pyproject.toml", "pyproject.toml")
|
||||
|
||||
assert not (tmp_path / "poetry.lock").exists()
|
||||
assert (tmp_path / "poetry-old.lock").read_text(encoding="utf-8") == (
|
||||
"current lock\n"
|
||||
)
|
||||
assert (tmp_path / "pyproject-old.toml").exists()
|
||||
|
||||
|
||||
def test_migrate_pyproject_overwrites_existing_lock_backup(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""A second ``crewai update`` must replace a stale ``poetry-old.lock``.
|
||||
|
||||
``os.rename`` refuses to overwrite an existing destination on Windows
|
||||
(``FileExistsError``) while POSIX replaces it silently, so re-running the
|
||||
migration used to fail only on Windows.
|
||||
"""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
_write_project(tmp_path)
|
||||
(tmp_path / "poetry-old.lock").write_text("stale backup\n", encoding="utf-8")
|
||||
|
||||
migrate_pyproject("pyproject.toml", "pyproject.toml")
|
||||
|
||||
assert not (tmp_path / "poetry.lock").exists()
|
||||
assert (tmp_path / "poetry-old.lock").read_text(encoding="utf-8") == (
|
||||
"current lock\n"
|
||||
)
|
||||
Reference in New Issue
Block a user