mkdocstrings-matlab 0.8.2__py3-none-any.whl → 0.9.1__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.
@@ -3,7 +3,7 @@
3
3
  from collections import defaultdict, deque
4
4
  from copy import copy, deepcopy
5
5
  from pathlib import Path
6
- from typing import Mapping, Sequence, Callable, TypeVar
6
+ from typing import Any, Mapping, Sequence, Callable, TypeVar
7
7
 
8
8
  from _griffe.collections import LinesCollection as GLC, ModulesCollection
9
9
  from _griffe.docstrings.models import (
@@ -716,9 +716,9 @@ class LazyModel:
716
716
  parent = None
717
717
  return parent
718
718
 
719
- def _collect_path(self, path: Path) -> MatlabMixin:
719
+ def _collect_path(self, path: Path, **kwargs: Any) -> MatlabMixin:
720
720
  file = FileParser(path)
721
- model = file.parse(path_collection=self._path_collection)
721
+ model = file.parse(path_collection=self._path_collection, **kwargs)
722
722
  self._lines_collection[path] = file.content.split("\n")
723
723
  return model
724
724
 
@@ -1,4 +1,23 @@
1
1
  from enum import Enum
2
+ from _griffe.enumerations import Kind as GriffeKind
3
+
4
+
5
+ class Kind(str, Enum):
6
+ """
7
+ An enumeration representing different kinds of MATLAB code elements.
8
+ This enumeration is a subclass of the Griffe `Kind` enumeration, and extends it with additional values.
9
+ """
10
+ MODULE = "module"
11
+ """Modules."""
12
+ CLASS = "class"
13
+ """Classes."""
14
+ FUNCTION = "function"
15
+ """Functions and methods."""
16
+ ATTRIBUTE = "attribute"
17
+ """Attributes and properties."""
18
+ ALIAS = "alias"
19
+ """Aliases (imported objects)."""
20
+ SCRIPT = "script"
2
21
 
3
22
 
4
23
  class ParameterKind(str, Enum):
@@ -193,7 +193,7 @@ class MatlabHandler(BaseHandler):
193
193
  config_path = None
194
194
  full_paths = []
195
195
  else:
196
- config_path = Path(config_file_path).parent
196
+ config_path = Path(config_file_path).resolve().parent
197
197
  full_paths = [(config_path / path).resolve() for path in paths]
198
198
 
199
199
  if pathIds := [str(path) for path in full_paths if not path.is_dir()]:
@@ -17,7 +17,7 @@ from griffe import (
17
17
  Parameter as GriffeParameter,
18
18
  )
19
19
 
20
- from mkdocstrings_handlers.matlab.enums import AccessEnum, ParameterKind
20
+ from mkdocstrings_handlers.matlab.enums import Kind, AccessEnum, ParameterKind
21
21
 
22
22
  if TYPE_CHECKING:
23
23
  from mkdocstrings_handlers.matlab.collect import PathCollection
@@ -151,6 +151,14 @@ class MatlabObject(Object):
151
151
  def namespaces(self) -> dict[str, "Namespace"]:
152
152
  return {}
153
153
 
154
+ @property
155
+ def scripts(self) -> dict[str, "Script"]:
156
+ return {name: member for name, member in self.all_members.items() if member.kind is Kind.SCRIPT} # type: ignore[misc]
157
+
158
+ @property
159
+ def is_script(self) -> bool:
160
+ return False
161
+
154
162
  @property
155
163
  def is_namespace(self) -> bool:
156
164
  return False
@@ -280,9 +288,15 @@ class Script(MatlabMixin, PathMixin, MatlabObject):
280
288
  This class inherits from `PathMixin` and `MatlabObject` to provide
281
289
  functionality specific to MATLAB scripts.
282
290
  """
291
+ kind = Kind.SCRIPT # type: ignore
283
292
 
284
- pass
293
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
294
+ super().__init__(*args, **kwargs)
295
+ self.extra["mkdocstrings"] = {"template": "script.html.jinja"}
285
296
 
297
+ @property
298
+ def is_script(self) -> bool:
299
+ return True
286
300
 
287
301
  class Class(MatlabMixin, PathMixin, GriffeClass, MatlabObject):
288
302
  """
@@ -442,13 +456,9 @@ class Property(MatlabMixin, Attribute, MatlabObject):
442
456
  @property
443
457
  def Private(self) -> bool:
444
458
  private = self.Access != AccessEnum.public
445
- set_private = (
446
- self.SetAccess != AccessEnum.public
447
- and self.SetAccess != AccessEnum.immutable
448
- )
449
459
  get_private = self.GetAccess != AccessEnum.public
450
- return private or set_private or get_private
451
-
460
+ return private or get_private
461
+
452
462
  @property
453
463
  def is_private(self) -> bool:
454
464
  return self.Private or self.Hidden
@@ -99,6 +99,27 @@ Context:
99
99
  {% endif %}
100
100
  {% endwith %}
101
101
 
102
+ {% if obj.is_module %}
103
+ {% with scripts = obj.scripts|filter_objects(
104
+ filters=config.filters,
105
+ members_list=members_list,
106
+ keep_no_docstrings=config.show_if_no_docstring,
107
+ ) %}
108
+ {% if scripts %}
109
+ {% if config.show_category_heading %}
110
+ {% filter heading(heading_level, id=html_id ~ "-scripts") %}Scripts{% endfilter %}
111
+ {% endif %}
112
+ {% with heading_level = heading_level + extra_level %}
113
+ {% for script in scripts|order_members(config.members_order.alphabetical, members_list) %}
114
+ {% if members_list is not none or (not script.is_alias or script.is_public) %}
115
+ {% include script|get_template with context %}
116
+ {% endif %}
117
+ {% endfor %}
118
+ {% endwith %}
119
+ {% endif %}
120
+ {% endwith %}
121
+ {% endif %}
122
+
102
123
  {% if config.show_subnamespaces or obj.is_folder %}
103
124
  {% with modules = obj.modules|filter_objects(
104
125
  filters=config.filters,
@@ -0,0 +1,137 @@
1
+ {#- Template for MATLAB scripts.
2
+
3
+ This template renders a MATLAB script.
4
+
5
+ Context:
6
+ script (mkdocstrings_handlers.matlab.models.Script): The Script to render.
7
+ root (bool): Whether this is the root object, injected with `:::` in a Markdown page.
8
+ heading_level (int): The HTML heading level to use.
9
+ config (dict): The configuration options.
10
+ -#}
11
+
12
+ {% block logs scoped %}
13
+ {#- Logging block.
14
+
15
+ This block can be used to log debug messages, deprecation messages, warnings, etc.
16
+ -#}
17
+ {{ log.debug("Rendering " + script.path) }}
18
+ {% endblock logs %}
19
+
20
+ <div class="doc doc-object doc-function">
21
+ {% with obj = script, html_id = script.path %}
22
+
23
+ {% if root %}
24
+ {% set show_full_path = config.show_root_full_path %}
25
+ {% set root_members = True %}
26
+ {% elif root_members %}
27
+ {% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %}
28
+ {% set root_members = False %}
29
+ {% else %}
30
+ {% set show_full_path = config.show_object_full_path %}
31
+ {% endif %}
32
+
33
+ {% set script_name = script.path if show_full_path else script.name %}
34
+
35
+ {% if not root or config.show_root_heading %}
36
+ {% filter heading(
37
+ heading_level,
38
+ role="function",
39
+ id=html_id,
40
+ class="doc doc-heading",
41
+ toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-script"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + script.name,
42
+ ) %}
43
+
44
+ {% block heading scoped %}
45
+ {#- Heading block.
46
+
47
+ This block renders the heading for the function.
48
+ -#}
49
+ {% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-script"></code>{% endif %}
50
+ {% if config.separate_signature %}
51
+ <span class="doc doc-object-name doc-function-name">{{ script_name }}</span>
52
+ {% else %}
53
+ {%+ filter highlight(language="matlab", inline=True) %}
54
+ {{ script_name }}
55
+ {% endfilter %}
56
+ {% endif %}
57
+ {% endblock heading %}
58
+
59
+ {% block labels scoped %}
60
+ {#- Labels block.
61
+
62
+ This block renders the labels for the script.
63
+ -#}
64
+ {% with labels = script.labels %}
65
+ {% include "labels"|get_template with context %}
66
+ {% endwith %}
67
+ {% endblock labels %}
68
+
69
+ {% endfilter %}
70
+
71
+ {% block signature scoped %}
72
+ {#- Signature block.
73
+
74
+ This block renders the signature for the script.
75
+ -#}
76
+ {% if config.separate_signature %}
77
+ {% filter format_signature(script, config.line_length, crossrefs=config.signature_crossrefs) %}
78
+ {{ script.name }}
79
+ {% endfilter %}
80
+ {% endif %}
81
+ {% endblock signature %}
82
+
83
+ {% else %}
84
+
85
+ {% if config.show_root_toc_entry %}
86
+ {% filter heading(heading_level,
87
+ role="function",
88
+ id=html_id,
89
+ toc_label=('<code class="doc-symbol doc-symbol-toc doc-symbol-script"></code>&nbsp;'|safe if config.show_symbol_type_toc else '') + script.name,
90
+ hidden=True,
91
+ ) %}
92
+ {% endfilter %}
93
+ {% endif %}
94
+ {% set heading_level = heading_level - 1 %}
95
+ {% endif %}
96
+
97
+ <div class="doc doc-contents {% if root %}first{% endif %}">
98
+ {% block contents scoped %}
99
+ {#- Contents block.
100
+
101
+ This block renders the contents of the script.
102
+ It contains other blocks that users can override.
103
+ Overriding the contents block allows to rearrange the order of the blocks.
104
+ -#}
105
+ {% block docstring scoped %}
106
+ {#- Docstring block.
107
+
108
+ This block renders the docstring for the script.
109
+ -#}
110
+ {% with docstring_sections = script.docstring.parsed %}
111
+ {% include "docstring"|get_template with context %}
112
+ {% endwith %}
113
+ {% endblock docstring %}
114
+
115
+ {% block source scoped %}
116
+ {#- Source block.
117
+
118
+ This block renders the source code for the script.
119
+ -#}
120
+ {% if config.show_source and script.source %}
121
+ <details class="quote">
122
+ <summary>{{ lang.t("Source code in") }} <code>
123
+ {%- if script.relative_filepath.is_absolute() -%}
124
+ {{ script.relative_package_filepath }}
125
+ {%- else -%}
126
+ {{ script.relative_filepath }}
127
+ {%- endif -%}
128
+ </code></summary>
129
+ {{ script.source|highlight(language="python", linestart=script.lineno or 0, linenums=True) }}
130
+ </details>
131
+ {% endif %}
132
+ {% endblock source %}
133
+ {% endblock contents %}
134
+ </div>
135
+
136
+ {% endwith %}
137
+ </div>
@@ -24,3 +24,12 @@ code.doc-symbol-property {
24
24
  code.doc-symbol-property::after {
25
25
  content: "prop";
26
26
  }
27
+
28
+ code.doc-symbol-script {
29
+ color: #d0bf3d;
30
+ background-color: #96862f27;
31
+ }
32
+
33
+ code.doc-symbol-script::after {
34
+ content: "script";
35
+ }
@@ -46,7 +46,7 @@ FUNCTION_QUERY = LANGUAGE.query("""(function_definition .
46
46
  [
47
47
  (identifier) @output
48
48
  (multioutput_variable .
49
- ((identifier) @output (",")?)+
49
+ ((identifier) @output (",")?)*
50
50
  )
51
51
  ]
52
52
  )? .
@@ -68,6 +68,7 @@ ARGUMENTS_QUERY = LANGUAGE.query("""(arguments_statement .
68
68
  (attributes
69
69
  (identifier) @attributes
70
70
  )? .
71
+ (comment)? .
71
72
  ("\\n")? .
72
73
  (property)+ @arguments
73
74
  )""")
@@ -165,7 +166,7 @@ def _dedent(lines: list[str]) -> list[str]:
165
166
  list[str]: A list of strings with the common leading whitespace removed from each line.
166
167
  """
167
168
  indents = [len(line) - len(line.lstrip()) for line in lines if line.strip()]
168
- indent = min(indents)
169
+ indent = min(indents) if indents else 0
169
170
  if indent == 0:
170
171
  return lines
171
172
  else:
@@ -208,7 +209,7 @@ class FileParser(object):
208
209
  """
209
210
  return self._content.decode(self.encoding)
210
211
 
211
- def parse(self, **kwargs) -> MatlabMixin:
212
+ def parse(self, **kwargs: Any) -> MatlabMixin:
212
213
  """
213
214
  Parse the content of the file and return a MatlabMixin.
214
215
 
@@ -246,7 +247,7 @@ class FileParser(object):
246
247
 
247
248
  return model
248
249
 
249
- def _parse_class(self, node: Node, **kwargs) -> Class:
250
+ def _parse_class(self, node: Node, **kwargs: Any) -> Class:
250
251
  """
251
252
  Parse a class node and return a Class or Classfolder model.
252
253
 
@@ -412,7 +413,7 @@ class FileParser(object):
412
413
 
413
414
  return (key, value)
414
415
 
415
- def _parse_function(self, node: Node, method: bool = False, **kwargs) -> Function:
416
+ def _parse_function(self, node: Node, method: bool = False, **kwargs: Any) -> Function:
416
417
  """
417
418
  Parse a function node and return a Function model.
418
419
 
@@ -592,6 +593,12 @@ class FileParser(object):
592
593
  if nodes is None:
593
594
  return None
594
595
  elif isinstance(nodes, list):
596
+
597
+ # Ensure that if there is a gap between subsequent comment nodes, only the first block is considered
598
+ if gaps := (end.start_point.row - start.end_point.row for (start, end) in zip(nodes[:-1], nodes[1:])):
599
+ first_gap_index = next((i for i, gap in enumerate(gaps) if gap > 1), None)
600
+ nodes = nodes[:first_gap_index+1] if first_gap_index is not None else nodes
601
+
595
602
  lineno = nodes[0].range.start_point.row + 1
596
603
  endlineno = nodes[-1].range.end_point.row + 1
597
604
  lines = iter(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocstrings-matlab
3
- Version: 0.8.2
3
+ Version: 0.9.1
4
4
  Summary: A MATLAB handler for mkdocstrings
5
5
  Author-email: Mark Hu <watermarkhu@gmail.com>
6
6
  License: MIT
@@ -1,21 +1,22 @@
1
1
  mkdocstrings_handlers/matlab/__init__.py,sha256=w5R9cGtqeJF0GUP_Jc_ad8FnS4FpbutnmHvzVRlohPM,1124
2
- mkdocstrings_handlers/matlab/collect.py,sha256=a2ZLBpSmkfwc7uG63dnV36Y7gvnrwvmFK7Gihggn2hc,29647
3
- mkdocstrings_handlers/matlab/enums.py,sha256=lr3wLlhPxyBym3O7Rt0cLUZYqPCz6wQ2PYBibLKLTek,982
4
- mkdocstrings_handlers/matlab/handler.py,sha256=kHyBrHTvZJBXVgondNcbjyeRna0pMmfCnIDVk7ru3oQ,19708
5
- mkdocstrings_handlers/matlab/models.py,sha256=MqLZNL3um0yEeFSzv-xjzwjFpOyCdx7elyZ4X1ZV-yE,19228
2
+ mkdocstrings_handlers/matlab/collect.py,sha256=6GkAwKor11Hm9QvKr6cKSHuylpoMF4Y3c8_myKiYOdE,29677
3
+ mkdocstrings_handlers/matlab/enums.py,sha256=Lzc8MLar-uMoKplT5LxF1lXNBfjHc9MCTe2b0mJMc10,1540
4
+ mkdocstrings_handlers/matlab/handler.py,sha256=5EK559dDElhNI9owKmia72Nl02MBULUaa1Dd-zCCeSE,19718
5
+ mkdocstrings_handlers/matlab/models.py,sha256=2kMF7dyg5nPAzJt9G48IVtNAAq8K6xyKCBDDZHOBtUQ,19614
6
6
  mkdocstrings_handlers/matlab/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- mkdocstrings_handlers/matlab/treesitter.py,sha256=FkWGuH7EmE_aO2qub5-_NnOVacYeXW353SkB7cNMlRo,21820
8
- mkdocstrings_handlers/matlab/templates/material/children.html.jinja,sha256=61OLBlQw3SaRscBkN7hVpbuSX2Bo7I0j_F581eDAUn8,6462
7
+ mkdocstrings_handlers/matlab/treesitter.py,sha256=mpYNAoIU_nxvyisYLYzXllKjWKUKu0pkk8_e3RqVNaE,22284
8
+ mkdocstrings_handlers/matlab/templates/material/children.html.jinja,sha256=xF_J8afiIciWTP1GBhGAGWXe36wl0zJBKCwa2uDQFbU,7409
9
9
  mkdocstrings_handlers/matlab/templates/material/folder.html.jinja,sha256=cWgaQH4EDFgL3eEIv0NRwRXYvtn9pp4tW7ntv3X2nM8,4076
10
10
  mkdocstrings_handlers/matlab/templates/material/namespace.html.jinja,sha256=a7Ya3YuN3hNEvqb_aG5Yr3QCuFYv6UhX5B26Gx2-tUQ,4099
11
11
  mkdocstrings_handlers/matlab/templates/material/property.html.jinja,sha256=anYCQM6AcyGgEApDC97TqzWlgVNtc1I_Ys1xyvUXye0,4396
12
- mkdocstrings_handlers/matlab/templates/material/style.css,sha256=0_Bs5_0fHM3X9l-IU1VHbZfhNA7nUw4SKEH_3zRhCDw,557
12
+ mkdocstrings_handlers/matlab/templates/material/script.html.jinja,sha256=6bl-F1zDgBwgRaL76SFa_zyjKgyooofde6Vnq56DKso,4746
13
+ mkdocstrings_handlers/matlab/templates/material/style.css,sha256=nCtnnMjJyDp6u2dZMRs4DIDTjmRdlS9oM2YdSMluVh0,690
13
14
  mkdocstrings_handlers/matlab/templates/material/summary.html.jinja,sha256=hVbQGxbMWd6fl01afbg0LhfYCJD1IRPmmCdcDBxU650,735
14
15
  mkdocstrings_handlers/matlab/templates/material/docstring/namespaces.html.jinja,sha256=jLtPxNNfZFO3-Ozy0eHqxHvKmlPCODML_5xt8SJr8UE,3165
15
16
  mkdocstrings_handlers/matlab/templates/material/docstring/properties.html.jinja,sha256=9ckdYymLlB5sflwYEaEPAQLJuVWF8nezMCV5JnanXVA,4165
16
17
  mkdocstrings_handlers/matlab/templates/material/summary/namespaces.html.jinja,sha256=0vVlUB6oh-A7cpXbuDLOQLxTubyb_DisdOKm062WNMs,650
17
18
  mkdocstrings_handlers/matlab/templates/material/summary/properties.html.jinja,sha256=nyPaELf9qPCxJQFxK1MWYK4fPwsk5VESh9xKHLtd-XE,643
18
- mkdocstrings_matlab-0.8.2.dist-info/METADATA,sha256=HXy7oTcI9VTg2cvY-OduEv9ugM4wyqeobHEgVLkkC_s,4736
19
- mkdocstrings_matlab-0.8.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
20
- mkdocstrings_matlab-0.8.2.dist-info/licenses/LICENSE,sha256=TZQpwBuA3KLH56--XDAY2Qwo9gGdxeTITYhMOylmYhg,743
21
- mkdocstrings_matlab-0.8.2.dist-info/RECORD,,
19
+ mkdocstrings_matlab-0.9.1.dist-info/METADATA,sha256=nGcZZuakb88AhvWVFsfaDaZcr5pJJ7vYVGJUTa2a_Xw,4736
20
+ mkdocstrings_matlab-0.9.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
21
+ mkdocstrings_matlab-0.9.1.dist-info/licenses/LICENSE,sha256=TZQpwBuA3KLH56--XDAY2Qwo9gGdxeTITYhMOylmYhg,743
22
+ mkdocstrings_matlab-0.9.1.dist-info/RECORD,,