mkdocstrings-matlab 0.1.3__tar.gz → 0.1.5__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/PKG-INFO +4 -2
  2. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/pyproject.toml +4 -2
  3. mkdocstrings_matlab-0.1.5/src/mkdocstrings_handlers/matlab/collections.py +17 -0
  4. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/handler.py +51 -24
  5. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/argument.m +1 -1
  6. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+utils/dedent.m +0 -1
  7. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/resolve.m +4 -0
  8. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/models.py +31 -6
  9. mkdocstrings_matlab-0.1.5/src/mkdocstrings_handlers/matlab/parser.py +31 -0
  10. mkdocstrings_matlab-0.1.5/src/mkdocstrings_handlers/matlab/resources/grammar.yml +566 -0
  11. mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2023a/LICENSE +21 -0
  12. mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2023a/README.md +5 -0
  13. mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2023a/pyproject.toml +55 -0
  14. mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2023b/LICENSE +21 -0
  15. mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2023b/README.md +3 -0
  16. mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2023b/pyproject.toml +54 -0
  17. mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2024a/.gitignore +10 -0
  18. mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2024a/LICENSE +21 -0
  19. mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2024a/README.md +4 -0
  20. mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2024a/pyproject.toml +53 -0
  21. mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2024a/src/mkdocstrings_handlers/matlab_engine/__init__.py +8 -0
  22. mkdocstrings_matlab-0.1.3/submodules/mkdocstrings-matlab-r2023b/README.md +0 -3
  23. mkdocstrings_matlab-0.1.3/submodules/mkdocstrings-matlab-r2023b/pyproject.toml +0 -27
  24. mkdocstrings_matlab-0.1.3/submodules/mkdocstrings-matlab-r2024a/README.md +0 -3
  25. mkdocstrings_matlab-0.1.3/submodules/mkdocstrings-matlab-r2024a/pyproject.toml +0 -26
  26. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/.gitignore +0 -0
  27. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/LICENSE +0 -0
  28. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/README.md +0 -0
  29. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/docs/index.md +0 -0
  30. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/mkdocs.yml +0 -0
  31. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/__init__.py +0 -0
  32. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+case/builtin.m +0 -0
  33. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+case/class.m +0 -0
  34. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+case/func.m +0 -0
  35. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+case/method.m +0 -0
  36. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+case/namespace.m +0 -0
  37. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/class.m +0 -0
  38. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/func.m +0 -0
  39. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/namespace.m +0 -0
  40. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/property.m +0 -0
  41. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/script.m +0 -0
  42. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+utils/get_namespace_path.m +0 -0
  43. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+utils/parse_doc.m +0 -0
  44. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/+docstring/exception.m +0 -0
  45. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/matlab/matlab_startup.m +0 -0
  46. {mkdocstrings_matlab-0.1.3 → mkdocstrings_matlab-0.1.5}/src/mkdocstrings_handlers/matlab/py.typed +0 -0
  47. {mkdocstrings_matlab-0.1.3/submodules/mkdocstrings-matlab-r2023b → mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2023a}/.gitignore +0 -0
  48. {mkdocstrings_matlab-0.1.3/submodules/mkdocstrings-matlab-r2023b → mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2023a}/src/mkdocstrings_handlers/matlab_engine/__init__.py +0 -0
  49. {mkdocstrings_matlab-0.1.3/submodules/mkdocstrings-matlab-r2024a → mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2023b}/.gitignore +0 -0
  50. {mkdocstrings_matlab-0.1.3/submodules/mkdocstrings-matlab-r2024a → mkdocstrings_matlab-0.1.5/submodules/mkdocstrings-matlab-r2023b}/src/mkdocstrings_handlers/matlab_engine/__init__.py +0 -0
@@ -1,15 +1,17 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: mkdocstrings-matlab
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: Add your description here
5
- Author-email: Mark Hu <mark.hu@asml.com>
5
+ Author-email: Mark Hu <watermarkhu@gmail.com>
6
6
  License-File: LICENSE
7
+ Requires-Dist: charset-normalizer>=3.3.2
7
8
  Requires-Dist: griffe>=1.2.0
8
9
  Requires-Dist: markdown>=3.7
9
10
  Requires-Dist: mkdocs-material>=9.5.33
10
11
  Requires-Dist: mkdocs>=1.6.0
11
12
  Requires-Dist: mkdocstrings>=0.25.2
