hass.tibber_prices/scripts/clean
Julian Pawlowski 503075c443 refactor(config_flow): restructure package to satisfy hassfest validation
Home Assistant's hassfest validation requires config flows to be defined
in a file named config_flow.py (not a package directory).

Changes:
- Renamed custom_components/tibber_prices/config_flow/ → config_flow_handlers/
- Created config_flow.py as bridge file re-exporting from config_flow_handlers/
- Updated all import paths across 5 files (user_flow, options_flow, subentry_flow, etc.)
- Added ./scripts/hassfest for local validation (JSON/Python syntax, required files)
- Added ./scripts/clean with three modes (--minimal, normal, --deep)
- Refactored develop/lint/lint-check to use centralized cleanup (DRY principle)
- Updated documentation in AGENTS.md and docs/development/

Technical details:
- Bridge file uses __all__ exports to maintain clean public API
- hassfest script uses ast.parse() for syntax validation (no disk artifacts)
- clean --minimal removes .egg-info only (silent, for automated scripts)
- Dual pip/uv pip compatibility for package uninstallation

Impact: Integration now passes hassfest validation. Local validation available
via ./scripts/hassfest before pushing to GitHub. Cleanup logic centralized and
DRY across all development scripts.
2025-11-15 17:40:53 +00:00

89 lines
2.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# script/clean: Clean up development artifacts and caches
# Usage:
# ./scripts/clean # Standard cleanup (recommended)
# ./scripts/clean --deep # Also remove __pycache__
# ./scripts/clean --minimal # Only critical issues (.egg-info)
set -e
cd "$(dirname "$0")/.."
MINIMAL_MODE=false
DEEP_MODE=false
if [ "$1" = "--minimal" ]; then
MINIMAL_MODE=true
elif [ "$1" = "--deep" ]; then
DEEP_MODE=true
fi
if [ "$MINIMAL_MODE" = false ]; then
echo "==> Cleaning development artifacts..."
fi
# Clean up accidental package installation (always, even in minimal mode)
if [ -d "tibber_prices.egg-info" ]; then
if [ "$MINIMAL_MODE" = false ]; then
echo " → Removing tibber_prices.egg-info"
fi
rm -rf tibber_prices.egg-info
fi
# Uninstall if accidentally installed (always, even in minimal mode)
# Try both pip and uv pip for maximum compatibility
PACKAGE_INSTALLED=false
if pip show tibber_prices >/dev/null 2>&1 || uv pip show tibber_prices >/dev/null 2>&1; then
PACKAGE_INSTALLED=true
if [ "$MINIMAL_MODE" = false ]; then
echo " → Uninstalling accidentally installed package"
fi
# Use regular pip (cleaner output, always works in venv)
pip uninstall -y tibber_prices >/dev/null 2>&1 || true
# Also try uv pip as fallback
uv pip uninstall tibber_prices >/dev/null 2>&1 || true
fi
# Exit early if minimal mode
if [ "$MINIMAL_MODE" = true ]; then
exit 0
fi
# Clean pytest cache
if [ -d ".pytest_cache" ]; then
echo " → Removing .pytest_cache"
rm -rf .pytest_cache
fi
# Clean coverage files
if [ -f ".coverage" ]; then
echo " → Removing .coverage"
rm -f .coverage
fi
if [ -f "coverage.xml" ]; then
echo " → Removing coverage.xml"
rm -f coverage.xml
fi
# Clean ruff cache
if [ -d ".ruff_cache" ]; then
echo " → Removing .ruff_cache"
rm -rf .ruff_cache
fi
# Optional: Clean __pycache__ (normally not needed, but useful for troubleshooting)
if [ "$DEEP_MODE" = true ]; then
echo " → Deep clean: Removing all __pycache__ directories"
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
echo " → Deep clean: Removing all .pyc files"
find . -type f -name "*.pyc" -delete 2>/dev/null || true
fi
echo ""
echo "==> Cleanup complete!"
if [ "$DEEP_MODE" = false ]; then
echo ""
echo "Tip: Use './scripts/clean --deep' to also remove __pycache__ directories"
echo " (normally not needed - __pycache__ speeds up Home Assistant startup)"
fi