59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import json
|
||
|
|
from functools import lru_cache
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
from .models import PortingBacklog, PortingModule
|
||
|
|
|
||
|
|
SNAPSHOT_PATH = Path(__file__).resolve().parent / 'reference_data' / 'tools_snapshot.json'
|
||
|
|
|
||
|
|
|
||
|
|
@lru_cache(maxsize=1)
|
||
|
|
def load_tool_snapshot() -> tuple[PortingModule, ...]:
|
||
|
|
raw_entries = json.loads(SNAPSHOT_PATH.read_text())
|
||
|
|
return tuple(
|
||
|
|
PortingModule(
|
||
|
|
name=entry['name'],
|
||
|
|
responsibility=entry['responsibility'],
|
||
|
|
source_hint=entry['source_hint'],
|
||
|
|
status='mirrored',
|
||
|
|
)
|
||
|
|
for entry in raw_entries
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
PORTED_TOOLS = load_tool_snapshot()
|
||
|
|
|
||
|
|
|
||
|
|
def build_tool_backlog() -> PortingBacklog:
|
||
|
|
return PortingBacklog(title='Tool surface', modules=list(PORTED_TOOLS))
|
||
|
|
|
||
|
|
|
||
|
|
def tool_names() -> list[str]:
|
||
|
|
return [module.name for module in PORTED_TOOLS]
|
||
|
|
|
||
|
|
|
||
|
|
def get_tool(name: str) -> PortingModule | None:
|
||
|
|
needle = name.lower()
|
||
|
|
for module in PORTED_TOOLS:
|
||
|
|
if module.name.lower() == needle:
|
||
|
|
return module
|
||
|
|
return None
|
||
|
|
|
||
|
|
|
||
|
|
def find_tools(query: str, limit: int = 20) -> list[PortingModule]:
|
||
|
|
needle = query.lower()
|
||
|
|
matches = [module for module in PORTED_TOOLS if needle in module.name.lower() or needle in module.source_hint.lower()]
|
||
|
|
return matches[:limit]
|
||
|
|
|
||
|
|
|
||
|
|
def render_tool_index(limit: int = 20, query: str | None = None) -> str:
|
||
|
|
modules = find_tools(query, limit) if query else list(PORTED_TOOLS[:limit])
|
||
|
|
lines = [f'Tool entries: {len(PORTED_TOOLS)}', '']
|
||
|
|
if query:
|
||
|
|
lines.append(f'Filtered by: {query}')
|
||
|
|
lines.append('')
|
||
|
|
lines.extend(f'- {module.name} — {module.source_hint}' for module in modules)
|
||
|
|
return '\n'.join(lines)
|