12
13
  Requires-Dist: mkdocstrings[python]>=0.18
14
+ Requires-Dist: textmate-grammar-python>=0.6.1
13
15
  Description-Content-Type: text/markdown
14
16
 
15
17
  # mkdocstrings-matlab
@@ -1,9 +1,9 @@
1
1
  [project]
2
2
  name = "mkdocstrings-matlab"
3
- version = "0.1.3"
3
+ version = "0.1.5"
4
4
  description = "Add your description here"
5
5
  authors = [
6
- { name = "Mark Hu", email = "mark.hu@asml.com" }
6
+ { name = "Mark Hu", email = "watermarkhu@gmail.com" }
7
7
  ]
8
8
  dependencies = [
9
9
  "mkdocs>=1.6.0",
@@ -12,6 +12,8 @@ dependencies = [
12
12
  "griffe>=1.2.0",
13
13
  "mkdocs-material>=9.5.33",
14
14
  "markdown>=3.7",
15
+ "charset-normalizer>=3.3.2",
16
+ "textmate-grammar-python>=0.6.1",
15
17
  ]
16
18
  readme = "README.md"
17
19
 
@@ -0,0 +1,17 @@
1
+ from _griffe.collections import LinesCollection as _LinesCollection, ModulesCollection
2
+ from _griffe.models import Object
3
+
4
+
5
+ class LinesCollection(_LinesCollection):
6
+ pass
7
+
8
+
9
+ class ModelsCollection(ModulesCollection):
10
+ def __init__(self):
11
+ self.members: dict[str, Object] = {}
12
+
13
+ def __setitem__(self, key: str, value: Object):
14
+ self.members[key] = value
15
+
16
+ def __getitem__(self, key: str):
17
+ return self.members[key]
@@ -8,9 +8,11 @@ from griffe import Docstring, Parameters, Parameter, ParameterKind
8
8
  from pprint import pprint
9
9
 
10
10
 
11
+ import charset_normalizer
11
12
  import json
12
13
 
13
14
 
15
+ from mkdocstrings_handlers.matlab.collections import LinesCollection, ModelsCollection
14
16
  from mkdocstrings_handlers.matlab_engine import MatlabEngine, MatlabExecutionError
15
17
  from mkdocstrings_handlers.matlab.models import (
16
18
  Function,
@@ -18,23 +20,9 @@ from mkdocstrings_handlers.matlab.models import (
18
20
  Classfolder,
19
21
  Namespace,
20
22
  Property,
21
- ROOT
23
+ ROOT,
22
24
  )
23
-
24
-
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
25
+ from mkdocstrings_handlers.matlab.parser import MatlabParser
38
26
 
39
27
 
40
28
  class MatlabHandler(BaseHandler):
@@ -72,8 +60,8 @@ class MatlabHandler(BaseHandler):
72
60
  # "find_stubs_package": False,
73
61
  # "allow_inspection": True,
74
62
  "show_bases": True,
75
- "show_inheritance_diagram": False, # not implemented
76
- "show_source": False, # not implemented
63
+ "show_inheritance_diagram": False, # Insider feature
64
+ "show_source": True,
77
65
  # "preload_modules": None,
78
66
  # Heading options
79
67
  "heading_level": 2,
@@ -138,11 +126,16 @@ class MatlabHandler(BaseHandler):
138
126
 
139
127
  if paths is None:
140
128
  paths = ""
129
+ else:
130
+ config_path = Path(config_file_path).parent
131
+ full_paths = [str((config_path / path).resolve()) for path in paths]
141
132
 
142
133
  self.engine = MatlabEngine()
143
134
  self.engine.addpath(str(Path(__file__).parent / "matlab"))
144
- self.engine.matlab_startup(paths, startup_expression)
145
- self.models = _ModelsStorage()
135
+ self.engine.matlab_startup(full_paths, startup_expression)
136
+ self.models = ModelsCollection()
137
+ self.lines = LinesCollection()
138
+ self.parser = MatlabParser()
146
139
  self._locale = locale
147
140
 
148
141
  def get_templates_dir(self, handler: str | None = None) -> Path:
@@ -173,6 +166,11 @@ class MatlabHandler(BaseHandler):
173
166
  raise CollectionError(error.args[0].strip()) from error
174
167
  ast_dict = json.loads(ast_json)
175
168
 
169
+ filepath = Path(ast_dict["path"])
170
+ if filepath not in self.lines:
171
+ lines = str(charset_normalizer.from_path(filepath).best()).splitlines()
172
+ self.lines[filepath] = lines
173
+
176
174
  match ast_dict["type"]:
177
175
  case "function" | "method":
178
176
  return self.collect_function(ast_dict, final_config)
@@ -255,16 +253,38 @@ class MatlabHandler(BaseHandler):
255
253
  if ast_dict["docstring"]
256
254
  else None
257
255
  )
256
+
257
+ filepath = Path(ast_dict["path"])
258
+
259
+ if config["show_source"]:
260
+ tmObject = self.parser.parse_file(filepath)
261
+ tmClass = next(
262
+ child
263
+ for child in tmObject.children
264
+ if child.token == "meta.class.matlab"
265
+ )
266
+ else:
267
+ tmClass = None
268
+
269
+ bases = ast_dict["superclasses"] if isinstance(ast_dict["superclasses"], list) else [ast_dict["superclasses"]]
270
+ bases = [base for base in bases if base != "handle"]
271
+
258
272
  model = Class(
259
273
  ast_dict["name"],
260
274
  docstring=docstring,
261
- parent=self.get_parent(Path(ast_dict["path"]).parent),
275
+ parent=self.get_parent(filepath.parent),
262
276
  hidden=ast_dict["hidden"],
263
277
  sealed=ast_dict["sealed"],
264
278
  abstract=ast_dict["abstract"],
265
279
  enumeration=ast_dict["enumeration"],
266
280
  handle=ast_dict["handle"],
267
- filepath=Path(ast_dict["path"]),
281
+ bases=bases,
282
+ filepath=filepath,
283
+ modules_collection=self.models,
284
+ lines_collection=self.lines,
285
+ lineno=1,
286
+ endlineno=len(self.lines[filepath]),
287
+ textmate=tmClass,
268
288
  )
269
289
 
270
290
  for property_dict in ast_dict["properties"]:
@@ -296,12 +316,14 @@ class MatlabHandler(BaseHandler):
296
316
  continue
297
317
 
298
318
  method = self.collect(f"{defining_class}.{name}", config)
319
+ (method.lineno, method.endlineno) = model.get_lineno_method(name)
299
320
  method.parent = model
300
321
  method._access = method_dict["access"]
301
322
  method._static = method_dict["static"]
302
323
  method._abstract = method_dict["abstract"]
303
324
  method._sealed = method_dict["sealed"]
304
325
  method._hidden = method_dict["hidden"]
326
+
305
327
  model.members[name] = method
306
328
  self.models[method.canonical_path] = method
307
329
 
@@ -340,6 +362,7 @@ class MatlabHandler(BaseHandler):
340
362
  )
