diff --git a/src/crewai/cli/templates/crew/crew.py b/src/crewai/cli/templates/crew/crew.py index 383bfac48..05cfca603 100644 --- a/src/crewai/cli/templates/crew/crew.py +++ b/src/crewai/cli/templates/crew/crew.py @@ -6,7 +6,7 @@ from crewai.project import CrewBase, agent, crew, task # https://docs.crewai.com/concepts/crews#example-crew-class-with-decorators @CrewBase -class {{crew_name}}(): +class {{crew_name}}: """{{crew_name}} crew""" # Learn more about YAML configuration files here: diff --git a/src/crewai/cli/templates/crew/tools/custom_tool.py b/src/crewai/cli/templates/crew/tools/custom_tool.py index 154beae8e..d4e072c60 100644 --- a/src/crewai/cli/templates/crew/tools/custom_tool.py +++ b/src/crewai/cli/templates/crew/tools/custom_tool.py @@ -1,5 +1,4 @@ from crewai.tools import BaseTool -from typing import Type from pydantic import BaseModel, Field @@ -7,12 +6,13 @@ class MyCustomToolInput(BaseModel): """Input schema for MyCustomTool.""" argument: str = Field(..., description="Description of the argument.") + class MyCustomTool(BaseTool): name: str = "Name of my tool" description: str = ( "Clear description for what this tool is useful for, your agent will need this information to use it." ) - args_schema: Type[BaseModel] = MyCustomToolInput + args_schema: type[BaseModel] = MyCustomToolInput def _run(self, argument: str) -> str: # Implementation goes here diff --git a/src/crewai/cli/templates/flow/crews/poem_crew/poem_crew.py b/src/crewai/cli/templates/flow/crews/poem_crew/poem_crew.py index 5e978d985..a0a309f5a 100644 --- a/src/crewai/cli/templates/flow/crews/poem_crew/poem_crew.py +++ b/src/crewai/cli/templates/flow/crews/poem_crew/poem_crew.py @@ -16,7 +16,7 @@ class PoemCrew: agents_config = "config/agents.yaml" tasks_config = "config/tasks.yaml" - # If you would lik to add tools to your crew, you can learn more about it here: + # If you would like to add tools to your crew, you can learn more about it here: # https://docs.crewai.com/concepts/agents#agent-tools @agent def poem_writer(self) -> Agent: diff --git a/src/crewai/cli/templates/flow/tools/custom_tool.py b/src/crewai/cli/templates/flow/tools/custom_tool.py index 718d2be1b..ec9fd9cd1 100644 --- a/src/crewai/cli/templates/flow/tools/custom_tool.py +++ b/src/crewai/cli/templates/flow/tools/custom_tool.py @@ -1,5 +1,3 @@ -from typing import Type - from crewai.tools import BaseTool from pydantic import BaseModel, Field @@ -15,7 +13,7 @@ class MyCustomTool(BaseTool): description: str = ( "Clear description for what this tool is useful for, your agent will need this information to use it." ) - args_schema: Type[BaseModel] = MyCustomToolInput + args_schema: type[BaseModel] = MyCustomToolInput def _run(self, argument: str) -> str: # Implementation goes here diff --git a/tests/test_project_formatting.py b/tests/test_project_formatting.py new file mode 100644 index 000000000..e9f5ebc37 --- /dev/null +++ b/tests/test_project_formatting.py @@ -0,0 +1,54 @@ +import os +import shutil +import subprocess +import tempfile +from pathlib import Path + +import pytest + +from crewai.cli.create_crew import create_crew + + +@pytest.fixture +def temp_dir(): + """Create a temporary directory for testing.""" + temp_dir = tempfile.mkdtemp() + yield temp_dir + shutil.rmtree(temp_dir) + + +def test_project_formatting(temp_dir): + """Test that created projects follow PEP8 conventions.""" + # Change to the temporary directory + original_dir = os.getcwd() + os.chdir(temp_dir) + + try: + # Create a new crew project + create_crew("test_crew", skip_provider=True) + + # Create a ruff configuration file + ruff_config = """ +line-length = 120 +target-version = "py310" +select = ["E", "F", "I", "UP", "A"] +ignore = ["D203"] +""" + with open(Path(temp_dir) / "test_crew" / ".ruff.toml", "w") as f: + f.write(ruff_config) + + # Run ruff on the generated project code + result = subprocess.run( + ["ruff", "check", "test_crew"], + capture_output=True, + text=True, + ) + + # Check that there are no linting errors + assert result.returncode == 0, f"Ruff found issues: {result.stdout}" + # If ruff reports "All checks passed!" or empty output, that's good + assert "All checks passed!" in result.stdout or not result.stdout.strip(), f"Ruff found issues: {result.stdout}" + + finally: + # Change back to the original directory + os.chdir(original_dir)