mkdocstrings-matlab 0.1.0__py2.py3-none-any.whl → 0.1.1__py2.py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,11 +12,29 @@ import json
12
12
 
13
13
 
14
14
  from mkdocstrings_handlers.matlab_engine import MatlabEngine, MatlabExecutionError
15
- from mkdocstrings_handlers.matlab.models import Function, Class, Classfolder, Namespace, Property
15
+ from mkdocstrings_handlers.matlab.models import (
16
+ Function,
17
+ Class,
18
+ Classfolder,
19
+ Namespace,
20
+ Property,
21
+ ROOT
22
+ )
16
23
 
17
24
 
18
- ROOT_NAMESPACE = Namespace("", filepath="")
19
- MODELS = {}
25
+ class _ModelsStorage:
26
+ def __init__(self):
27
+ self._namespace = ""
28
+ self._models = {}
29
+
30
+ def __getitem__(self, key):
31
+ return self._models[key]
32
+
33
+ def __setitem__(self, key, value):
34
+ self._models[key] = value
35
+
36
+ def __contains__(self, key):
37
+ return key in self._models
20
38
 
21
39
 
22
40
  class MatlabHandler(BaseHandler):
@@ -71,8 +89,8 @@ class MatlabHandler(BaseHandler):
71
89
  # Member options
72
90
  "inherited_members": False,
73
91
  "members": None,
74
- "members_order": rendering.Order.alphabetical.value,
75
- "filters": ["!^_[^_]"],
92
+ "members_order": rendering.Order.alphabetical,
93
+ "filters": [],
76
94
  "group_by_category": True,
77
95
  "show_submodules": False,
78
96
  "summary": False,
@@ -102,7 +120,7 @@ class MatlabHandler(BaseHandler):
102
120
  "show_signature": True,
103
121
  "show_signature_annotations": False,
104
122
  "signature_crossrefs": False,
105
- "separate_signature": True,
123
+ "separate_signature": False,
106
124
  "unwrap_annotated": False,
107
125
  "modernize_annotations": False,
108
126
  }
@@ -124,6 +142,7 @@ class MatlabHandler(BaseHandler):
124
142
  self.engine = MatlabEngine()
125
143
  self.engine.addpath(str(Path(__file__).parent / "matlab"))
126
144
  self.engine.matlab_startup(paths, startup_expression)
145
+ self.models = _ModelsStorage()
127
146
  self._locale = locale
128
147
 
129
148
  def get_templates_dir(self, handler: str | None = None) -> Path:
@@ -145,6 +164,9 @@ class MatlabHandler(BaseHandler):
145
164
  CollectorItem
