Files
meson/docs/validatelinks.py
T
Paolo Bonzini 82c25986d7 docs: accept 429 status for github search and topic pages
GitHub queries often returns a 429 Too Many Requests status code
to the runners.  Ignore the error, as it makes CI flaky and a
Too Many Requests result (unlike a 404) is a sign that the
URL itself is ok.

While at it, improve slightly the formatting to avoid this:

>>> ASAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1 MESON_TEST_ITERATION=1 UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 MSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 MALLOC_PERTURB_=51 /usr/bin/python3 /home/runner/work/meson/meson/docs/./validatelinks.py /home/runner/work/meson/meson/docs/markdown/Users.md
――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――
"`meson` GitHub
topic" https://github.com/topics/meson 429
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2026-06-23 05:26:53 -04:00

49 lines
1.4 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
# Copyright 2025 The Meson development team
import sys
import re
import aiohttp
import asyncio
LINK = re.compile(r'\[(?P<name>[^\]]+)\]\((?P<url>.*?)\)')
async def fetch(session, name, url, timeout):
try:
async with session.get(url, timeout=timeout) as r:
if not r.ok:
return (name, url, r.status)
except Exception as e:
return (name, url, str(e))
async def main(filename):
with open(filename) as f:
text = f.read()
timeout = aiohttp.ClientTimeout(total=60)
async with aiohttp.ClientSession() as session:
tasks = []
for link in LINK.finditer(text):
name, url = link.groups()
name = name.replace('\n', ' ')
task = asyncio.ensure_future(fetch(session, name, url, timeout))
tasks.append(task)
responses = asyncio.gather(*tasks)
errors = [r for r in await responses if r is not None]
bad = False
for name, url, result in errors:
if re.match(r'https://github.com/(search|topics/)', url) and result == 429:
print(f'"{name}" {url} {result} (ignored)')
else:
print(f'"{name}" {url} {result}')
bad = True
if errors:
sys.exit(int(bad))
if __name__ == '__main__':
asyncio.run(main(sys.argv[1]))