mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-06 01:32:36 +00:00
chore(core): address bot findings on extraction follow-up
- Add __all__ to all re-export shims (crewai.{settings,constants,utilities.{
version,paths,printer,lock_store,constants,project_utils},auth.token_manager,
events.utils.console_formatter}, crewai_cli.{config,shared.token_manager},
crewai_cli.utils) to silence CodeQL "unused import" findings — the imports
are the module's public API.
- Migrate three CLI internal callers (cli.py, authentication/main.py,
authentication/token.py) off the deprecated crewai_cli.shared.token_manager
shim, importing crewai_core.token_manager directly. Avoids a self-imposed
DeprecationWarning on every CLI startup.
- Add Telemetry._safe_telemetry_procedure for void operations; switch the
CLI-facing span methods (deploy/template/flow_creation/signup, _add_attribute)
off _safe_telemetry_operation since they don't return a span.
- Delete unused crewai_cli.utils.update_env_vars (had a latent type-cast bug
and zero callers).
This commit is contained in:
@@ -2,13 +2,13 @@ import time
|
||||
from typing import TYPE_CHECKING, Any, TypeVar, cast
|
||||
import webbrowser
|
||||
|
||||
from crewai_core.token_manager import TokenManager
|
||||
import httpx
|
||||
from pydantic import BaseModel, Field
|
||||
from rich.console import Console
|
||||
|
||||
from crewai_cli.authentication.utils import validate_jwt_token
|
||||
from crewai_cli.config import Settings
|
||||
from crewai_cli.shared.token_manager import TokenManager
|
||||
|
||||
|
||||
console = Console()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from crewai_cli.shared.token_manager import TokenManager
|
||||
from crewai_core.token_manager import TokenManager
|
||||
|
||||
|
||||
class AuthError(Exception):
|
||||
|
||||
@@ -6,6 +6,7 @@ import subprocess
|
||||
from typing import Any
|
||||
|
||||
import click
|
||||
from crewai_core.token_manager import TokenManager
|
||||
|
||||
from crewai_cli.add_crew_to_flow import add_crew_to_flow
|
||||
from crewai_cli.authentication.main import AuthenticationCommand
|
||||
@@ -25,7 +26,6 @@ from crewai_cli.replay_from_task import replay_task_command
|
||||
from crewai_cli.reset_memories_command import reset_memories_command
|
||||
from crewai_cli.run_crew import run_crew
|
||||
from crewai_cli.settings.main import SettingsCommand
|
||||
from crewai_cli.shared.token_manager import TokenManager
|
||||
from crewai_cli.task_outputs import load_task_outputs
|
||||
from crewai_cli.tools.main import ToolCommand
|
||||
from crewai_cli.train_crew import train_crew
|
||||
|
||||
@@ -16,3 +16,15 @@ from crewai_core.settings import (
|
||||
Settings as Settings,
|
||||
get_writable_config_path as get_writable_config_path,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"CLI_SETTINGS_KEYS",
|
||||
"DEFAULT_CLI_SETTINGS",
|
||||
"DEFAULT_CONFIG_PATH",
|
||||
"HIDDEN_SETTINGS_KEYS",
|
||||
"READONLY_SETTINGS_KEYS",
|
||||
"USER_SETTINGS_KEYS",
|
||||
"Settings",
|
||||
"get_writable_config_path",
|
||||
]
|
||||
|
||||
@@ -7,6 +7,9 @@ import warnings
|
||||
from crewai_core.token_manager import TokenManager as TokenManager
|
||||
|
||||
|
||||
__all__ = ["TokenManager"]
|
||||
|
||||
|
||||
warnings.warn(
|
||||
"crewai_cli.shared.token_manager is deprecated; "
|
||||
"import from crewai_core.token_manager.",
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
from typing import Any, cast
|
||||
from typing import Any
|
||||
|
||||
import click
|
||||
from crewai_core.project import (
|
||||
@@ -21,7 +21,22 @@ from crewai_core.tool_credentials import (
|
||||
)
|
||||
from rich.console import Console
|
||||
|
||||
from crewai_cli.constants import ENV_VARS
|
||||
|
||||
__all__ = [
|
||||
"build_env_with_all_tool_credentials",
|
||||
"build_env_with_tool_repository_credentials",
|
||||
"copy_template",
|
||||
"fetch_and_json_env_file",
|
||||
"get_project_description",
|
||||
"get_project_name",
|
||||
"get_project_version",
|
||||
"load_env_vars",
|
||||
"parse_toml",
|
||||
"read_toml",
|
||||
"tree_copy",
|
||||
"tree_find_and_replace",
|
||||
"write_env_file",
|
||||
]
|
||||
|
||||
|
||||
console = Console()
|
||||
@@ -116,41 +131,6 @@ def load_env_vars(folder_path: Path) -> dict[str, Any]:
|
||||
return env_vars
|
||||
|
||||
|
||||
def update_env_vars(
|
||||
env_vars: dict[str, Any], provider: str, model: str
|
||||
) -> dict[str, Any] | None:
|
||||
"""Updates environment variables with the API key for the selected provider and model."""
|
||||
provider_config = cast(
|
||||
list[str],
|
||||
ENV_VARS.get(
|
||||
provider,
|
||||
[
|
||||
click.prompt(
|
||||
f"Enter the environment variable name for your {provider.capitalize()} API key",
|
||||
type=str,
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
api_key_var = provider_config[0]
|
||||
|
||||
if api_key_var not in env_vars:
|
||||
try:
|
||||
env_vars[api_key_var] = click.prompt(
|
||||
f"Enter your {provider.capitalize()} API key", type=str, hide_input=True
|
||||
)
|
||||
except click.exceptions.Abort:
|
||||
click.secho("Operation aborted by the user.", fg="red")
|
||||
return None
|
||||
else:
|
||||
click.secho(f"API key already exists for {provider.capitalize()}.", fg="yellow")
|
||||
|
||||
env_vars["MODEL"] = model
|
||||
click.secho(f"Selected model: {model}", fg="green")
|
||||
return env_vars
|
||||
|
||||
|
||||
def write_env_file(folder_path: Path, env_vars: dict[str, Any]) -> None:
|
||||
"""Writes environment variables to a .env file in the specified folder."""
|
||||
env_file_path = folder_path / ".env"
|
||||
|
||||
@@ -159,6 +159,7 @@ class Telemetry:
|
||||
def _safe_telemetry_operation(
|
||||
self, operation: Callable[[], Span | None]
|
||||
) -> Span | None:
|
||||
"""Run a span-returning telemetry operation, swallowing failures."""
|
||||
if not self._should_execute_telemetry():
|
||||
return None
|
||||
try:
|
||||
@@ -167,14 +168,23 @@ class Telemetry:
|
||||
logger.debug("Telemetry operation failed: %s", e)
|
||||
return None
|
||||
|
||||
def _safe_telemetry_procedure(self, operation: Callable[[], None]) -> None:
|
||||
"""Run a void telemetry procedure, swallowing failures."""
|
||||
if not self._should_execute_telemetry():
|
||||
return
|
||||
try:
|
||||
operation()
|
||||
except Exception as e:
|
||||
logger.debug("Telemetry operation failed: %s", e)
|
||||
|
||||
def _add_attribute(self, span: Span | None, key: str, value: Any) -> None:
|
||||
if span is None:
|
||||
return
|
||||
|
||||
def _operation() -> None:
|
||||
return span.set_attribute(key, value)
|
||||
span.set_attribute(key, value)
|
||||
|
||||
self._safe_telemetry_operation(_operation)
|
||||
self._safe_telemetry_procedure(_operation)
|
||||
|
||||
# --- CLI-facing spans ---------------------------------------------------
|
||||
|
||||
@@ -186,7 +196,7 @@ class Telemetry:
|
||||
span = tracer.start_span("Deploy Signup Error")
|
||||
close_span(span)
|
||||
|
||||
self._safe_telemetry_operation(_operation)
|
||||
self._safe_telemetry_procedure(_operation)
|
||||
|
||||
def start_deployment_span(self, uuid: str | None = None) -> None:
|
||||
"""Records the start of a deployment process."""
|
||||
@@ -198,7 +208,7 @@ class Telemetry:
|
||||
self._add_attribute(span, "uuid", uuid)
|
||||
close_span(span)
|
||||
|
||||
self._safe_telemetry_operation(_operation)
|
||||
self._safe_telemetry_procedure(_operation)
|
||||
|
||||
def create_crew_deployment_span(self) -> None:
|
||||
"""Records the creation of a new crew deployment."""
|
||||
@@ -208,7 +218,7 @@ class Telemetry:
|
||||
span = tracer.start_span("Create Crew Deployment")
|
||||
close_span(span)
|
||||
|
||||
self._safe_telemetry_operation(_operation)
|
||||
self._safe_telemetry_procedure(_operation)
|
||||
|
||||
def get_crew_logs_span(
|
||||
self, uuid: str | None, log_type: str = "deployment"
|
||||
@@ -223,7 +233,7 @@ class Telemetry:
|
||||
self._add_attribute(span, "uuid", uuid)
|
||||
close_span(span)
|
||||
|
||||
self._safe_telemetry_operation(_operation)
|
||||
self._safe_telemetry_procedure(_operation)
|
||||
|
||||
def remove_crew_span(self, uuid: str | None = None) -> None:
|
||||
"""Records the removal of a crew."""
|
||||
@@ -235,7 +245,7 @@ class Telemetry:
|
||||
self._add_attribute(span, "uuid", uuid)
|
||||
close_span(span)
|
||||
|
||||
self._safe_telemetry_operation(_operation)
|
||||
self._safe_telemetry_procedure(_operation)
|
||||
|
||||
def flow_creation_span(self, flow_name: str) -> None:
|
||||
"""Records the creation of a new flow."""
|
||||
@@ -246,7 +256,7 @@ class Telemetry:
|
||||
self._add_attribute(span, "flow_name", flow_name)
|
||||
close_span(span)
|
||||
|
||||
self._safe_telemetry_operation(_operation)
|
||||
self._safe_telemetry_procedure(_operation)
|
||||
|
||||
def template_installed_span(self, template_name: str) -> None:
|
||||
"""Records when a template is downloaded and installed."""
|
||||
@@ -259,4 +269,4 @@ class Telemetry:
|
||||
self._add_attribute(span, "template_name", template_name)
|
||||
close_span(span)
|
||||
|
||||
self._safe_telemetry_operation(_operation)
|
||||
self._safe_telemetry_procedure(_operation)
|
||||
|
||||
@@ -7,6 +7,9 @@ import warnings
|
||||
from crewai_core.token_manager import TokenManager as TokenManager
|
||||
|
||||
|
||||
__all__ = ["TokenManager"]
|
||||
|
||||
|
||||
warnings.warn(
|
||||
"crewai.auth.token_manager is deprecated; import from crewai_core.token_manager.",
|
||||
DeprecationWarning,
|
||||
|
||||
@@ -11,6 +11,21 @@ from crewai_core.constants import (
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"CREWAI_ENTERPRISE_DEFAULT_OAUTH2_AUDIENCE",
|
||||
"CREWAI_ENTERPRISE_DEFAULT_OAUTH2_CLIENT_ID",
|
||||
"CREWAI_ENTERPRISE_DEFAULT_OAUTH2_DOMAIN",
|
||||
"CREWAI_ENTERPRISE_DEFAULT_OAUTH2_PROVIDER",
|
||||
"DEFAULT_CREWAI_ENTERPRISE_URL",
|
||||
"DEFAULT_LLM_MODEL",
|
||||
"ENV_VARS",
|
||||
"JSON_URL",
|
||||
"LITELLM_PARAMS",
|
||||
"MODELS",
|
||||
"PROVIDERS",
|
||||
]
|
||||
|
||||
|
||||
ENV_VARS: dict[str, list[dict[str, Any]]] = {
|
||||
"openai": [
|
||||
{
|
||||
|
||||
@@ -15,6 +15,13 @@ from rich.text import Text
|
||||
from crewai.version import is_current_version_yanked, is_newer_version_available
|
||||
|
||||
|
||||
__all__ = [
|
||||
"ConsoleFormatter",
|
||||
"set_suppress_console_output",
|
||||
"should_suppress_console_output",
|
||||
]
|
||||
|
||||
|
||||
_disable_version_check: ContextVar[bool] = ContextVar(
|
||||
"_disable_version_check", default=False
|
||||
)
|
||||
|
||||
@@ -16,3 +16,15 @@ from crewai_core.settings import (
|
||||
Settings as Settings,
|
||||
get_writable_config_path as get_writable_config_path,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"CLI_SETTINGS_KEYS",
|
||||
"DEFAULT_CLI_SETTINGS",
|
||||
"DEFAULT_CONFIG_PATH",
|
||||
"HIDDEN_SETTINGS_KEYS",
|
||||
"READONLY_SETTINGS_KEYS",
|
||||
"USER_SETTINGS_KEYS",
|
||||
"Settings",
|
||||
"get_writable_config_path",
|
||||
]
|
||||
|
||||
@@ -11,6 +11,20 @@ from crewai_core.printer import PrinterColor
|
||||
from pydantic_core import CoreSchema
|
||||
|
||||
|
||||
__all__ = [
|
||||
"CC_ENV_VAR",
|
||||
"CODEX_ENV_VARS",
|
||||
"CREWAI_TRAINED_AGENTS_FILE_ENV",
|
||||
"CURSOR_ENV_VARS",
|
||||
"EMITTER_COLOR",
|
||||
"KNOWLEDGE_DIRECTORY",
|
||||
"MAX_FILE_NAME_LENGTH",
|
||||
"NOT_SPECIFIED",
|
||||
"TRAINED_AGENTS_DATA_FILE",
|
||||
"TRAINING_DATA_FILE",
|
||||
]
|
||||
|
||||
|
||||
EMITTER_COLOR: Final[PrinterColor] = "bold_blue"
|
||||
CC_ENV_VAR: Final[str] = "CLAUDECODE"
|
||||
CODEX_ENV_VARS: Final[tuple[str, ...]] = (
|
||||
|
||||
@@ -7,6 +7,9 @@ import warnings
|
||||
from crewai_core.lock_store import lock as lock
|
||||
|
||||
|
||||
__all__ = ["lock"]
|
||||
|
||||
|
||||
warnings.warn(
|
||||
"crewai.utilities.lock_store is deprecated; import from crewai_core.lock_store.",
|
||||
DeprecationWarning,
|
||||
|
||||
@@ -10,6 +10,9 @@ from crewai_core.paths import (
|
||||
)
|
||||
|
||||
|
||||
__all__ = ["db_storage_path", "get_project_directory_name"]
|
||||
|
||||
|
||||
warnings.warn(
|
||||
"crewai.utilities.paths is deprecated; import from crewai_core.paths.",
|
||||
DeprecationWarning,
|
||||
|
||||
@@ -12,6 +12,9 @@ from crewai_core.printer import (
|
||||
)
|
||||
|
||||
|
||||
__all__ = ["PRINTER", "ColoredText", "Printer", "PrinterColor"]
|
||||
|
||||
|
||||
warnings.warn(
|
||||
"crewai.utilities.printer is deprecated; import from crewai_core.printer.",
|
||||
DeprecationWarning,
|
||||
|
||||
@@ -32,6 +32,25 @@ from crewai.crew import Crew
|
||||
from crewai.flow import Flow
|
||||
|
||||
|
||||
__all__ = [
|
||||
"build_env_with_all_tool_credentials",
|
||||
"build_env_with_tool_repository_credentials",
|
||||
"extract_available_exports",
|
||||
"extract_tools_metadata",
|
||||
"fetch_crews",
|
||||
"get_crew_instance",
|
||||
"get_crews",
|
||||
"get_flow_instance",
|
||||
"get_flows",
|
||||
"get_project_description",
|
||||
"get_project_name",
|
||||
"get_project_version",
|
||||
"is_valid_tool",
|
||||
"parse_toml",
|
||||
"read_toml",
|
||||
]
|
||||
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ import warnings
|
||||
from crewai_core.version import get_crewai_version as get_crewai_version
|
||||
|
||||
|
||||
__all__ = ["get_crewai_version"]
|
||||
|
||||
|
||||
warnings.warn(
|
||||
"crewai.utilities.version is deprecated; import from crewai_core.version.",
|
||||
DeprecationWarning,
|
||||
|
||||
Reference in New Issue
Block a user