146
165
  """
147
166
  final_config = ChainMap(config, self.default_config) # type: ignore[arg-type]
167
+ if identifier in self.models:
168
+ return self.models[identifier]
169
+
148
170
  try:
149
171
  ast_json = self.engine.docstring.resolve(identifier)
150
172
  except MatlabExecutionError as error:
@@ -152,10 +174,8 @@ class MatlabHandler(BaseHandler):
152
174
  ast_dict = json.loads(ast_json)
153
175
 
154
176
  match ast_dict["type"]:
155
- case "function":
156
- return collect_function(ast_dict, final_config)
157
- case "method":
158
- return collect_function(ast_dict, final_config)
177
+ case "function" | "method":
178
+ return self.collect_function(ast_dict, final_config)
159
179
  case "class":
160
180
  return self.collect_class(ast_dict, final_config)
161
181
  case _:
@@ -229,25 +249,24 @@ class MatlabHandler(BaseHandler):
229
249
  lambda template_name: template_name in self.env.list_templates()
230
250
  )
231
251
 
232
-
233
252
  def collect_class(self, ast_dict: dict, config: Mapping) -> Class:
234
253
  docstring = (
235
254
  Docstring(ast_dict["docstring"], parser=config["docstring_style"])
236
255
  if ast_dict["docstring"]
237
256
  else None
238
257
  )
239
- object = Class(
258
+ model = Class(
240
259
  ast_dict["name"],
241
260
  docstring=docstring,
242
- parent=get_parent(Path(ast_dict["path"]).parent),
261
+ parent=self.get_parent(Path(ast_dict["path"]).parent),
243
262
  hidden=ast_dict["hidden"],
244
263
  sealed=ast_dict["sealed"],
245
264
  abstract=ast_dict["abstract"],
246
265
  enumeration=ast_dict["enumeration"],
247
266
  handle=ast_dict["handle"],
267
+ filepath=Path(ast_dict["path"]),
248
268
  )
249
269
 
250
-
251
270
  for property_dict in ast_dict["properties"]:
252
271
  name = property_dict.pop("name")
253
272
  defining_class = property_dict.pop("class")
@@ -257,92 +276,111 @@ class MatlabHandler(BaseHandler):
257
276
  if property_doc
258
277
  else None
259
278
  )
260
- if defining_class != object.canonical_path and not config["inherited_members"]:
279
+ if (
280
+ defining_class != model.canonical_path
281
+ and not config["inherited_members"]
282
+ ):
261
283
  continue
262
284
 
263
- object.members[name] = Property(name, docstring=docstring, **property_dict)
285
+ prop = Property(name, docstring=docstring, parent=model, **property_dict)
286
+ model.members[name] = prop
287
+ self.models[prop.canonical_path] = prop
264
288
 
265
289
  for method_dict in ast_dict["methods"]:
266
290
  name = method_dict.pop("name")
267
291
  defining_class = method_dict.pop("class")
268
- if defining_class != object.canonical_path and not config["inherited_members"]:
292
+ if (
293
+ defining_class != model.canonical_path
294
+ and not config["inherited_members"]
295
+ ):
269
296
  continue
270
-
297
+
271
298
  method = self.collect(f"{defining_class}.{name}", config)
299
+ method.parent = model
272
300
  method._access = method_dict["access"]
273
301
  method._static = method_dict["static"]
274
302
  method._abstract = method_dict["abstract"]
275
303
  method._sealed = method_dict["sealed"]
276
304
  method._hidden = method_dict["hidden"]
305
+ model.members[name] = method
306
+ self.models[method.canonical_path] = method
277
307
 
278
- object.members[name] = method
308
+ if config["merge_init_into_class"] and model.name in model.members:
309
+ constructor = model.members.pop(model.name)
310
+ model.members["__init__"] = constructor
311
+ if constructor.docstring.value == model.docstring.value:
312
+ model.docstring = None
279
313
 
280
- return object
281
-
282
- def get_parent(path: Path) -> Namespace | Classfolder:
283
- if path.stem[0] == "+":
284
- if path in MODELS:
285
- parent = MODELS[path]
286
- else:
287
- parent = Namespace(
288
- path.stem[1:], filepath=str(path), parent=get_parent(path.parent)
289
- )
290
- MODELS[path] = parent
291
- elif path.stem[0] == "@":
292
- if path in MODELS:
293
- parent = MODELS[path]
294
- else:
295
- parent = Classfolder(
296
- path.stem[1:], filepath=str(path), parent=get_parent(path.parent)
297
- )
298
- MODELS[path] = parent
299
- else:
300
- parent = ROOT_NAMESPACE
301
- return parent
314
+ self.models[model.canonical_path] = model
302
315
 
316
+ return model
303
317
 
318
+ def collect_function(self, ast_dict: dict, config: Mapping) -> Function:
319
+ parameters = []
304
320
 
321
+ inputs = (
322
+ ast_dict["inputs"]
323
+ if isinstance(ast_dict["inputs"], list)
324
+ else [ast_dict["inputs"]]
325
+ )
326
+ for input_dict in inputs:
327
+ if input_dict["name"] == "varargin":
328
+ parameter_kind = ParameterKind.var_positional
329
+ elif input_dict["kind"] == "positional":
330
+ parameter_kind = ParameterKind.positional_only
331
+ else:
332
+ parameter_kind = ParameterKind.keyword_only
333
+
334
+ parameters.append(
335
+ Parameter(
336
+ input_dict["name"],
337
+ kind=parameter_kind,
338
+ annotation=input_dict["class"],
339
+ default=input_dict["default"] if input_dict["default"] else None,
340
+ )
341
+ )
305
342
 
343
+ model = Function(
344
+ ast_dict["name"],
345
+ parameters=Parameters(*parameters),
346
+ docstring=Docstring(
347
+ ast_dict["docstring"],
348
+ parser=config["docstring_style"],
349
+ parser_options=config["docstring_options"],
350
+ )
351
+ if ast_dict["docstring"]
352
+ else None,
353
+ parent=self.get_parent(Path(ast_dict["path"]).parent),
354
+ filepath=Path(ast_dict["path"]),
355
+ )
306
356
 
307
- def collect_function(ast_dict: dict, config: Mapping) -> Function:
308
- parameters = []
357
+ self.models[model.canonical_path] = model
358
+ return model
309
359
 
310
- inputs = (
311
- ast_dict["inputs"]
312
- if isinstance(ast_dict["inputs"], list)
313
- else [ast_dict["inputs"]]
314
- )
315
- for input_dict in inputs:
316
- if input_dict["name"] == "varargin":
317
- parameter_kind = ParameterKind.var_positional
318
- elif input_dict["kind"] == "positional":
319
- parameter_kind = ParameterKind.positional_only
320
- else:
321
- parameter_kind = ParameterKind.keyword_only
322
-
323
- parameters.append(
324
- Parameter(
325
- input_dict["name"],
326
- kind=parameter_kind,
327
- annotation=input_dict["class"],
328
- default=input_dict["default"] if input_dict["default"] else None,
360
+ def get_parent(self, path: Path) -> Namespace | Classfolder:
361
+ if path.stem[0] == "+":
362
+ parent = Namespace(
363
+ path.stem[1:], filepath=path, parent=self.get_parent(path.parent)
329
364
  )
330
- )
365
+ identifier = parent.canonical_path
366
+ if identifier in self.models:
367
+ parent = self.models[identifier]
368
+ else:
369
+ self.models[identifier] = parent
331
370
 
332
- func = Function(
333
- ast_dict["name"],
334
- parameters=Parameters(*parameters),
335
- docstring=Docstring(
336
- ast_dict["docstring"],
337
- parser=config["docstring_style"],
338
- parser_options=config["docstring_options"],
339
- )
340
- if ast_dict["docstring"]
341
- else None,
342
- parent=get_parent(Path(ast_dict["path"]).parent),
343
- )
371
+ elif path.stem[0] == "@":
372
+ parent = Classfolder(
373
+ path.stem[1:], filepath=path, parent=self.get_parent(path.parent)
374
+ )
375
+ identifier = parent.canonical_path
376
+ if identifier in self.models:
377
+ parent = self.models[identifier]
378
+ else:
379
+ self.models[identifier] = parent
344
380
 
345
- return func
381
+ else:
382
+ parent = ROOT
383
+ return parent
346
384
 
347
385
 
348
386
  def get_handler(
@@ -17,12 +17,21 @@ function data = argument(object)
17
17
  data.kind = string(object.Kind);
18
18
  data.presence = string(object.Presence);
19
19
 
20
- if isempty(object.DefaultValue)
20
+ if contains(data.presence, ["required", "unspecified"])
21
21
  data.default = "";
22
- elseif object.DefaultValue.IsConstant
23
- data.default = string(object.DefaultValue.Value);
24
22
  else
25
- data.default = "*expression*";
23
+ if ~isempty(object.DefaultValue) && object.DefaultValue.IsConstant
24
+ value = object.DefaultValue.Value;
25
+ if strcmp(value, "")
26
+ data.default = """""";
27
+ elseif isstring(value) || ischar(value)
28
+ data.default = sprintf("'%s'", value);
29
+ else
30
+ data.default = string(value);
31
+ end
32
+ else
33
+ data.default = "...";
34
+ end
26
35
  end
27
36
 
28
37
  if ~isempty(object.Validation)
@@ -7,7 +7,7 @@ function data = class(object)
7
7
  namespaces = split(object.Name, '.');
8
8
  data.name = namespaces{end};
9
9
 
10
- data.docstring = docstring.utils.parse_doc(object, true);
10
+ data.docstring = docstring.utils.parse_doc(object);
11
11
  data.path = matlab.internal.metafunction(object.Name).Location;
12
12
  data.hidden = object.Hidden;
13
13
  data.sealed = object.Sealed;
@@ -24,7 +24,11 @@ function data = class(object)
24
24
  else
25
25
  method.name = string(methodObject.Name);
26
26
  method.class = string(methodObject.DefiningClass.Name);
27
- method.access = methodObject.Access;
27
+ if iscell(methodObject.Access)
28
+ method.access = "private";
29
+ else
30
+ method.access = methodObject.Access;
31
+ end
28
32
  method.static = methodObject.Static;
29
33
  method.abstract = methodObject.Abstract;
30
34
  method.sealed = methodObject.Sealed;
@@ -1,4 +1,4 @@
1
- function data = argument(object)
1
+ function data = property(object)
2
2
  arguments
3
3
  object (1,:) meta.property
4
4
  end
@@ -6,8 +6,17 @@ function data = argument(object)
6
6
  data.name = string(object.Name);
7
7
  data.class = string(object.DefiningClass.Name);
8
8
  data.docstring = docstring.utils.parse_doc(object);
9
- data.get_access = object.GetAccess;
10
- data.set_access = object.SetAccess;
9
+
10
+ if iscell(object.GetAccess)
11
+ data.get_access = 'private';
12
+ else
13
+ data.get_access = object.GetAccess;
14
+ end
15
+ if iscell(object.SetAccess)
16
+ data.set_access = 'private';
17
+ else
18
+ data.set_access = object.SetAccess;
19
+ end
11
20
  data.dependent = object.Dependent;
12
21
  data.constant = object.Constant;
13
22
  data.abstract = object.Abstract;
@@ -2,10 +2,10 @@ function doc = parse_doc(object, combine)
2
2
 
3
3
  arguments
4
4
  object (1,1) matlab.metadata.MetaData
5
- combine (1,1) logical = false
5
+ combine (1,1) logical = true
6
6
  end
7
7
 
8
- if isempty(object.DetailedDescription)
8
+ if isempty(object.DetailedDescription) || strcmp(object.DetailedDescription, "")
9
9
  doc = object.Description;
10
10
  else
11
11
  if combine
@@ -2,6 +2,7 @@ from enum import Enum
2
2
  from typing import Any
3
3
  from griffe import Function as GriffeFunction, Class as GriffeClass, Module, Attribute
4
4
  from _griffe.exceptions import BuiltinModuleError
5
+ from pathlib import Path
5
6
 
6
7
 
7
8
  class Access(Enum):
@@ -18,12 +19,22 @@ class CanonicalPathMixin:
18
19
 
19
20
  The canonical path is the path where the object was defined (not imported).
20
21
  """
