Skip to content

Commit

Permalink
refactor: Report inventory loading errors
Browse files Browse the repository at this point in the history
Issue #157: #517
PR #568: #568

Co-authored-by: Oleh Prypin <oleh@pryp.in>
  • Loading branch information
pawamoy and oprypin committed May 11, 2023
1 parent 47afbf6 commit 2c05d78
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/mkdocstrings/plugin.py
Expand Up @@ -14,7 +14,6 @@

from __future__ import annotations

import collections
import functools
import gzip
import os
Expand Down Expand Up @@ -226,16 +225,17 @@ def on_config(self, config: Config, **kwargs: Any) -> Config: # noqa: ARG002

config["extra_css"].insert(0, self.css_filename) # So that it has lower priority than user files.

self._inv_futures = []
self._inv_futures = {}
if to_import:
inv_loader = futures.ThreadPoolExecutor(4)
for handler_name, import_item in to_import:
loader = self.get_handler(handler_name).load_inventory
future = inv_loader.submit(
self._load_inventory, # type: ignore[misc]
self.get_handler(handler_name).load_inventory,
loader,
**import_item,
)
self._inv_futures.append(future)
self._inv_futures[future] = (loader, import_item)
inv_loader.shutdown(wait=False)

if self.config["watch"]:
Expand Down Expand Up @@ -286,9 +286,18 @@ def on_env(self, env: Environment, config: Config, *args: Any, **kwargs: Any) ->
if self._inv_futures:
log.debug(f"Waiting for {len(self._inv_futures)} inventory download(s)")
futures.wait(self._inv_futures, timeout=30)
for page, identifier in collections.ChainMap(*(fut.result() for fut in self._inv_futures)).items():
results = {}
# Reversed order so that pages from first futures take precedence:
for fut in reversed(list(self._inv_futures)):
try:
results.update(fut.result())
except Exception as error: # noqa: BLE001
loader, import_item = self._inv_futures[fut]
loader_name = loader.__func__.__qualname__
log.error(f"Couldn't load inventory {import_item} through {loader_name}: {error}") # noqa: TRY400
for page, identifier in results.items():
config["plugins"]["autorefs"].register_url(page, identifier)
self._inv_futures = []
self._inv_futures = {}

def on_post_build(
self,
Expand Down

0 comments on commit 2c05d78

Please sign in to comment.