Apply automatic linting fixes to src directory

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-05-12 13:30:50 +00:00
parent 807dfe0558
commit ad1ea46bbb
160 changed files with 3218 additions and 3197 deletions

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional
from typing import Any
from rich.console import Console
@@ -10,34 +10,27 @@ console = Console()
class DeployCommand(BaseCommand, PlusAPIMixin):
"""
A class to handle deployment-related operations for CrewAI projects.
"""
def __init__(self):
"""
Initialize the DeployCommand with project name and API client.
"""
"""A class to handle deployment-related operations for CrewAI projects."""
def __init__(self) -> None:
"""Initialize the DeployCommand with project name and API client."""
BaseCommand.__init__(self)
PlusAPIMixin.__init__(self, telemetry=self._telemetry)
self.project_name = get_project_name(require=True)
def _standard_no_param_error_message(self) -> None:
"""
Display a standard error message when no UUID or project name is available.
"""
"""Display a standard error message when no UUID or project name is available."""
console.print(
"No UUID provided, project pyproject.toml not found or with error.",
style="bold red",
)
def _display_deployment_info(self, json_response: Dict[str, Any]) -> None:
"""
Display deployment information.
def _display_deployment_info(self, json_response: dict[str, Any]) -> None:
"""Display deployment information.
Args:
json_response (Dict[str, Any]): The deployment information to display.
"""
console.print("Deploying the crew...\n", style="bold blue")
for key, value in json_response.items():
@@ -47,24 +40,24 @@ class DeployCommand(BaseCommand, PlusAPIMixin):
console.print(" or")
console.print(f"crewai deploy status --uuid \"{json_response['uuid']}\"")
def _display_logs(self, log_messages: List[Dict[str, Any]]) -> None:
"""
Display log messages.
def _display_logs(self, log_messages: list[dict[str, Any]]) -> None:
"""Display log messages.
Args:
log_messages (List[Dict[str, Any]]): The log messages to display.
"""
for log_message in log_messages:
console.print(
f"{log_message['timestamp']} - {log_message['level']}: {log_message['message']}"
f"{log_message['timestamp']} - {log_message['level']}: {log_message['message']}",
)
def deploy(self, uuid: Optional[str] = None) -> None:
"""
Deploy a crew using either UUID or project name.
def deploy(self, uuid: str | None = None) -> None:
"""Deploy a crew using either UUID or project name.
Args:
uuid (Optional[str]): The UUID of the crew to deploy.
"""
self._start_deployment_span = self._telemetry.start_deployment_span(uuid)
console.print("Starting deployment...", style="bold blue")
@@ -80,9 +73,7 @@ class DeployCommand(BaseCommand, PlusAPIMixin):
self._display_deployment_info(response.json())
def create_crew(self, confirm: bool = False) -> None:
"""
Create a new crew deployment.
"""
"""Create a new crew deployment."""
self._create_crew_deployment_span = (
self._telemetry.create_crew_deployment_span()
)
@@ -110,29 +101,28 @@ class DeployCommand(BaseCommand, PlusAPIMixin):
self._display_creation_success(response.json())
def _confirm_input(
self, env_vars: Dict[str, str], remote_repo_url: str, confirm: bool
self, env_vars: dict[str, str], remote_repo_url: str, confirm: bool,
) -> None:
"""
Confirm input parameters with the user.
"""Confirm input parameters with the user.
Args:
env_vars (Dict[str, str]): Environment variables.
remote_repo_url (str): Remote repository URL.
confirm (bool): Whether to confirm input.
"""
if not confirm:
input(f"Press Enter to continue with the following Env vars: {env_vars}")
input(
f"Press Enter to continue with the following remote repository: {remote_repo_url}\n"
f"Press Enter to continue with the following remote repository: {remote_repo_url}\n",
)
def _create_payload(
self,
env_vars: Dict[str, str],
env_vars: dict[str, str],
remote_repo_url: str,
) -> Dict[str, Any]:
"""
Create the payload for crew creation.
) -> dict[str, Any]:
"""Create the payload for crew creation.
Args:
remote_repo_url (str): Remote repository URL.
@@ -140,25 +130,26 @@ class DeployCommand(BaseCommand, PlusAPIMixin):
Returns:
Dict[str, Any]: The payload for crew creation.
"""
return {
"deploy": {
"name": self.project_name,
"repo_clone_url": remote_repo_url,
"env": env_vars,
}
},
}
def _display_creation_success(self, json_response: Dict[str, Any]) -> None:
"""
Display success message after crew creation.
def _display_creation_success(self, json_response: dict[str, Any]) -> None:
"""Display success message after crew creation.
Args:
json_response (Dict[str, Any]): The response containing crew information.
"""
console.print("Deployment created successfully!\n", style="bold green")
console.print(
f"Name: {self.project_name} ({json_response['uuid']})", style="bold green"
f"Name: {self.project_name} ({json_response['uuid']})", style="bold green",
)
console.print(f"Status: {json_response['status']}", style="bold green")
console.print("\nTo (re)deploy the crew, run:")
@@ -167,9 +158,7 @@ class DeployCommand(BaseCommand, PlusAPIMixin):
console.print(f"crewai deploy push --uuid {json_response['uuid']}")
def list_crews(self) -> None:
"""
List all available crews.
"""
"""List all available crews."""
console.print("Listing all Crews\n", style="bold blue")
response = self.plus_api_client.list_crews()
@@ -179,31 +168,29 @@ class DeployCommand(BaseCommand, PlusAPIMixin):
else:
self._display_no_crews_message()
def _display_crews(self, crews_data: List[Dict[str, Any]]) -> None:
"""
Display the list of crews.
def _display_crews(self, crews_data: list[dict[str, Any]]) -> None:
"""Display the list of crews.
Args:
crews_data (List[Dict[str, Any]]): List of crew data to display.
"""
for crew_data in crews_data:
console.print(
f"- {crew_data['name']} ({crew_data['uuid']}) [blue]{crew_data['status']}[/blue]"
f"- {crew_data['name']} ({crew_data['uuid']}) [blue]{crew_data['status']}[/blue]",
)
def _display_no_crews_message(self) -> None:
"""
Display a message when no crews are available.
"""
"""Display a message when no crews are available."""
console.print("You don't have any Crews yet. Let's create one!", style="yellow")
console.print(" crewai create crew <crew_name>", style="green")
def get_crew_status(self, uuid: Optional[str] = None) -> None:
"""
Get the status of a crew.
def get_crew_status(self, uuid: str | None = None) -> None:
"""Get the status of a crew.
Args:
uuid (Optional[str]): The UUID of the crew to check.
"""
console.print("Fetching deployment status...", style="bold blue")
if uuid:
@@ -217,23 +204,23 @@ class DeployCommand(BaseCommand, PlusAPIMixin):
self._validate_response(response)
self._display_crew_status(response.json())
def _display_crew_status(self, status_data: Dict[str, str]) -> None:
"""
Display the status of a crew.
def _display_crew_status(self, status_data: dict[str, str]) -> None:
"""Display the status of a crew.
Args:
status_data (Dict[str, str]): The status data to display.
"""
console.print(f"Name:\t {status_data['name']}")
console.print(f"Status:\t {status_data['status']}")
def get_crew_logs(self, uuid: Optional[str], log_type: str = "deployment") -> None:
"""
Get logs for a crew.
def get_crew_logs(self, uuid: str | None, log_type: str = "deployment") -> None:
"""Get logs for a crew.
Args:
uuid (Optional[str]): The UUID of the crew to get logs for.
log_type (str): The type of logs to retrieve (default: "deployment").
"""
self._get_crew_logs_span = self._telemetry.get_crew_logs_span(uuid, log_type)
console.print(f"Fetching {log_type} logs...", style="bold blue")
@@ -249,12 +236,12 @@ class DeployCommand(BaseCommand, PlusAPIMixin):
self._validate_response(response)
self._display_logs(response.json())
def remove_crew(self, uuid: Optional[str]) -> None:
"""
Remove a crew deployment.
def remove_crew(self, uuid: str | None) -> None:
"""Remove a crew deployment.
Args:
uuid (Optional[str]): The UUID of the crew to remove.
"""
self._remove_crew_span = self._telemetry.remove_crew_span(uuid)
console.print("Removing deployment...", style="bold blue")
@@ -269,9 +256,9 @@ class DeployCommand(BaseCommand, PlusAPIMixin):
if response.status_code == 204:
console.print(
f"Crew '{self.project_name}' removed successfully.", style="green"
f"Crew '{self.project_name}' removed successfully.", style="green",
)
else:
console.print(
f"Failed to remove crew '{self.project_name}'", style="bold red"
f"Failed to remove crew '{self.project_name}'", style="bold red",
)