(args: list[str])
| 640 | |
| 641 | |
| 642 | def _cmd_doctor(args: list[str]) -> None: |
| 643 | import asyncio |
| 644 | from uncommon_route.providers import load_providers |
| 645 | |
| 646 | checks: list[tuple[str, str, str]] = [] |
| 647 | |
| 648 | # Python version |
| 649 | vi = sys.version_info |
| 650 | python_ok = vi >= (3, 11) |
| 651 | checks.append(("Python version", "ok" if python_ok else "fail", f"{vi.major}.{vi.minor}.{vi.micro}")) |
| 652 | |
| 653 | connection = resolve_primary_connection(store=ConnectionsStore()) |
| 654 | upstream = connection.upstream |
| 655 | |
| 656 | def _upstream_is_local(url: str) -> bool: |
| 657 | host = (urlparse(url).hostname or "").lower() |
| 658 | return host in {"localhost", "127.0.0.1", "0.0.0.0", "::1"} |
| 659 | |
| 660 | def _local_proxy_no_proxy_warning() -> str | None: |
| 661 | local_targets = [ |
| 662 | os.environ.get("ANTHROPIC_BASE_URL", ""), |
| 663 | os.environ.get("OPENAI_BASE_URL", ""), |
| 664 | ] |
| 665 | if upstream: |
| 666 | local_targets.append(upstream) |
| 667 | if not any(target and _upstream_is_local(target) for target in local_targets): |
| 668 | return None |
| 669 | |
| 670 | proxy_values = [ |
| 671 | os.environ.get("http_proxy", ""), |
| 672 | os.environ.get("HTTP_PROXY", ""), |
| 673 | os.environ.get("https_proxy", ""), |
| 674 | os.environ.get("HTTPS_PROXY", ""), |
| 675 | ] |
| 676 | if not any(proxy_values): |
| 677 | return None |
| 678 | |
| 679 | no_proxy = os.environ.get("NO_PROXY") or os.environ.get("no_proxy") or "" |
| 680 | tokens = {item.strip().lower() for item in no_proxy.split(",") if item.strip()} |
| 681 | required = {"localhost", "127.0.0.1", "::1"} |
| 682 | missing = sorted(required - tokens) |
| 683 | if not missing: |
| 684 | return None |
| 685 | |
| 686 | missing_text = ", ".join(missing) |
| 687 | return f"proxy env is set; add NO_PROXY for local proxy access ({missing_text})" |
| 688 | |
| 689 | api_key = connection.api_key |
| 690 | providers = load_providers() |
| 691 | has_byok = bool(providers.providers) |
| 692 | local_upstream = bool(upstream) and _upstream_is_local(upstream) |
| 693 | primary_ready = bool(upstream) and (bool(api_key) or local_upstream) |
| 694 | |
| 695 | if primary_ready: |
| 696 | detail = upstream |
| 697 | if local_upstream: |
| 698 | detail = f"{upstream} (local upstream)" |
| 699 | checks.append(("Primary connection", "ok", detail)) |
nothing calls this directly
no test coverage detected