|
1 | | -"""Base module for handlers. |
2 | | -
|
3 | | -This module contains the base classes for implementing handlers. |
4 | | -""" |
| 1 | +# Base module for handlers. |
| 2 | +# |
| 3 | +# This module contains the base classes for implementing handlers. |
5 | 4 |
|
6 | 5 | from __future__ import annotations |
7 | 6 |
|
|
25 | 24 | # TODO: Replace with `from mkdocs.utils.cache import download_and_cache_url` when we depend on mkdocs>=1.5. |
26 | 25 | from mkdocs_get_deps.cache import download_and_cache_url |
27 | 26 |
|
28 | | -from mkdocstrings._internal.download import download_url_with_gz |
| 27 | +from mkdocstrings._internal.download import _download_url_with_gz |
29 | 28 | from mkdocstrings._internal.handlers.rendering import ( |
30 | 29 | HeadingShiftingTreeprocessor, |
31 | 30 | Highlighter, |
|
48 | 47 | from markdown import Extension |
49 | 48 | from mkdocs_autorefs import AutorefsHookInterface |
50 | 49 |
|
51 | | -log = get_logger(__name__) |
| 50 | +_logger = get_logger(__name__) |
52 | 51 |
|
53 | 52 | CollectorItem = Any |
| 53 | +"""The type of the item returned by the `collect` method of a handler.""" |
54 | 54 | HandlerConfig = Any |
| 55 | +"""The type of the configuration of a handler.""" |
55 | 56 | HandlerOptions = Any |
| 57 | +"""The type of the options passed to a handler.""" |
56 | 58 |
|
57 | 59 |
|
58 | 60 | # Autodoc instructions can appear in nested Markdown, |
@@ -201,9 +203,13 @@ def __init__( |
201 | 203 | ) |
202 | 204 |
|
203 | 205 | self.theme = theme |
| 206 | + """The selected theme.""" |
204 | 207 | self.custom_templates = custom_templates |
| 208 | + """The path to custom templates.""" |
205 | 209 | self.mdx = mdx |
| 210 | + """The Markdown extensions to use.""" |
206 | 211 | self.mdx_config = mdx_config |
| 212 | + """The configuration for the Markdown extensions.""" |
207 | 213 | self._md: Markdown | None = None |
208 | 214 | self._headings: list[Element] = [] |
209 | 215 |
|
@@ -240,6 +246,8 @@ def __init__( |
240 | 246 | loader=FileSystemLoader(paths), |
241 | 247 | auto_reload=False, # Editing a template in the middle of a build is not useful. |
242 | 248 | ) |
| 249 | + """The Jinja environment.""" |
| 250 | + |
243 | 251 | self.env.filters["convert_markdown"] = self.do_convert_markdown |
244 | 252 | self.env.filters["heading"] = self.do_heading |
245 | 253 | self.env.filters["any"] = do_any |
@@ -587,6 +595,7 @@ def __init__( |
587 | 595 | self._tool_config = tool_config |
588 | 596 |
|
589 | 597 | self.inventory: Inventory = Inventory(project=inventory_project, version=inventory_version) |
| 598 | + """The objects inventory.""" |
590 | 599 |
|
591 | 600 | self._inv_futures: dict[futures.Future, tuple[BaseHandler, str, Any]] = {} |
592 | 601 |
|
@@ -722,26 +731,26 @@ def _download_inventories(self) -> None: |
722 | 731 | if to_download: |
723 | 732 | thread_pool = futures.ThreadPoolExecutor(4) |
724 | 733 | for handler, url, conf in to_download: |
725 | | - log.debug("Downloading inventory from %s", url) |
| 734 | + _logger.debug("Downloading inventory from %s", url) |
726 | 735 | future = thread_pool.submit( |
727 | 736 | download_and_cache_url, |
728 | 737 | url, |
729 | 738 | datetime.timedelta(days=1), |
730 | | - download=download_url_with_gz, |
| 739 | + download=_download_url_with_gz, |
731 | 740 | ) |
732 | 741 | self._inv_futures[future] = (handler, url, conf) |
733 | 742 | thread_pool.shutdown(wait=False) |
734 | 743 |
|
735 | 744 | def _yield_inventory_items(self) -> Iterator[tuple[str, str]]: |
736 | 745 | if self._inv_futures: |
737 | | - log.debug("Waiting for %s inventory download(s)", len(self._inv_futures)) |
| 746 | + _logger.debug("Waiting for %s inventory download(s)", len(self._inv_futures)) |
738 | 747 | futures.wait(self._inv_futures, timeout=30) |
739 | 748 | # Reversed order so that pages from first futures take precedence: |
740 | 749 | for fut, (handler, url, conf) in reversed(self._inv_futures.items()): |
741 | 750 | try: |
742 | 751 | yield from handler.load_inventory(BytesIO(fut.result()), url, **conf) |
743 | 752 | except Exception as error: # noqa: BLE001 |
744 | | - log.error("Couldn't load inventory %s through handler '%s': %s", url, handler.name, error) # noqa: TRY400 |
| 753 | + _logger.error("Couldn't load inventory %s through handler '%s': %s", url, handler.name, error) # noqa: TRY400 |
745 | 754 | self._inv_futures = {} |
746 | 755 |
|
747 | 756 | @property |
|
0 commit comments