341
363
  )
342
364
 
365
+ filepath = Path(ast_dict["path"])
343
366
  model = Function(
344
367
  ast_dict["name"],
345
368
  parameters=Parameters(*parameters),
@@ -350,8 +373,12 @@ class MatlabHandler(BaseHandler):
350
373
  )
351
374
  if ast_dict["docstring"]
352
375
  else None,
353
- parent=self.get_parent(Path(ast_dict["path"]).parent),
354
- filepath=Path(ast_dict["path"]),
376
+ parent=self.get_parent(filepath.parent),
377
+ filepath=filepath,
378
+ modules_collection=self.models,
379
+ lines_collection=self.lines,
380
+ lineno=1,
381
+ endlineno=len(self.lines[filepath]),
355
382
  )
356
383
 
357
384
  self.models[model.canonical_path] = model
@@ -11,7 +11,7 @@ function data = argument(object)
11
11
  data(iArg) = docstring.metadata.argument(object(iArg));
12
12
  end
13
13
  return
14
- end
14
+ end
15
15
 
16
16
  data.name = object.Name;
17
17
  data.kind = string(object.Kind);
@@ -7,7 +7,6 @@ end
7
7
 
8
8
  lines = cellstr(splitlines(doc));
9
9
 
10
-
11
10
  for iLine = numel(lines):-1:1
12
11
  line = lines{iLine};
13
12
  if ~isempty(line) && ~all(line == ' ')
@@ -18,6 +18,10 @@ arguments
18
18
  cwd (1,1) string {mustBeFolder} = pwd()
19
19
  end
