* Fetch package metadata from PyPI and extract dependencies (with retry)
(packageName, version)
| 250 | * Fetch package metadata from PyPI and extract dependencies (with retry) |
| 251 | */ |
| 252 | async function fetchPyPIDependencies(packageName, version) { |
| 253 | const url = `https://pypi.org/pypi/${packageName}/${version}/json`; |
| 254 | |
| 255 | console.log(`${colors.dim}Fetching ${url}${colors.reset}`); |
| 256 | |
| 257 | let lastError; |
| 258 | for (let attempt = 0; attempt < RETRY_COUNT; attempt++) { |
| 259 | try { |
| 260 | const response = await fetch(url); |
| 261 | |
| 262 | // 404 is a config issue, don't retry |
| 263 | if (response.status === 404) { |
| 264 | throw new Error( |
| 265 | `Package ${packageName}==${version} not found on PyPI (404). Check the package name and version.`, |
| 266 | ); |
| 267 | } |
| 268 | |
| 269 | if (!response.ok) { |
| 270 | throw new Error( |
| 271 | `Failed to fetch ${packageName}==${version} from PyPI: ${response.status} ${response.statusText}`, |
| 272 | ); |
| 273 | } |
| 274 | |
| 275 | const data = await response.json(); |
| 276 | return data.info?.requires_dist || []; |
| 277 | } catch (err) { |
| 278 | lastError = err; |
| 279 | |
| 280 | // Don't retry on 404 (config issue) |
| 281 | if (err.message.includes("not found on PyPI (404)")) { |
| 282 | throw err; |
| 283 | } |
| 284 | |
| 285 | // Retry on other errors (network issues, 5xx, etc.) |
| 286 | if (attempt < RETRY_COUNT - 1) { |
| 287 | const delay = RETRY_DELAY_MS * (attempt + 1); |
| 288 | console.log( |
| 289 | `${colors.yellow}Retry ${attempt + 1}/${RETRY_COUNT - 1} after ${delay}ms...${colors.reset}`, |
| 290 | ); |
| 291 | await sleep(delay); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | throw lastError; |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Parse PyPI requires_dist array and extract SDK package versions |