21
- if self.parent is None or self.parent.path == "":
22
+ if isinstance(self.parent, _Root):
22
23
  return self.name
23
24
  return f"{self.parent.path}.{self.name}"
24
25
 
25
26
 
26
- class Class(CanonicalPathMixin, GriffeClass):
27
+ class PathMixin:
28
+ def __init__(self, *args: Any, filepath: Path | None = None, **kwargs: Any) -> None:
29
+ self._filepath: Path | None = filepath
30
+ super().__init__(*args, **kwargs)
31
+
32
+ @property
33
+ def filepath(self) -> Path | None:
34
+ return self._filepath
35
+
36
+
37
+ class Class(CanonicalPathMixin, PathMixin, GriffeClass):
27
38
  def __init__(
28
39
  self,
29
40
  *args: Any,
@@ -96,7 +107,7 @@ class Property(CanonicalPathMixin, Attribute):
96
107
  return (set_public or get_public) and not self._hidden
97
108
 
98
109
 
99
- class Function(CanonicalPathMixin, GriffeFunction):
110
+ class Function(CanonicalPathMixin, PathMixin, GriffeFunction):
100
111
  def __init__(self, *args: Any, **kwargs: Any) -> None:
101
112
  super().__init__(*args, **kwargs)
102
113
  self._access: Access = Access.PUBLIC
@@ -111,17 +122,30 @@ class Function(CanonicalPathMixin, GriffeFunction):
111
122
  return public and not self._hidden
112
123
 
113
124
 
114
- class Namespace(CanonicalPathMixin, Module):
125
+ class Namespace(CanonicalPathMixin, PathMixin, Module):
126
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
127
+ super().__init__(*args, **kwargs)
128
+ self._access: Access = Access.PUBLIC
129
+
130
+ def __repr__(self) -> str:
131
+ return f"Namespace({self.path!r})"
132
+
133
+
134
+ class _Root(Namespace):
135
+ def __init__(self) -> None:
136
+ super().__init__("ROOT", parent=None)
137
+
115
138
  def __repr__(self) -> str:
116
- try:
117
- return f"Namespace({self.filepath!r})"
118
- except BuiltinModuleError:
119
- return f"Namespace({self.name!r})"
139
+ return "MATLABROOT"
140
+
141
+
142
+ ROOT = _Root()
120
143
 
121
144
 
122
- class Classfolder(CanonicalPathMixin, Module):
145
+ class Classfolder(Class):
123
146
  def __repr__(self) -> str:
124
- try:
125
- return f"Classfolder({self.filepath!r})"
126
- except BuiltinModuleError:
127
- return f"Classfolder({self.name!r})"
147
+ return f"Classfolder({self.path!r})"
148
+
149
+
150
+
151
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: mkdocstrings-matlab
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Add your description here
5
5
  Author-email: Mark Hu <mark.hu@asml.com>
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  mkdocstrings_handlers/matlab/__init__.py,sha256=laA2bEP5rxdIWBLmfLiKKu7ChZ_HzCe-VeRvxmUTqww,128
2
- mkdocstrings_handlers/matlab/handler.py,sha256=GuFjY7Jrv9QnHZELWghzAXEBf6Z67xvYr7aLPxMGvAg,14294
3
- mkdocstrings_handlers/matlab/models.py,sha256=-k5V6Usho9D8KAynvEnMz7B6Fyrf1TrkJ1P8NhRdyzQ,3997
2
+ mkdocstrings_handlers/matlab/handler.py,sha256=078JkZgLNGIbTmGGhzQfKWjPLdw79Jf1d9Vj_hG6rgY,15721
3
+ mkdocstrings_handlers/matlab/models.py,sha256=9oK-ZmpQuU2cU2wX8wlaK540BB9LazzaCtTmnnnIDyo,4428
4
4
  mkdocstrings_handlers/matlab/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  mkdocstrings_handlers/matlab/matlab/matlab_startup.m,sha256=rGXiR8fI2GW7yWmHxgzE5Un66n5ws3ogYnMvS2oWO8U,464
6
6
  mkdocstrings_handlers/matlab/matlab/+docstring/exception.m,sha256=sj2ycqMpknn_OG5A5X_b5e4WcAoR2oPoqNnDEHJsi7c,222
@@ -10,16 +10,16 @@ mkdocstrings_handlers/matlab/matlab/+docstring/+case/class.m,sha256=MXeRhQibRQSO
10
10
  mkdocstrings_handlers/matlab/matlab/+docstring/+case/func.m,sha256=QneDYSICtXqdPNq8sYNieirXUisuDKRM9rxPx-0osDU,137
11
11
  mkdocstrings_handlers/matlab/matlab/+docstring/+case/method.m,sha256=Bw8Mb96OP7-AnbGnvRMySOIbYSTtEC1BGBnqHMEIhsM,165
12
12
  mkdocstrings_handlers/matlab/matlab/+docstring/+case/namespace.m,sha256=ZpYrgZHLIdGvgg3F6210gDTska9YyASn63ZVYkBq41A,667
13
- mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/argument.m,sha256=l6UIQ4uolz533vo5DDWxl0R5PRkbb6hpRxpMPu5SNm8,1583
14
- mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/class.m,sha256=KurAMy-D_-47CYCdrqvzlSDXIl_dB2gwIQPLzjai35s,1542
13
+ mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/argument.m,sha256=xfshXZas8h0oZ2od5b6hW_f4_-u_XmiJSS52XiAOaC4,1906
14
+ mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/class.m,sha256=NjJxS1Kn5Bhbfk_W-0ySs3gJ5ImrEClkns8w7Fs-g9E,1659
15
15
  mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/func.m,sha256=urjYQauSRZ9bXg4co4gurOmiKzj5Sc4IS8FRKU8eEHM,408
16
16
  mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/namespace.m,sha256=kMzfAoWIpMXH76rrkyUqauJSRIaylsfnu0Cds4pYnJc,481
17
- mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/property.m,sha256=Ro5jciF60k8YRjJ_GWSm0kJNVZPfh4kyyLvYOwhrL2o,1379
17
+ mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/property.m,sha256=rH3cHz66ZG9sUvDU2fhlyASSB_yp0SiHlbpB44fcFiY,1560
18
18
  mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/script.m,sha256=pmuazWBqlugNEEojfQFkAg1ioErizoiEZ9RcFXecCP4,329
19
19
  mkdocstrings_handlers/matlab/matlab/+docstring/+utils/dedent.m,sha256=r02mWQkRP9uuoEl-f-02h1-ja17a_29LTeyJvK-kazI,669
20
20
  mkdocstrings_handlers/matlab/matlab/+docstring/+utils/get_namespace_path.m,sha256=4NlQ7-RjqIFZAn6P-9JzCrm2FvfGRKiM2M_leINj9i4,835
21
- mkdocstrings_handlers/matlab/matlab/+docstring/+utils/parse_doc.m,sha256=z1voyYnASblb2i98n4dySOmBIbCa3n9moQKtbR5WE-k,442
22
- mkdocstrings_matlab-0.1.0.dist-info/METADATA,sha256=R5KTt_IHagwweU_hC78Od6DXPiTfNOkE6S0IiDqqNeU,457
23
- mkdocstrings_matlab-0.1.0.dist-info/WHEEL,sha256=fl6v0VwpzfGBVsGtkAkhILUlJxROXbA3HvRL6Fe3140,105
24
- mkdocstrings_matlab-0.1.0.dist-info/licenses/LICENSE,sha256=14xA0OIYNpfmdeuq8-Yyqg7-3IJ4qhu3BJhknent-cY,1069
25
- mkdocstrings_matlab-0.1.0.dist-info/RECORD,,
21
+ mkdocstrings_handlers/matlab/matlab/+docstring/+utils/parse_doc.m,sha256=6pGRMZSPrqaI5C0LNan342-Dje5tneDwUPkUJ_cMiSA,483
22
+ mkdocstrings_matlab-0.1.1.dist-info/METADATA,sha256=I4RLFAZMluugnZ1sefZSDCGRF4_s5ETUav-_o7yFtw8,457
23
+ mkdocstrings_matlab-0.1.1.dist-info/WHEEL,sha256=fl6v0VwpzfGBVsGtkAkhILUlJxROXbA3HvRL6Fe3140,105
24
+ mkdocstrings_matlab-0.1.1.dist-info/licenses/LICENSE,sha256=14xA0OIYNpfmdeuq8-Yyqg7-3IJ4qhu3BJhknent-cY,1069
25
+ mkdocstrings_matlab-0.1.1.dist-info/RECORD,,