Resolve a package version to its download URL via PlatformIO Registry API. Args: package_name: Package name (e.g., "toolchain-riscv32-esp") version: Version string (e.g., "14.2.0+20241119") or None for latest package_type: Package type hint ("tool", "framework", etc
(
package_name: str,
version: Optional[str],
package_type: str = "",
system: Optional[str] = None,
)
| 798 | |
| 799 | |
| 800 | def _resolve_package_url_from_registry( |
| 801 | package_name: str, |
| 802 | version: Optional[str], |
| 803 | package_type: str = "", |
| 804 | system: Optional[str] = None, |
| 805 | ) -> Optional[str]: |
| 806 | """ |
| 807 | Resolve a package version to its download URL via PlatformIO Registry API. |
| 808 | |
| 809 | Args: |
| 810 | package_name: Package name (e.g., "toolchain-riscv32-esp") |
| 811 | version: Version string (e.g., "14.2.0+20241119") or None for latest |
| 812 | package_type: Package type hint ("tool", "framework", etc.) |
| 813 | system: Target system (e.g., "windows_amd64"). If None, auto-detects. |
| 814 | |
| 815 | Returns: |
| 816 | Download URL or None if resolution fails. |
| 817 | """ |
| 818 | import platform as platform_module |
| 819 | import urllib.request |
| 820 | |
| 821 | # Auto-detect system if not provided |
| 822 | if system is None: |
| 823 | os_name = platform_module.system().lower() |
| 824 | machine = platform_module.machine().lower() |
| 825 | |
| 826 | if os_name == "windows": |
| 827 | system = ( |
| 828 | "windows_amd64" if machine in ("amd64", "x86_64") else "windows_x86" |
| 829 | ) |
| 830 | elif os_name == "darwin": |
| 831 | system = "darwin_arm64" if machine == "arm64" else "darwin_x86_64" |
| 832 | elif os_name == "linux": |
| 833 | if machine in ("aarch64", "arm64"): |
| 834 | system = "linux_aarch64" |
| 835 | elif machine in ("armv7l", "armv8l"): |
| 836 | system = "linux_armv7l" |
| 837 | elif machine == "armv6l": |
| 838 | system = "linux_armv6l" |
| 839 | else: |
| 840 | system = "linux_x86_64" |
| 841 | else: |
| 842 | logger.warning(f"Unknown platform: {os_name}/{machine}") |
| 843 | return None |
| 844 | |
| 845 | # Try both platformio/ and espressif/ owners (common for ESP32 packages) |
| 846 | owners = ["platformio", "espressif"] |
| 847 | |
| 848 | # Normalize package type for PlatformIO Registry API |
| 849 | # The API uses "tool" for toolchains, frameworks, debuggers, uploaders, etc. |
| 850 | if package_type in ("toolchain", "framework", "debugger", "uploader", ""): |
| 851 | package_type = "tool" |
| 852 | # If still empty or unknown, default to "tool" |
| 853 | if not package_type: |
| 854 | package_type = "tool" |
| 855 | |
| 856 | for owner in owners: |
| 857 | try: |
no test coverage detected