11"""This module implements a renderer for the Python language."""
22
3- import json
4- import os
5- import posixpath
63import sys
7- import traceback
84from collections import ChainMap
9- from subprocess import PIPE , Popen # noqa: S404 (what other option, more secure that PIPE do we have? sockets?)
10- from typing import Any , BinaryIO , Callable , Iterator , List , Optional , Sequence , Tuple
5+ from typing import Any , Callable , Sequence
116
127from markdown import Markdown
138from markupsafe import Markup
149
1510from mkdocstrings .extension import PluginError
16- from mkdocstrings .handlers .base import BaseCollector , BaseHandler , BaseRenderer , CollectionError , CollectorItem
17- from mkdocstrings .inventory import Inventory
11+ from mkdocstrings .handlers .base import BaseRenderer , CollectorItem
1812from mkdocstrings .loggers import get_logger
1913
2014log = get_logger (__name__ )
2115
2216
23- class Order (enum .Enum ):
24- """Enumeration for the possible members ordering."""
25-
26- alphabetical = "alphabetical"
27- source = "source"
28-
29-
30- def _sort_key_alphabetical (item : CollectorItem ) -> Any :
31- # chr(sys.maxunicode) is a string that contains the final unicode
32- # character, so if 'name' isn't found on the object, the item will go to
33- # the end of the list.
34- return item .name or chr (sys .maxunicode )
35-
36-
37- def _sort_key_source (item : CollectorItem ) -> Any :
38- # if 'lineno' is none, the item will go to the start of the list.
39- return item .lineno if item .lineno is not None else - 1
40-
41-
42- order_map = {
43- Order .alphabetical : _sort_key_alphabetical ,
44- Order .source : _sort_key_source ,
45- }
46-
47-
4817class PythonRenderer (BaseRenderer ):
4918 """The class responsible for loading Jinja templates and rendering them.
5019
@@ -131,7 +100,14 @@ def update_env(self, md: Markdown, config: dict) -> None: # noqa: D102 (ignore
131100 self .env .filters ["brief_xref" ] = self .do_brief_xref
132101
133102 def do_brief_xref (self , path : str ) -> Markup :
134- """Filter to create cross-reference with brief text and full identifier as hover text."""
103+ """Filter to create cross-reference with brief text and full identifier as hover text.
104+
105+ Arguments:
106+ path: The path to shorten and render.
107+
108+ Returns:
109+ A span containing the brief cross-reference and the full one on hover.
110+ """
135111 brief = path .split ("." )[- 1 ]
136112 return Markup ("<span data-autorefs-optional-hover={path}>{brief}</span>" ).format (path = path , brief = brief )
137113
@@ -155,15 +131,13 @@ def sort_object(obj: CollectorItem, sort_function: Callable[[CollectorItem], Any
155131
156132
157133def _sort_key_alphabetical (item : CollectorItem ) -> Any :
158- """Return a sort key for 'alphabetical' sorting of CollectorItems."""
159134 # chr(sys.maxunicode) is a string that contains the final unicode
160135 # character, so if 'name' isn't found on the object, the item will go to
161136 # the end of the list.
162137 return item .get ("name" , chr (sys .maxunicode ))
163138
164139
165140def _sort_key_source (item : CollectorItem ) -> Any :
166- """Return a sort key for 'source' sorting of CollectorItems."""
167141 # if 'line_start' isn't found on the object, the item will go to
168142 # the start of the list.
169143 return item .get ("source" , {}).get ("line_start" , - 1 )
0 commit comments