···
#! /usr/bin/env nix-shell
#! nix-shell -i "python3 -I" -p "python3.withPackages(p: with p; [ aiohttp rich structlog ])"
4
-
from argparse import ArgumentParser
4
+
from argparse import ArgumentParser, Namespace
from collections import defaultdict
6
+
from collections.abc import Mapping, Sequence
from http import HTTPStatus
10
+
from typing import Optional
import asyncio, json, logging
import aiohttp, structlog
···
27
-
async def check(session, manpage: str, url: str) -> HTTPStatus:
29
+
async def check(session: aiohttp.ClientSession, manpage: str, url: str) -> HTTPStatus:
with log_context(manpage=manpage, url=url):
async with session.head(url) as resp:
···
44
-
async def main(urls_path):
46
+
async def main(urls_path: Path) -> Mapping[HTTPStatus, int]:
logger.info(f"Parsing {urls_path}")
with urls_path.open() as urls_file:
urls = json.load(urls_file)
49
-
count = defaultdict(lambda: 0)
51
+
count: defaultdict[HTTPStatus, int] = defaultdict(lambda: 0)
logger.info(f"Checking URLs from {urls_path}")
async with aiohttp.ClientSession() as session:
···
68
-
def parse_args(args=None):
70
+
def parse_args(args: Optional[Sequence[str]] = None) -> Namespace:
prog = 'check-manpage-urls',
description = 'Check the validity of the manpage URLs linked in the nixpkgs manual',