mkdocstrings-matlab 1.0.7__py3-none-any.whl → 1.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@ import sys
7
7
  from dataclasses import field, fields
8
8
  from typing import TYPE_CHECKING, Annotated, Any, Literal
9
9
 
10
+ from griffe._internal.docstrings.parsers import DocstringStyle
10
11
  from mkdocstrings import get_logger
11
12
 
12
13
  # YORE: EOL 3.10: Replace block with line 2.
@@ -358,12 +359,12 @@ class MatlabInputOptions:
358
359
  ] = "table"
359
360
 
360
361
  docstring_style: Annotated[
361
- Literal["auto", "google", "numpy", "sphinx"] | None,
362
+ DocstringStyle | None,
362
363
  Field(
363
364
  group="docstrings",
364
365
  description="The docstring style to use: `auto`, `google`, `numpy`, `sphinx`, or `None`.",
365
366
  ),
366
- ] = "google"
367
+ ] = "auto"
367
368
 
368
369
  parse_arguments: Annotated[
369
370
  bool,
@@ -132,6 +132,9 @@ class MatlabHandler(BaseHandler):
132
132
  template_name = rendering.do_get_template(data)
133
133
  template = self.env.get_template(template_name)
134
134
 
135
+ if hasattr(data, "docstring") and data.docstring is not None:
136
+ data.docstring.parse()
137
+
135
138
  heading_level = options.heading_level
136
139
 
137
140
  html = template.render(
@@ -166,6 +169,7 @@ class MatlabHandler(BaseHandler):
166
169
  self.env.filters["stash_crossref"] = rendering.do_stash_crossref
167
170
  self.env.filters["get_template"] = rendering.do_get_template
168
171
  self.env.filters["function_docstring"] = rendering.do_function_docstring
172
+ self.env.filters["parse_docstring"] = rendering.do_parse_docstring
169
173
  self.env.filters["as_properties_section"] = rendering.do_as_properties_section
170
174
  self.env.filters["as_functions_section"] = rendering.do_as_functions_section
171
175
  self.env.filters["as_classes_section"] = rendering.do_as_classes_section
@@ -14,6 +14,7 @@ from typing import TYPE_CHECKING, Any, Callable, ClassVar, Literal
14
14
  from griffe import (
15
15
  AliasResolutionError,
16
16
  CyclicAliasError,
17
+ Docstring,
17
18
  DocstringAttribute,
18
19
  DocstringClass,
19
20
  DocstringFunction,
@@ -32,6 +33,7 @@ from griffe._internal.docstrings.models import (
32
33
  DocstringSectionParameters,
33
34
  DocstringSectionReturns,
34
35
  )
36
+ from griffe._internal.docstrings.parsers import DocstringStyle, parse
35
37
  from jinja2 import pass_context
36
38
  from markupsafe import Markup
37
39
  from maxx.enums import ArgumentKind
@@ -612,17 +614,30 @@ def do_as_namespaces_section(
612
614
  )
613
615
 
614
616
 
617
+ def do_parse_docstring(
618
+ docstring: Docstring | None,
619
+ docstring_style: DocstringStyle,
620
+ docstring_options: dict[str, Any] | None,
621
+ ) -> list[DocstringSection]:
622
+ if docstring is None:
623
+ return []
624
+ options = docstring_options or {}
625
+ return parse(docstring, docstring_style, **options)
626
+
627
+
615
628
  def do_function_docstring(
616
629
  function: Function,
617
630
  parse_arguments: bool,
618
631
  show_docstring_input_arguments: bool,
619
632
  show_docstring_name_value_arguments: bool,
620
633
  show_docstring_output_arguments: bool,
634
+ docstring_style: DocstringStyle,
635
+ docstring_options: dict[str, Any] | None,
621
636
  ) -> list[DocstringSection]:
622
637
  if function.docstring is None:
623
638
  return []
624
639
 
625
- docstring_sections = [section for section in function.docstring.parsed]
640
+ docstring_sections = do_parse_docstring(function.docstring, docstring_style, docstring_options)
626
641
  if not parse_arguments or not (
627
642
  show_docstring_input_arguments
628
643
  or show_docstring_name_value_arguments
@@ -154,7 +154,7 @@ Context:
154
154
 
155
155
  This block renders the docstring for the class.
156
156
  -#}
157
- {% with docstring_sections = class.docstring.parsed %}
157
+ {% with docstring_sections = class.docstring | parse_docstring(config.docstring_style, config.docstring_options) %}
158
158
  {% include "docstring.html.jinja" with context %}
159
159
  {% endwith %}
160
160
  {% if config.merge_constructor_into_class and class.constructor %}
@@ -163,7 +163,7 @@ Context:
163
163
  {% with check_members = all_members if (config.inherited_members is true or (config.inherited_members is iterable and class.constructor.name in config.inherited_members)) else class.members %}
164
164
  {% if class.constructor.name in check_members and class.constructor.has_docstring %}
165
165
  {% with function = class.constructor %}
166
- {% with obj = function, docstring_sections = function | function_docstring(config.parse_arguments, config.show_docstring_input_arguments, config.show_docstring_name_value_arguments, config.show_docstring_output_arguments) %}
166
+ {% with obj = function, docstring_sections = function | function_docstring(config.parse_arguments, config.show_docstring_input_arguments, config.show_docstring_name_value_arguments, config.show_docstring_output_arguments, config.docstring_style, config.docstring_options) %}
167
167
  {% include "docstring.html.jinja" with context %}
168
168
  {% endwith %}
169
169
  {% endwith %}
@@ -79,7 +79,7 @@ Context:
79
79
 
80
80
  This block renders the docstring for the folder.
81
81
  -#}
82
- {% with docstring_sections = folder.docstring.parsed %}
82
+ {% with docstring_sections = folder.docstring | parse_docstring(config.docstring_style, config.docstring_options) %}
83
83
  {% include "docstring.html.jinja" with context %}
84
84
  {% endwith %}
85
85
  {% endblock docstring %}
@@ -114,7 +114,7 @@ Context:
114
114
 
115
115
  This block renders the docstring for the function.
116
116
  -#}
117
- {% with docstring_sections = function | function_docstring(config.parse_arguments, config.show_docstring_input_arguments, config.show_docstring_name_value_arguments, config.show_docstring_output_arguments) %}
117
+ {% with docstring_sections = function | function_docstring(config.parse_arguments, config.show_docstring_input_arguments, config.show_docstring_name_value_arguments, config.show_docstring_output_arguments, config.docstring_style, config.docstring_options) %}
118
118
  {% include "docstring.html.jinja" with context %}
119
119
  {% endwith %}
120
120
  {% endblock docstring %}
@@ -82,7 +82,7 @@ Context:
82
82
 
83
83
  This block renders the docstring for the namespace.
84
84
  -#}
85
- {% with docstring_sections = namespace.docstring.parsed %}
85
+ {% with docstring_sections = namespace.docstring | parse_docstring(config.docstring_style, config.docstring_options) %}
86
86
  {% include "docstring.html.jinja" with context %}
87
87
  {% endwith %}
88
88
  {% endblock docstring %}
@@ -109,7 +109,7 @@ Context:
109
109
 
110
110
  This block renders the docstring for the property.
111
111
  -#}
112
- {% with docstring_sections = property.docstring.parsed %}
112
+ {% with docstring_sections = property.docstring | parse_docstring(config.docstring_style, config.docstring_options) %}
113
113
  {% include "docstring.html.jinja" with context %}
114
114
  {% endwith %}
115
115
  {% endblock docstring %}
@@ -85,7 +85,7 @@ Context:
85
85
 
86
86
  This block renders the docstring for the script.
87
87
  -#}
88
- {% with docstring_sections = script.docstring.parsed %}
88
+ {% with docstring_sections = script.docstring | parse_docstring(config.docstring_style, config.docstring_options) %}
89
89
  {% include "docstring.html.jinja" with context %}
90
90
  {% endwith %}
91
91
  {% endblock docstring %}
@@ -7,7 +7,7 @@
7
7
  -#}
8
8
  {% endblock logs %}
9
9
 
10
- {% if not obj.docstring.parsed | selectattr("kind.value", "eq", "classes") | list %}
10
+ {% if not obj.docstring | parse_docstring(config.docstring_style, config.docstring_options) | selectattr("kind.value", "eq", "classes") | list %}
11
11
  {% with section = obj.classes
12
12
  |filter_objects(
13
13
  filters=config.filters,
@@ -7,7 +7,7 @@
7
7
  -#}
8
8
  {% endblock logs %}
9
9
 
10
- {% if not obj.docstring.parsed | selectattr("kind.value", "eq", "functions") | list %}
10
+ {% if not obj.docstring | parse_docstring(config.docstring_style, config.docstring_options) | selectattr("kind.value", "eq", "functions") | list %}
11
11
  {% with section = obj.functions
12
12
  |filter_objects(
13
13
  filters=config.filters,
@@ -7,7 +7,7 @@
7
7
  -#}
8
8
  {% endblock logs %}
9
9
 
10
- {% if not obj.docstring.parsed | selectattr("kind.value", "eq", "modules") | list %}
10
+ {% if not obj.docstring | parse_docstring(config.docstring_style, config.docstring_options) | selectattr("kind.value", "eq", "modules") | list %}
11
11
  {% with section = obj.modules
12
12
  |filter_objects(
13
13
  filters=config.filters,
@@ -7,7 +7,7 @@
7
7
  -#}
8
8
  {% endblock logs %}
9
9
 
10
- {% if not obj.docstring.parsed | selectattr("kind.value", "eq", "properties") | list %}
10
+ {% if not obj.docstring | parse_docstring(config.docstring_style, config.docstring_options) | selectattr("kind.value", "eq", "properties") | list %}
11
11
  {% with section = obj.properties
12
12
  |filter_objects(
13
13
  filters=config.filters,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocstrings-matlab
3
- Version: 1.0.7
3
+ Version: 1.0.9
4
4
  Summary: A MATLAB handler for mkdocstrings
5
5
  Author-email: Mark Hu <watermarkhu@gmail.com>
6
6
  License: MIT
@@ -22,7 +22,7 @@ Classifier: Typing :: Typed
22
22
  Requires-Python: <3.14,>=3.10
23
23
  Requires-Dist: charset-normalizer~=3.4
24
24
  Requires-Dist: griffe~=1.14.0
25
- Requires-Dist: maxx~=0.4.1
25
+ Requires-Dist: maxx~=0.4.2
26
26
  Requires-Dist: mkdocs-autorefs~=1.4
27
27
  Requires-Dist: mkdocstrings~=0.29
28
28
  Requires-Dist: typing-extensions>=4.0; python_version < '3.11'
@@ -1,21 +1,20 @@
1
1
  mkdocstrings_handlers/matlab/__init__.py,sha256=zLE8MANvIbg-pEVFc9bGhhIUvqAjnSANBGqek-dm3LM,1721
2
- mkdocstrings_handlers/matlab/config.py,sha256=yuoB62JOm4vW5uJYd9mqvwIhtfmgSD34CMccc-9aEEc,26724
3
- mkdocstrings_handlers/matlab/handler.py,sha256=gD0ogRqzOlZAn_iv1E0xFflFj_tUmQcWUeWLPlp1RxI,9803
4
- mkdocstrings_handlers/matlab/logger.py,sha256=96hRpwOVyvEF0e9f8rvXnNBSBAuHEvM5a6bJNN8hjRo,3298
2
+ mkdocstrings_handlers/matlab/config.py,sha256=zpnTijfd21NTc_gIHSvzkOheUO4NTeNoaTyD62SIcNg,26755
3
+ mkdocstrings_handlers/matlab/handler.py,sha256=QUvqGlFaAvNVsxkjdh8y2xM7f7J-12vU351Ed9bItps,9984
5
4
  mkdocstrings_handlers/matlab/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- mkdocstrings_handlers/matlab/rendering.py,sha256=yhxpyAcEkCCC6of84ENip5QhEheVNl16E5jNjB53iZs,25726
5
+ mkdocstrings_handlers/matlab/rendering.py,sha256=NhhgO7s6A64_s5U6Zg_wOFWHIzM3Alk6hO-so29zj7g,26227
7
6
  mkdocstrings_handlers/matlab/templates/material/attributes.html.jinja,sha256=3Wv9tRkBASmxW3NGdAw9V8mc7G6hc1pDIKmVQztlFJk,818
8
7
  mkdocstrings_handlers/matlab/templates/material/backlinks.html.jinja,sha256=FFrvIa-KH-DhT1cpc9HL0ecShR2gUVGs3VT9c1q88z8,467
9
8
  mkdocstrings_handlers/matlab/templates/material/children.html.jinja,sha256=gWV77R1BSkVlbQdY_VB9wrGSBY30bcm23skPTfOW1Fs,7517
10
- mkdocstrings_handlers/matlab/templates/material/class.html.jinja,sha256=vcTCQ9Q5WRLiT6t8mMKopGSQCfmJpnI678kCBxNWmak,9706
9
+ mkdocstrings_handlers/matlab/templates/material/class.html.jinja,sha256=cF4MbUEjlqK0p7LpKozRJyb3ULHVtXDl5VVDO83VSnE,9817
11
10
  mkdocstrings_handlers/matlab/templates/material/docstring.html.jinja,sha256=lpdQelVsBwBi0jpO1xCqX-59SmFZ7N269JCNhiae6Pc,2666
12
11
  mkdocstrings_handlers/matlab/templates/material/expression.html.jinja,sha256=3srDE2lRULPYAo7PFvy0tMT-2FKo2r6yE8Dvtui1HMI,1921
13
- mkdocstrings_handlers/matlab/templates/material/folder.html.jinja,sha256=wdr9Mte9cFy_dKbpCnWN2UPreZEZo5EHG23bEHwMd9M,4004
14
- mkdocstrings_handlers/matlab/templates/material/function.html.jinja,sha256=xJ6E06q9vxHaOxK2cRzP1DvoWqWOCO1NIME7j64dsf8,5659
12
+ mkdocstrings_handlers/matlab/templates/material/folder.html.jinja,sha256=b5fzUclu95-5vVwr6row8Y3GJUJWaxw2e7EU8kPlXM8,4065
13
+ mkdocstrings_handlers/matlab/templates/material/function.html.jinja,sha256=sPiTAknccAhHm0mbJYGcnmjGpQswDCHgzyAZ0DBYaVU,5709
15
14
  mkdocstrings_handlers/matlab/templates/material/language.html.jinja,sha256=7gyknTiapqCM8TjUHdXkQgZMmYwcuy6Ze0pkntE7g8s,617
16
- mkdocstrings_handlers/matlab/templates/material/namespace.html.jinja,sha256=oS8Hiy_BWRRw-Xf-r3Mvi7H3egR7YlKms8bIHk_ocw0,4107
17
- mkdocstrings_handlers/matlab/templates/material/property.html.jinja,sha256=qS3WyTyhMH5c40TukESjVRirYybGoyhNys4kECegR3I,4579
18
- mkdocstrings_handlers/matlab/templates/material/script.html.jinja,sha256=doIFI-HiOAqBmSP3RhUsHlE-Djk2xE-MrModxWLM-VQ,4040
15
+ mkdocstrings_handlers/matlab/templates/material/namespace.html.jinja,sha256=AuxgTGzPdXAnjR8Vly19Wh1eHdkR4c_3HVeljHKgk3Y,4168
16
+ mkdocstrings_handlers/matlab/templates/material/property.html.jinja,sha256=yTnaXkGZVsy0rip388yeJJxtta21ImTDY8OjfOej5n8,4640
17
+ mkdocstrings_handlers/matlab/templates/material/script.html.jinja,sha256=7KdPbjSKCVBnSwhmHoYfMT8ub4Wvp1dc2Xg_7HJb2bU,4101
19
18
  mkdocstrings_handlers/matlab/templates/material/signature.html.jinja,sha256=2J0XcBlTEGbC-UKCqoMbVmstAKMgszzGyZAIovhDSW0,3946
20
19
  mkdocstrings_handlers/matlab/templates/material/style.css,sha256=UgaVpWNzrTNzt_19wH0ryVAhs1GJ5eYK4JKJMHT4h2k,5083
21
20
  mkdocstrings_handlers/matlab/templates/material/summary.html.jinja,sha256=NgPQG1FeujVPJc6ePB1lRx7ovMuHqPkkSDVYPXoDWmA,725
@@ -31,11 +30,11 @@ mkdocstrings_handlers/matlab/templates/material/docstring/properties.html.jinja,
31
30
  mkdocstrings_handlers/matlab/templates/material/languages/en.html.jinja,sha256=Oen9OTX26S-RfcGYkRQr-FVoIYo1jWpK47UB_47l6S0,1042
32
31
  mkdocstrings_handlers/matlab/templates/material/languages/ja.html.jinja,sha256=Urtwz_zgo4ij3SkThxuaCS3x0eLqD0ScejocX-wgWVs,1131
33
32
  mkdocstrings_handlers/matlab/templates/material/languages/zh.html.jinja,sha256=qV2S8ikiE1C3TBqwRvKGvAnNtWGqDLn9j_NCOmFi95E,999
34
- mkdocstrings_handlers/matlab/templates/material/summary/classes.html.jinja,sha256=JuPeZVFHUF398Dw_E-HWoDKlCGFgj52B4W2YJosU4pA,842
35
- mkdocstrings_handlers/matlab/templates/material/summary/functions.html.jinja,sha256=f19-RvEkHZO4VegiQApq71nAEA27RKwQW3S2NMmKrW4,860
36
- mkdocstrings_handlers/matlab/templates/material/summary/namespaces.html.jinja,sha256=J0aPYlktc5RY3Gax6GCZDxT5qgFDB5b3eqZZXfZOHxU,845
37
- mkdocstrings_handlers/matlab/templates/material/summary/properties.html.jinja,sha256=0wQeDtZzfLSZPHJzLG_MVzre1NSyoSHowTwYzk0JX1c,857
38
- mkdocstrings_matlab-1.0.7.dist-info/METADATA,sha256=2DbOSly9BX0gdF6hluz1x1aAI8WcsyhIWurZL6iDPck,4616
39
- mkdocstrings_matlab-1.0.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
40
- mkdocstrings_matlab-1.0.7.dist-info/licenses/LICENSE,sha256=TZQpwBuA3KLH56--XDAY2Qwo9gGdxeTITYhMOylmYhg,743
41
- mkdocstrings_matlab-1.0.7.dist-info/RECORD,,
33
+ mkdocstrings_handlers/matlab/templates/material/summary/classes.html.jinja,sha256=eALUVZq6MDLZmtaLD_Y9029eQQbFdtHxGKDe44FDWMI,903
34
+ mkdocstrings_handlers/matlab/templates/material/summary/functions.html.jinja,sha256=IhcY4O2HeGYjUjNQ9W9aYiNecCjrTzNVQopgRzxHtz8,921
35
+ mkdocstrings_handlers/matlab/templates/material/summary/namespaces.html.jinja,sha256=fWuFO5a2P-OEky2wvv95XLtB-9PTkymFC9MIQ5XS6FE,906
36
+ mkdocstrings_handlers/matlab/templates/material/summary/properties.html.jinja,sha256=lgVn15U3mg72RjmgvZxCqrRsjx2eEyZ0HM0bt1LxWMM,918
37
+ mkdocstrings_matlab-1.0.9.dist-info/METADATA,sha256=NKl6JG6GBjVwdzalMgDGF1hvfTjIEPHjRJ6y4guQIf4,4616
38
+ mkdocstrings_matlab-1.0.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
39
+ mkdocstrings_matlab-1.0.9.dist-info/licenses/LICENSE,sha256=TZQpwBuA3KLH56--XDAY2Qwo9gGdxeTITYhMOylmYhg,743
40
+ mkdocstrings_matlab-1.0.9.dist-info/RECORD,,
@@ -1,111 +0,0 @@
1
- # This module contains the logger used throughout Griffe.
2
- # The logger is actually a wrapper around the standard Python logger.
3
- # We wrap it so that it is easier for other downstream libraries to patch it.
4
- # For example, mkdocstrings-python patches the logger to relocate it as a child
5
- # of `mkdocs.plugins` so that it fits in the MkDocs logging configuration.
6
- #
7
- # We use a single, global logger because our public API is exposed in a single module, `griffe`.
8
- # Extensions however should use their own logger, which is why we provide the `get_logger` function.
9
-
10
- from __future__ import annotations
11
-
12
- import logging
13
- from contextlib import contextmanager
14
- from typing import TYPE_CHECKING, Any, Callable, ClassVar
15
-
16
- if TYPE_CHECKING:
17
- from collections.abc import Iterator
18
-
19
-
20
- class Logger:
21
- _default_logger: Any = logging.getLogger
22
- _instances: ClassVar[dict[str, Logger]] = {}
23
-
24
- def __init__(self, name: str) -> None:
25
- # Default logger that can be patched by third-party.
26
- self._logger = self.__class__._default_logger(name)
27
-
28
- def __getattr__(self, name: str) -> Any:
29
- # Forward everything to the logger.
30
- return getattr(self._logger, name)
31
-
32
- @contextmanager
33
- def disable(self) -> Iterator[None]:
34
- """Temporarily disable logging."""
35
- old_level = self._logger.level
36
- self._logger.setLevel(100)
37
- try:
38
- yield
39
- finally:
40
- self._logger.setLevel(old_level)
41
-
42
- @classmethod
43
- def _get(cls, name: str = "griffe") -> Logger:
44
- if name not in cls._instances:
45
- cls._instances[name] = cls(name)
46
- return cls._instances[name]
47
-
48
- @classmethod
49
- def _patch_loggers(cls, get_logger_func: Callable) -> None:
50
- # Patch current instances.
51
- for name, instance in cls._instances.items():
52
- instance._logger = get_logger_func(name)
53
-
54
- # Future instances will be patched as well.
55
- cls._default_logger = get_logger_func
56
-
57
-
58
- logger: Logger = Logger._get()
59
- """Our global logger, used throughout the library.
60
-
61
- Griffe's output and error messages are logging messages.
62
-
63
- Griffe provides the [`patch_loggers`][griffe.patch_loggers]
64
- function so dependent libraries can patch Griffe loggers as they see fit.
65
-
66
- For example, to fit in the MkDocs logging configuration
67
- and prefix each log message with the module name:
68
-
69
- ```python
70
- import logging
71
- from griffe import patch_loggers
72
-
73
-
74
- class LoggerAdapter(logging.LoggerAdapter):
75
- def __init__(self, prefix, logger):
76
- super().__init__(logger, {})
77
- self.prefix = prefix
78
-
79
- def process(self, msg, kwargs):
80
- return f"{self.prefix}: {msg}", kwargs
81
-
82
-
83
- def get_logger(name):
84
- logger = logging.getLogger(f"mkdocs.plugins.{name}")
85
- return LoggerAdapter(name, logger)
86
-
87
-
88
- patch_loggers(get_logger)
89
- ```
90
- """
91
-
92
-
93
- def get_logger(name: str = "griffe") -> Logger:
94
- """Create and return a new logger instance.
95
-
96
- Parameters:
97
- name: The logger name.
98
-
99
- Returns:
100
- The logger.
101
- """
102
- return Logger._get(name)
103
-
104
-
105
- def patch_loggers(get_logger_func: Callable[[str], Any]) -> None:
106
- """Patch Griffe logger and Griffe extensions' loggers.
107
-
108
- Parameters:
109
- get_logger_func: A function accepting a name as parameter and returning a logger.
110
- """
111
- Logger._patch_loggers(get_logger_func)