|
10 | 10 | import xml.etree.ElementTree as ET |
11 | 11 | from typing import TYPE_CHECKING |
12 | 12 | from urllib.parse import urljoin, urlparse, urlunparse |
| 13 | +from packaging.version import Version |
13 | 14 |
|
14 | 15 | from sphinx.util import logging |
15 | 16 | from sphinx.util import requests |
| 17 | +from sphinx import __version__ as __sphinx_version__ |
16 | 18 |
|
17 | 19 | if TYPE_CHECKING: |
18 | 20 | from sphinx.application import Sphinx |
@@ -158,14 +160,20 @@ def patch_linkcheck_worker(app: Sphinx, config: Config) -> None: |
158 | 160 | if not hasattr(app, 'builder') or app.builder.name != 'linkcheck': |
159 | 161 | return |
160 | 162 |
|
161 | | - from sphinx.builders.linkcheck import HyperlinkAvailabilityCheckWorker, _Status |
| 163 | + from sphinx.builders.linkcheck import HyperlinkAvailabilityCheckWorker |
| 164 | + |
| 165 | + if Version(__sphinx_version__) > Version('8.1.3'): |
| 166 | + from sphinx.builders.linkcheck import _Status |
| 167 | + working = _Status.WORKING |
| 168 | + else: |
| 169 | + working = 'working' |
162 | 170 |
|
163 | 171 | original_check = HyperlinkAvailabilityCheckWorker._check |
164 | 172 |
|
165 | 173 | def patched_check(self, docname: str, uri: str, hyperlink) -> tuple: |
166 | 174 | """Patched _check method that handles in-sitemap URIs.""" |
167 | 175 | if uri.endswith(' (from sitemap)'): |
168 | | - return _Status.WORKING, '', 0 |
| 176 | + return working, '', 0 |
169 | 177 | return original_check(self, docname, uri, hyperlink) |
170 | 178 |
|
171 | 179 | HyperlinkAvailabilityCheckWorker._check = patched_check |
|
0 commit comments