Skip to content

Fix Requires-Python fallback when GitHub API is unavailable - #64

Merged
jaraco merged 9 commits into
mainfrom
copilot/fix-inference-fallback-when-service-unavailable
Jun 13, 2026
Merged

Fix Requires-Python fallback when GitHub API is unavailable#64
jaraco merged 9 commits into
mainfrom
copilot/fix-inference-fallback-when-service-unavailable

Conversation

Copilot AI commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

When GitHub's API returns a 429 (rate-limited), python_requires_supported() was falling back to the hardcoded and stale "3.8". A 429 response from GitHub returns a dict, causing branches[0] to raise KeyError — which was already caught — but the fallback value was outdated.

Changes

  • Smarter fallback: Instead of "3.8", reads Requires-Python directly from the installed coherent.build package metadata — a value that was previously resolved from CPython, so it's stable and up-to-date:
except KeyError:
    fallback = importlib.metadata.metadata('coherent.build')['Requires-Python']
    log.warning(
        f"Failed to determine supported Python versions from CPython; "
        f"Unexpected {branches=}; using {fallback}"
    )
    return fallback

Copilot AI added 2 commits June 13, 2026 16:04
When GitHub's API is unavailable (429 rate-limit, connection error, etc.),
`python_requires_supported()` now falls back to the `Requires-Python` from
coherent.build's own installed package metadata instead of the stale
hardcoded `"3.8"`.

Also catches all exceptions (not just `KeyError`) so connection errors and
JSON decode errors (e.g., non-JSON 429 responses) are handled gracefully.

Closes #63
Copilot AI changed the title [WIP] Fix Python inference fallback when service is unavailable Fix Requires-Python fallback when GitHub API is unavailable Jun 13, 2026
Copilot AI requested a review from jaraco June 13, 2026 16:05
Comment thread discovery.py Outdated
Per review feedback, the except KeyError is appropriate for catching
unexpected GitHub API responses (e.g. a 429 returns a dict, so
branches[0] raises KeyError). Narrow the exception back from
except Exception to except KeyError and remove the unneeded
connection-error test case.

The fallback still uses _python_requires_from_self() instead of
the stale hardcoded '3.8'.
Comment thread discovery.py Outdated
Copilot AI requested a review from jaraco June 13, 2026 16:13
Comment thread discovery.py Outdated
Copilot AI requested a review from jaraco June 13, 2026 16:14
@jaraco

jaraco commented Jun 13, 2026

Copy link
Copy Markdown
Member

@copilot Let's remove the test_discovery module. It's overkill.

Copilot AI commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Let's remove the test_discovery module. It's overkill.

Done, tests/test_discovery.py has been removed.

Comment thread discovery.py
Copilot AI requested a review from jaraco June 13, 2026 16:23
@jaraco
jaraco marked this pull request as ready for review June 13, 2026 23:27
@jaraco
jaraco merged commit 351c452 into main Jun 13, 2026
24 checks passed
@jaraco
jaraco deleted the copilot/fix-inference-fallback-when-service-unavailable branch June 13, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants