11#! /usr/bin/env nix-shell
22#! nix-shell -i "python3 -I" -p "python3.withPackages(p: with p; [ aiohttp rich structlog ])"
33
4- from argparse import ArgumentParser
4+ from argparse import ArgumentParser , Namespace
55from collections import defaultdict
6+ from collections .abc import Mapping , Sequence
67from enum import IntEnum
78from http import HTTPStatus
89from pathlib import Path
10+ from typing import Optional
911import asyncio , json , logging
1012
1113import aiohttp , structlog
2426 HTTPStatus .NOT_FOUND ,
2527))
2628
27- async def check (session , manpage : str , url : str ) -> HTTPStatus :
29+ async def check (session : aiohttp . ClientSession , manpage : str , url : str ) -> HTTPStatus :
2830 with log_context (manpage = manpage , url = url ):
2931 logger .debug ("Checking" )
3032 async with session .head (url ) as resp :
@@ -41,12 +43,12 @@ async def check(session, manpage: str, url: str) -> HTTPStatus:
4143
4244 return st
4345
44- async def main (urls_path ) :
46+ async def main (urls_path : Path ) -> Mapping [ HTTPStatus , int ] :
4547 logger .info (f"Parsing { urls_path } " )
4648 with urls_path .open () as urls_file :
4749 urls = json .load (urls_file )
4850
49- count = defaultdict (lambda : 0 )
51+ count : defaultdict [ HTTPStatus , int ] = defaultdict (lambda : 0 )
5052
5153 logger .info (f"Checking URLs from { urls_path } " )
5254 async with aiohttp .ClientSession () as session :
@@ -65,7 +67,7 @@ async def main(urls_path):
6567 return count
6668
6769
68- def parse_args (args = None ):
70+ def parse_args (args : Optional [ Sequence [ str ]] = None ) -> Namespace :
6971 parser = ArgumentParser (
7072 prog = 'check-manpage-urls' ,
7173 description = 'Check the validity of the manpage URLs linked in the nixpkgs manual' ,
0 commit comments