Ensure PlatformIO packages are installed via daemon. Enhanced with banner-style logging and typed message protocol. Args: project_dir: PlatformIO project directory environment: PlatformIO environment name (or None for all) timeout: Maximum wait time in seconds (defa
(
project_dir: Path,
environment: str | None,
timeout: int = 1800,
)
| 218 | |
| 219 | |
| 220 | def ensure_packages_installed( |
| 221 | project_dir: Path, |
| 222 | environment: str | None, |
| 223 | timeout: int = 1800, |
| 224 | ) -> bool: |
| 225 | """Ensure PlatformIO packages are installed via daemon. |
| 226 | |
| 227 | Enhanced with banner-style logging and typed message protocol. |
| 228 | |
| 229 | Args: |
| 230 | project_dir: PlatformIO project directory |
| 231 | environment: PlatformIO environment name (or None for all) |
| 232 | timeout: Maximum wait time in seconds (default: 30 minutes) |
| 233 | |
| 234 | Returns: |
| 235 | True if packages installed successfully, False otherwise |
| 236 | """ |
| 237 | # Detect default environment if None (for package validation) |
| 238 | default_env = environment |
| 239 | if default_env is None: |
| 240 | from ci.util.pio_package_daemon import get_default_environment |
| 241 | |
| 242 | default_env = get_default_environment(str(project_dir)) |
| 243 | if default_env: |
| 244 | environment = default_env # Use detected default for display |
| 245 | |
| 246 | # ═══════════════════════════════════════════════════════════ |
| 247 | # PHASE BANNER |
| 248 | # ═══════════════════════════════════════════════════════════ |
| 249 | print_phase_banner( |
| 250 | "PHASE 0: PACKAGE INSTALLATION", |
| 251 | details={ |
| 252 | "Project": str(project_dir), |
| 253 | "Environment": environment or "default", |
| 254 | "Caller PID": str(os.getpid()), |
| 255 | }, |
| 256 | ) |
| 257 | |
| 258 | # ─────────────────────────────────────────────────────────── |
| 259 | # PRE-FLIGHT CHECK |
| 260 | # ─────────────────────────────────────────────────────────── |
| 261 | # Quick check: are packages already installed? |
| 262 | if packages_already_installed(project_dir, environment): |
| 263 | # Additional validation check for corrupted packages |
| 264 | if default_env: |
| 265 | is_valid, errors = check_all_packages(project_dir, default_env) |
| 266 | if not is_valid: |
| 267 | print_tree_status( |
| 268 | "🔍 Checking packages...", |
| 269 | [ |
| 270 | ("", "Validating integrity...", None), |
| 271 | ("", f"❌ Corrupted: {errors[0]}", "error"), |
| 272 | ("", "📦 Reinstallation required", None), |
| 273 | ], |
| 274 | ) |
| 275 | # Fall through to daemon installation |
| 276 | else: |
| 277 | print_tree_status( |
no test coverage detected