context.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from __future__ import annotations
  2. from dataclasses import dataclass
  3. from pathlib import Path
  4. @dataclass(frozen=True)
  5. class PortContext:
  6. source_root: Path
  7. tests_root: Path
  8. assets_root: Path
  9. archive_root: Path
  10. python_file_count: int
  11. test_file_count: int
  12. asset_file_count: int
  13. archive_available: bool
  14. def build_port_context(base: Path | None = None) -> PortContext:
  15. root = base or Path(__file__).resolve().parent.parent
  16. source_root = root / 'src'
  17. tests_root = root / 'tests'
  18. assets_root = root / 'assets'
  19. archive_root = root / 'archive' / 'claude_code_ts_snapshot' / 'src'
  20. return PortContext(
  21. source_root=source_root,
  22. tests_root=tests_root,
  23. assets_root=assets_root,
  24. archive_root=archive_root,
  25. python_file_count=sum(1 for path in source_root.rglob('*.py') if path.is_file()),
  26. test_file_count=sum(1 for path in tests_root.rglob('*.py') if path.is_file()),
  27. asset_file_count=sum(1 for path in assets_root.rglob('*') if path.is_file()),
  28. archive_available=archive_root.exists(),
  29. )
  30. def render_context(context: PortContext) -> str:
  31. return '\n'.join([
  32. f'Source root: {context.source_root}',
  33. f'Test root: {context.tests_root}',
  34. f'Assets root: {context.assets_root}',
  35. f'Archive root: {context.archive_root}',
  36. f'Python files: {context.python_file_count}',
  37. f'Test files: {context.test_file_count}',
  38. f'Assets: {context.asset_file_count}',
  39. f'Archive available: {context.archive_available}',
  40. ])