20
20
 
21
+ if isempty(identifier)
22
+ docstring.exception("<empty>");
23
+ end
24
+
21
25
  cd(cwd);
22
26
 
23
27
  % Check if namespace
@@ -1,8 +1,8 @@
1
1
  from enum import Enum
2
2
  from typing import Any
3
3
  from griffe import Function as GriffeFunction, Class as GriffeClass, Module, Attribute
4
- from _griffe.exceptions import BuiltinModuleError
5
4
  from pathlib import Path
5
+ from textmate_grammar.elements import ContentElement
6
6
 
7
7
 
8
8
  class Access(Enum):
@@ -43,6 +43,7 @@ class Class(CanonicalPathMixin, PathMixin, GriffeClass):
43
43
  abstract: bool = False,
44
44
  enumeration: bool = False,
45
45
  handle: bool = False,
46
+ textmate: ContentElement | None = None,
46
47
  **kwargs: Any,
47
48
  ) -> None:
48
49
  super().__init__(*args, **kwargs)
@@ -51,6 +52,31 @@ class Class(CanonicalPathMixin, PathMixin, GriffeClass):
51
52
  self._abstract: bool = abstract
52
53
  self._enumeration: bool = enumeration
53
54
  self._handle: bool = handle
55
+ self._textmate: ContentElement | None = textmate
56
+
57
+ self._method_lineno: dict[str, tuple[int, int]] = {}
58
+ if textmate is None:
59
+ return
60
+ for block in [
61
+ block
62
+ for block in self._textmate.children
63
+ if block.token == "meta.methods.matlab"
64
+ ]:
65
+ for method in block.children:
66
+ declaration = next(
67
+ item
68
+ for item in method.children
69
+ if item.token == "meta.function.declaration.matlab"
70
+ )
71
+ name = next(
72
+ item
73
+ for item in declaration.children
74
+ if item.token == "entity.name.function.matlab"
75
+ ).content
76
+ charaters_ids = method.characters.keys()
77
+ lineno = min(charaters_ids, key=lambda p: p[0])[0]
78
+ endlino = max(charaters_ids, key=lambda p: p[0])[0] + 1
79
+ self._method_lineno[name] = (lineno, endlino)
54
80
 
55
81
  @property
56
82
  def is_private(self) -> bool:
@@ -63,6 +89,9 @@ class Class(CanonicalPathMixin, PathMixin, GriffeClass):
63
89
  else:
64
90
  return super().canonical_path
65
91
 
92
+ def get_lineno_method(self, method_name: str) -> tuple[int, int]:
93
+ return self._method_lineno.get(method_name, (self.lineno, self.endlineno))
94
+
66
95
 
67
96
  class Property(CanonicalPathMixin, Attribute):
68
97
  def __init__(
@@ -137,7 +166,7 @@ class _Root(Namespace):
137
166
 
138
167
  def __repr__(self) -> str:
139
168
  return "MATLABROOT"
140
-
169
+
141
170
 
142
171
  ROOT = _Root()
143
172
 
@@ -145,7 +174,3 @@ ROOT = _Root()
145
174
  class Classfolder(Class):
146
175
  def __repr__(self) -> str:
147
176
  return f"Classfolder({self.path!r})"
148
-
149
-
150
-
151
-
@@ -0,0 +1,31 @@
1
+ from textmate_grammar.parsers.base import LanguageParser
2
+ from pathlib import Path
3
+
4
+
5
+ import logging
6
+ import yaml
7
+
8
+
9
+ logging.getLogger("textmate_grammar").setLevel(logging.ERROR)
10
+
11
+
12
+ class MatlabParser(LanguageParser):
13
+ """
14
+ Represents a grammar for the MATLAB language.
15
+ """
16
+
17
+ def __init__(self, **kwargs):
18
+ """
19
+ Initializes a new instance of the MatlabGrammar class.
20
+
21
+ Args:
22
+ remove_line_continuations (bool, optional): Whether to remove line continuations. Defaults to False.
23
+ """
24
+
25
+ with open(Path(__file__).parent / "resources" / "grammar.yml") as file:
26
+ try:
27
+ grammar = yaml.load(file.read(), Loader=yaml.CLoader)
28
+ except ImportError:
29
+ grammar = yaml.load(file.read(), Loader=yaml.Loader)
30
+
31
+ super().__init__(grammar, **kwargs)