From 9b536340c79ace46ef752c1410b5a2ebf4c19741 Mon Sep 17 00:00:00 2001 From: Thiago Moretto Date: Wed, 25 Mar 2026 20:25:24 -0300 Subject: [PATCH] style: fix ruff formatting --- lib/crewai/src/crewai/cli/plus_api.py | 4 ++- lib/crewai/src/crewai/cli/tools/main.py | 26 ++++++++++---- lib/crewai/src/crewai/cli/utils.py | 46 ++++++++++++++++--------- 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/lib/crewai/src/crewai/cli/plus_api.py b/lib/crewai/src/crewai/cli/plus_api.py index 1bfa59fd9..b167c48aa 100644 --- a/lib/crewai/src/crewai/cli/plus_api.py +++ b/lib/crewai/src/crewai/cli/plus_api.py @@ -82,7 +82,9 @@ class PlusAPI: "file": encoded_file, "description": description, "available_exports": available_exports, - "tools_metadata": {"package": handle, "tools": tools_metadata} if tools_metadata else None, + "tools_metadata": {"package": handle, "tools": tools_metadata} + if tools_metadata + else None, } return self._make_request("POST", f"{self.TOOLS_RESOURCE}", json=params) diff --git a/lib/crewai/src/crewai/cli/tools/main.py b/lib/crewai/src/crewai/cli/tools/main.py index 0228518c7..72c1e6e25 100644 --- a/lib/crewai/src/crewai/cli/tools/main.py +++ b/lib/crewai/src/crewai/cli/tools/main.py @@ -265,14 +265,18 @@ class ToolCommand(BaseCommand, PlusAPIMixin): console.print("[yellow]No tool metadata extracted.[/yellow]") return - console.print(f"\n[bold]Tools to be published ({len(tools_metadata)}):[/bold]\n") + console.print( + f"\n[bold]Tools to be published ({len(tools_metadata)}):[/bold]\n" + ) for tool in tools_metadata: console.print(f" [bold cyan]{tool.get('name', 'Unknown')}[/bold cyan]") if tool.get("module"): console.print(f" Module: {tool.get('module')}") console.print(f" Name: {tool.get('humanized_name', 'N/A')}") - console.print(f" Description: {tool.get('description', 'N/A')[:80]}{'...' if len(tool.get('description', '')) > 80 else ''}") + console.print( + f" Description: {tool.get('description', 'N/A')[:80]}{'...' if len(tool.get('description', '')) > 80 else ''}" + ) init_params = tool.get("init_params_schema", {}).get("properties", {}) if init_params: @@ -282,16 +286,26 @@ class ToolCommand(BaseCommand, PlusAPIMixin): param_type = param_info.get("type", "any") is_required = param_name in required req_marker = "[red]*[/red]" if is_required else "" - default = f" = {param_info['default']}" if "default" in param_info else "" - console.print(f" - {param_name}: {param_type}{default} {req_marker}") + default = ( + f" = {param_info['default']}" if "default" in param_info else "" + ) + console.print( + f" - {param_name}: {param_type}{default} {req_marker}" + ) env_vars = tool.get("env_vars", []) if env_vars: console.print(" Environment variables:") for env_var in env_vars: req_marker = "[red]*[/red]" if env_var.get("required") else "" - default = f" (default: {env_var['default']})" if env_var.get("default") else "" - console.print(f" - {env_var['name']}: {env_var.get('description', 'N/A')}{default} {req_marker}") + default = ( + f" (default: {env_var['default']})" + if env_var.get("default") + else "" + ) + console.print( + f" - {env_var['name']}: {env_var.get('description', 'N/A')}{default} {req_marker}" + ) console.print() diff --git a/lib/crewai/src/crewai/cli/utils.py b/lib/crewai/src/crewai/cli/utils.py index 87ebc8775..9188d63d3 100644 --- a/lib/crewai/src/crewai/cli/utils.py +++ b/lib/crewai/src/crewai/cli/utils.py @@ -556,7 +556,9 @@ def _load_module_from_file(init_file: Path, module_name: str | None = None): Yields the loaded module or None if loading fails. """ if module_name is None: - module_name = f"temp_module_{hashlib.sha256(str(init_file).encode()).hexdigest()[:8]}" + module_name = ( + f"temp_module_{hashlib.sha256(str(init_file).encode()).hexdigest()[:8]}" + ) spec = importlib.util.spec_from_file_location(module_name, init_file) if not spec or not spec.loader: @@ -670,7 +672,9 @@ def _extract_tool_metadata_from_init(init_file: Path) -> list[dict[str, Any]]: tools_metadata = [] for name in exported_names: obj = getattr(module, name, None) - if obj is None or not (inspect.isclass(obj) and issubclass(obj, BaseTool)): + if obj is None or not ( + inspect.isclass(obj) and issubclass(obj, BaseTool) + ): continue if tool_info := _extract_single_tool_metadata(obj): tools_metadata.append(tool_info) @@ -762,7 +766,9 @@ def _get_schema_generator() -> type: return SchemaGenerator -def _extract_run_params_schema(args_schema_field: dict[str, Any] | None) -> dict[str, Any]: +def _extract_run_params_schema( + args_schema_field: dict[str, Any] | None, +) -> dict[str, Any]: """ Extract JSON Schema for the tool's run parameters from args_schema field. """ @@ -772,27 +778,33 @@ def _extract_run_params_schema(args_schema_field: dict[str, Any] | None) -> dict return {} args_schema_class = args_schema_field.get("schema", {}).get("default") - if not (inspect.isclass(args_schema_class) and issubclass(args_schema_class, BaseModel)): + if not ( + inspect.isclass(args_schema_class) and issubclass(args_schema_class, BaseModel) + ): return {} try: - return args_schema_class.model_json_schema(schema_generator=_get_schema_generator()) + return args_schema_class.model_json_schema( + schema_generator=_get_schema_generator() + ) except Exception: return {} -_IGNORED_INIT_PARAMS = frozenset({ - "name", - "description", - "env_vars", - "args_schema", - "description_updated", - "cache_function", - "result_as_answer", - "max_usage_count", - "current_usage_count", - "package_dependencies", -}) +_IGNORED_INIT_PARAMS = frozenset( + { + "name", + "description", + "env_vars", + "args_schema", + "description_updated", + "cache_function", + "result_as_answer", + "max_usage_count", + "current_usage_count", + "package_dependencies", + } +) def _extract_init_params_schema(tool_class: type) -> dict[str, Any]: