Format codebase with uv run pre-commit run --all-files

This commit is contained in:
James Murdza
2025-10-22 11:11:02 -07:00
parent 759ff4703e
commit ddc5a5de91
234 changed files with 10127 additions and 8467 deletions

View File

@@ -8,10 +8,11 @@
</picture>
</div>
[![Python](https://img.shields.io/badge/Python-333333?logo=python&logoColor=white&labelColor=333333)](#)
[![macOS](https://img.shields.io/badge/macOS-000000?logo=apple&logoColor=F0F0F0)](#)
[![Discord](https://img.shields.io/badge/Discord-%235865F2.svg?&logo=discord&logoColor=white)](https://discord.com/invite/mVnXXpdE85)
[![PyPI](https://img.shields.io/pypi/v/cua-core?color=333333)](https://pypi.org/project/cua-core/)
[![Python](https://img.shields.io/badge/Python-333333?logo=python&logoColor=white&labelColor=333333)](#)
[![macOS](https://img.shields.io/badge/macOS-000000?logo=apple&logoColor=F0F0F0)](#)
[![Discord](https://img.shields.io/badge/Discord-%235865F2.svg?&logo=discord&logoColor=white)](https://discord.com/invite/mVnXXpdE85)
[![PyPI](https://img.shields.io/pypi/v/cua-core?color=333333)](https://pypi.org/project/cua-core/)
</h1>
</div>
@@ -25,4 +26,4 @@
```bash
pip install cua-core
```
```

View File

@@ -4,12 +4,11 @@ It provides a low-overhead way to collect anonymous usage data.
"""
from core.telemetry.posthog import (
record_event,
is_telemetry_enabled,
destroy_telemetry_client,
is_telemetry_enabled,
record_event,
)
__all__ = [
"record_event",
"is_telemetry_enabled",

View File

@@ -4,8 +4,8 @@ from __future__ import annotations
import logging
import os
import uuid
import sys
import uuid
from pathlib import Path
from typing import Any, Dict, List, Optional
@@ -20,6 +20,7 @@ logger = logging.getLogger("core.telemetry")
PUBLIC_POSTHOG_API_KEY = "phc_eSkLnbLxsnYFaXksif1ksbrNzYlJShr35miFLDppF14"
PUBLIC_POSTHOG_HOST = "https://eu.i.posthog.com"
class PostHogTelemetryClient:
"""Collects and reports telemetry data via PostHog."""
@@ -47,7 +48,8 @@ class PostHogTelemetryClient:
# Legacy opt-out flag
os.environ.get("CUA_TELEMETRY", "").lower() != "off"
# Opt-in flag (defaults to enabled)
and os.environ.get("CUA_TELEMETRY_ENABLED", "true").lower() in { "1", "true", "yes", "on" }
and os.environ.get("CUA_TELEMETRY_ENABLED", "true").lower()
in {"1", "true", "yes", "on"}
)
def _get_or_create_installation_id(self) -> str:
@@ -150,14 +152,12 @@ class PostHogTelemetryClient:
logger.debug(
f"Setting up PostHog user properties for: {self.installation_id} with properties: {properties}"
)
# In the Python SDK, we capture an identification event instead of calling identify()
posthog.capture(
distinct_id=self.installation_id,
event="$identify",
properties={"$set": properties}
distinct_id=self.installation_id, event="$identify", properties={"$set": properties}
)
logger.info(f"Set up PostHog user properties for installation: {self.installation_id}")
except Exception as e:
logger.warning(f"Failed to set up PostHog user properties: {e}")
@@ -224,13 +224,16 @@ class PostHogTelemetryClient:
"""Destroy the global PostHogTelemetryClient instance."""
cls._singleton = None
def destroy_telemetry_client() -> None:
"""Destroy the global PostHogTelemetryClient instance (class-managed)."""
PostHogTelemetryClient.destroy_client()
def is_telemetry_enabled() -> bool:
return PostHogTelemetryClient.is_telemetry_enabled()
def record_event(event_name: str, properties: Optional[Dict[str, Any]] | None = None) -> None:
"""Record an arbitrary PostHog event."""
PostHogTelemetryClient.get_client().record_event(event_name, properties or {})
PostHogTelemetryClient.get_client().record_event(event_name, properties or {})