mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
Fix: Add --active flag to uv sync command to fix virtual environment detection
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -8,7 +8,7 @@ def install_crew(proxy_options: list[str]) -> None:
|
|||||||
Install the crew by running the UV command to lock and install.
|
Install the crew by running the UV command to lock and install.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
command = ["uv", "sync"] + proxy_options
|
command = ["uv", "sync", "--active"] + proxy_options
|
||||||
subprocess.run(command, check=True, capture_output=False, text=True)
|
subprocess.run(command, check=True, capture_output=False, text=True)
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
|
|||||||
54
tests/cli/install_crew_test.py
Normal file
54
tests/cli/install_crew_test.py
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
from unittest import mock
|
||||||
|
import pytest
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from crewai.cli.install_crew import install_crew
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch("subprocess.run")
|
||||||
|
def test_install_crew_with_active_flag(mock_subprocess):
|
||||||
|
"""Test that install_crew includes the --active flag."""
|
||||||
|
install_crew([])
|
||||||
|
mock_subprocess.assert_called_once_with(
|
||||||
|
["uv", "sync", "--active"], check=True, capture_output=False, text=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch("subprocess.run")
|
||||||
|
def test_install_crew_with_proxy_options(mock_subprocess):
|
||||||
|
"""Test that install_crew correctly passes proxy options."""
|
||||||
|
proxy_options = ["--index-url", "https://custom-pypi.org/simple"]
|
||||||
|
install_crew(proxy_options)
|
||||||
|
mock_subprocess.assert_called_once_with(
|
||||||
|
["uv", "sync", "--active", "--index-url", "https://custom-pypi.org/simple"],
|
||||||
|
check=True,
|
||||||
|
capture_output=False,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch("subprocess.run")
|
||||||
|
@mock.patch("click.echo")
|
||||||
|
def test_install_crew_with_subprocess_error(mock_echo, mock_subprocess):
|
||||||
|
"""Test that install_crew handles subprocess errors correctly."""
|
||||||
|
error = subprocess.CalledProcessError(1, "uv sync --active")
|
||||||
|
error.output = "Error output"
|
||||||
|
mock_subprocess.side_effect = error
|
||||||
|
|
||||||
|
install_crew([])
|
||||||
|
|
||||||
|
assert mock_echo.call_count == 2
|
||||||
|
mock_echo.assert_any_call(f"An error occurred while running the crew: {error}", err=True)
|
||||||
|
mock_echo.assert_any_call("Error output", err=True)
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch("subprocess.run")
|
||||||
|
@mock.patch("click.echo")
|
||||||
|
def test_install_crew_with_generic_exception(mock_echo, mock_subprocess):
|
||||||
|
"""Test that install_crew handles generic exceptions correctly."""
|
||||||
|
error = Exception("Generic error")
|
||||||
|
mock_subprocess.side_effect = error
|
||||||
|
|
||||||
|
install_crew([])
|
||||||
|
|
||||||
|
mock_echo.assert_called_once_with(f"An unexpected error occurred: {error}", err=True)
|
||||||
Reference in New Issue
Block a user