@@ -60,9 +60,12 @@ class HTTPValidator[E = str]:
6060 validated : set [E ] = field (default_factory = set )
6161
6262
63+ @dataclass
6364class LinkChecker (HTTPValidator ):
6465 """Track known links and validate URLs."""
6566
67+ name : str
68+
6669 async def __call__ (self , url : str , context : str ) -> None | ValidationError :
6770 """Check if URL is duplicate, validate it exists, and register it.
6871
@@ -76,25 +79,27 @@ async def __call__(self, url: str, context: str) -> None | ValidationError:
7679 if m := re .fullmatch (RE_RTD , url ):
7780 new_url = f"https://{ m ['domain' ]} /" + (f"page{ m ['path' ]} " if m ["path" ].strip ("/" ) else "" )
7881 msg = (
79- f"Please use the default version in ReadTheDocs URLs instead of { m ['version' ]!r} :\n { url } \n ->\n { new_url } "
82+ f"{ self .name } :{ context } : "
83+ f"Please use the default version in ReadTheDocs URLs instead of { m ['version' ]!r} :\n "
84+ f"{ url } \n ->\n { new_url } "
8085 )
8186 return ValidationError (msg )
8287 if url in self .validated :
83- msg = f"{ context } : Duplicate link: { url } "
88+ msg = f"{ self . name } : { context } : Duplicate link: { url } "
8489 return ValidationError (msg )
8590
8691 try :
8792 response = await self .client .head (url )
8893 except Exception as e :
89- msg = f"{ context } : URL { url } is not reachable: { e } "
94+ msg = f"{ self . name } : { context } : URL { url } is not reachable: { e } "
9095 return ValidationError (msg )
9196
9297 if response .status_code != httpx .codes .OK :
93- msg = f"{ context } : URL { url } is not reachable (error { response .status_code } ). "
98+ msg = f"{ self . name } : { context } : URL { url } is not reachable (error { response .status_code } ). "
9499 return ValidationError (msg )
95100
96101 self .validated .add (url )
97- log .info (f"Validated URL for { context } : { url !r} " )
102+ log .info (f"Validated { self . name } URL for { context } : { url !r} " )
98103 return None
99104
100105
@@ -349,9 +354,9 @@ def __post_init__(self) -> None:
349354
350355 # using different link checkers,
351356 # because each of them may point to the same URL and this wouldn't qualify as duplicate
352- self .check_home = LinkChecker (self .client )
353- self .check_docs = LinkChecker (self .client )
354- self .check_tutorial = LinkChecker (self .client )
357+ self .check_home = LinkChecker (self .client , name = "home" )
358+ self .check_docs = LinkChecker (self .client , name = "docs" )
359+ self .check_tutorial = LinkChecker (self .client , name = "tutorial" )
355360
356361 self .check_gh_users = GitHubUserValidator (self .client , self .github_token )
357362 self .check_pypi = PyPIValidator (self .client )
0 commit comments