diff --git a/docs/scripts/autorefs/plugin.py b/docs/scripts/autorefs/plugin.py index c4ac6a3a0..7f76e8be5 100644 --- a/docs/scripts/autorefs/plugin.py +++ b/docs/scripts/autorefs/plugin.py @@ -16,17 +16,16 @@ this plugin searches for references of the form `[identifier][]` or `[title][identifier]` that were not resolved, and fixes them using the previously stored identifier-URL mapping. """ - import contextlib import functools import logging +import os import re from html import escape, unescape from typing import Any, Callable, Dict, List, Match, Optional, Sequence, Tuple, Union from urllib.parse import urlsplit from xml.etree.ElementTree import Element -import pathspec from markdown import Markdown from markdown.extensions import Extension from markdown.inlinepatterns import REFERENCE_RE, ReferenceInlineProcessor @@ -278,35 +277,32 @@ def __init__(self) -> None: def priority_patterns(self): if self._priority_patterns is None: self._priority_patterns = [ - pathspec.patterns.GitWildMatchPattern(pat) - for pat in self.config.get("priority") + os.path.join("/", pat) for pat in self.config.get("priority") ] return self._priority_patterns - def register_anchor(self, page: str, identifier: str): + def register_anchor(self, url: str, identifier: str): """Register that an anchor corresponding to an identifier was encountered when rendering the page. Arguments: - page: The relative URL of the current page. Examples: `'foo/bar/'`, `'foo/index.html'` + url: The relative URL of the current page. Examples: `'foo/bar/'`, `'foo/index.html'` identifier: The HTML anchor (without '#') as a string. """ + if identifier in self._url_map: + old_url = os.path.join("/", self._url_map[identifier]) rev_patterns = list(enumerate(self.priority_patterns))[::-1] old_priority_idx = next( - ( - i - for i, pat in rev_patterns - if pat.match_file(self._url_map[identifier]) - ), + (i for i, pat in rev_patterns if re.match(pat, old_url)), len(rev_patterns), ) new_priority_idx = next( - (i for i, pat in rev_patterns if pat.match_file(page)), + (i for i, pat in rev_patterns if re.match(pat, url)), len(rev_patterns), ) if new_priority_idx >= old_priority_idx: return - self._url_map[identifier] = f"{page}#{identifier}" + self._url_map[identifier] = f"{url}#{identifier}" def register_url(self, identifier: str, url: str): """Register that the identifier should be turned into a link to this URL. @@ -418,10 +414,10 @@ def on_page_content( f"{__name__}: Mapping identifiers to URLs for page {page.file.src_path}" ) for item in page.toc.items: - self.map_urls(page.url, item) + self.map_urls(page, item) return html - def map_urls(self, base_url: str, anchor: AnchorLink) -> None: + def map_urls(self, page: Page, anchor: AnchorLink) -> None: """Recurse on every anchor to map its ID to its absolute URL. This method populates `self.url_map` by side-effect. @@ -430,9 +426,10 @@ def map_urls(self, base_url: str, anchor: AnchorLink) -> None: base_url: The base URL to use as a prefix for each anchor's relative URL. anchor: The anchor to process and to recurse on. """ - self.register_anchor(base_url, anchor.id) + abs_url = os.path.join("/", page.file.url) + self.register_anchor(abs_url, anchor.id) for child in anchor.children: - self.map_urls(base_url, child) + self.map_urls(page, child) def on_post_page( self, output: str, page: Page, **kwargs diff --git a/docs/scripts/griffe_ext.py b/docs/scripts/griffe_ext.py index 9f8fd5af4..8cd495a99 100644 --- a/docs/scripts/griffe_ext.py +++ b/docs/scripts/griffe_ext.py @@ -1,12 +1,24 @@ import ast import importlib import inspect +import logging import sys from typing import Union import astunparse -from griffe import Extension, Object, ObjectNode, get_logger +from griffe import Extension, Object, ObjectNode from griffe.docstrings.dataclasses import DocstringSectionParameters +from griffe.expressions import Expr +from griffe.logger import patch_loggers + + +def get_logger(name): + new_logger = logging.getLogger(name) + new_logger.setLevel("ERROR") + return new_logger + + +patch_loggers(get_logger) logger = get_logger(__name__) @@ -98,5 +110,7 @@ def on_instance(self, node: Union[ast.AST, ObjectNode], obj: Object) -> None: for param in param_section.value: if param.name in defaults: param.default = str(defaults[param.name]) + if isinstance(param.default, Expr): + continue if param.default is not None and len(param.default) > 50: param.default = param.default[: 50 - 3] + "..." diff --git a/mkdocs.yml b/mkdocs.yml index 952b33115..e34b2c798 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -173,7 +173,7 @@ plugins: - search - autorefs: priority: - - '*' + - .* - reference - mkdocstrings: enable_inventory: true