mkdocstrings-matlab 0.1.2__tar.gz → 0.1.4__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.2 → mkdocstrings_matlab-0.1.4}/PKG-INFO +3 -1
  2. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/pyproject.toml +3 -1
  3. mkdocstrings_matlab-0.1.4/src/mkdocstrings_handlers/matlab/collections.py +17 -0
  4. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/handler.py +47 -23
  5. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+case/class.m +1 -1
  6. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/argument.m +1 -1
  7. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/class.m +2 -2
  8. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/func.m +1 -1
  9. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+utils/dedent.m +0 -1
  10. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+utils/parse_doc.m +1 -1
  11. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/resolve.m +4 -0
  12. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/models.py +31 -6
  13. mkdocstrings_matlab-0.1.4/src/mkdocstrings_handlers/matlab/parser.py +31 -0
  14. mkdocstrings_matlab-0.1.4/src/mkdocstrings_handlers/matlab/resources/grammar.yml +566 -0
  15. mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2023a/LICENSE +21 -0
  16. mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2023a/README.md +5 -0
  17. mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2023a/pyproject.toml +55 -0
  18. mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2023b/LICENSE +21 -0
  19. mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2023b/README.md +3 -0
  20. mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2023b/pyproject.toml +54 -0
  21. mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2024a/.gitignore +10 -0
  22. mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2024a/LICENSE +21 -0
  23. mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2024a/README.md +4 -0
  24. mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2024a/pyproject.toml +53 -0
  25. mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2024a/src/mkdocstrings_handlers/matlab_engine/__init__.py +8 -0
  26. mkdocstrings_matlab-0.1.2/submodules/mkdocstrings-matlab-r2023b/README.md +0 -3
  27. mkdocstrings_matlab-0.1.2/submodules/mkdocstrings-matlab-r2023b/pyproject.toml +0 -27
  28. mkdocstrings_matlab-0.1.2/submodules/mkdocstrings-matlab-r2024a/README.md +0 -3
  29. mkdocstrings_matlab-0.1.2/submodules/mkdocstrings-matlab-r2024a/pyproject.toml +0 -26
  30. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/.gitignore +0 -0
  31. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/LICENSE +0 -0
  32. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/README.md +0 -0
  33. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/docs/index.md +0 -0
  34. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/mkdocs.yml +0 -0
  35. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/__init__.py +0 -0
  36. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+case/builtin.m +0 -0
  37. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+case/func.m +0 -0
  38. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+case/method.m +0 -0
  39. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+case/namespace.m +0 -0
  40. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/namespace.m +0 -0
  41. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/property.m +0 -0
  42. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+metadata/script.m +0 -0
  43. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/+utils/get_namespace_path.m +0 -0
  44. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/+docstring/exception.m +0 -0
  45. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/matlab/matlab_startup.m +0 -0
  46. {mkdocstrings_matlab-0.1.2 → mkdocstrings_matlab-0.1.4}/src/mkdocstrings_handlers/matlab/py.typed +0 -0
  47. {mkdocstrings_matlab-0.1.2/submodules/mkdocstrings-matlab-r2023b → mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2023a}/.gitignore +0 -0
  48. {mkdocstrings_matlab-0.1.2/submodules/mkdocstrings-matlab-r2023b → mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2023a}/src/mkdocstrings_handlers/matlab_engine/__init__.py +0 -0
  49. {mkdocstrings_matlab-0.1.2/submodules/mkdocstrings-matlab-r2024a → mkdocstrings_matlab-0.1.4/submodules/mkdocstrings-matlab-r2023b}/.gitignore +0 -0
  50. {mkdocstrings_matlab-0.1.2/submodules/mkdocstrings-matlab-r2024a → mkdocstrings_matlab-0.1.4/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.2
3
+ Version: 0.1.4
4
4
  Summary: Add your description here
5
5
  Author-email: Mark Hu <mark.hu@asml.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,6 +1,6 @@
1
1
  [project]
2
2
  name = "mkdocstrings-matlab"
3
- version = "0.1.2"
3
+ version = "0.1.4"
4
4
  description = "Add your description here"
5
5
  authors = [
6
6
  { name = "Mark Hu", email = "mark.hu@asml.com" }
@@ -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,
@@ -142,7 +130,9 @@ class MatlabHandler(BaseHandler):
142
130
  self.engine = MatlabEngine()
143
131
  self.engine.addpath(str(Path(__file__).parent / "matlab"))
144
132
  self.engine.matlab_startup(paths, startup_expression)
145
- self.models = _ModelsStorage()
133
+ self.models = ModelsCollection()
134
+ self.lines = LinesCollection()
135
+ self.parser = MatlabParser()
146
136
  self._locale = locale
147
137
 
148
138
  def get_templates_dir(self, handler: str | None = None) -> Path:
@@ -173,6 +163,11 @@ class MatlabHandler(BaseHandler):
173
163
  raise CollectionError(error.args[0].strip()) from error
174
164
  ast_dict = json.loads(ast_json)
175
165
 
166
+ filepath = Path(ast_dict["path"])
167
+ if filepath not in self.lines:
168
+ lines = str(charset_normalizer.from_path(filepath).best()).splitlines()
169
+ self.lines[filepath] = lines
170
+
176
171
  match ast_dict["type"]:
177
172
  case "function" | "method":
178
173
  return self.collect_function(ast_dict, final_config)
@@ -255,16 +250,38 @@ class MatlabHandler(BaseHandler):
255
250
  if ast_dict["docstring"]
256
251
  else None
257
252
  )
253
+
254
+ filepath = Path(ast_dict["path"])
255
+
256
+ if config["show_source"]:
257
+ tmObject = self.parser.parse_file(filepath)
258
+ tmClass = next(
259
+ child
260
+ for child in tmObject.children
261
+ if child.token == "meta.class.matlab"
262
+ )
263
+ else:
264
+ tmClass = None
265
+
266
+ bases = ast_dict["superclasses"] if isinstance(ast_dict["superclasses"], list) else [ast_dict["superclasses"]]
267
+ bases = [base for base in bases if base != "handle"]
268
+
258
269
  model = Class(
259
270
  ast_dict["name"],
260
271
  docstring=docstring,
261
- parent=self.get_parent(Path(ast_dict["path"]).parent),
272
+ parent=self.get_parent(filepath.parent),
262
273
  hidden=ast_dict["hidden"],
263
274
  sealed=ast_dict["sealed"],
264
275
  abstract=ast_dict["abstract"],
265
276
  enumeration=ast_dict["enumeration"],
266
277
  handle=ast_dict["handle"],
267
- filepath=Path(ast_dict["path"]),
278
+ bases=bases,
279
+ filepath=filepath,
280
+ modules_collection=self.models,
281
+ lines_collection=self.lines,
282
+ lineno=1,
283
+ endlineno=len(self.lines[filepath]),
284
+ textmate=tmClass,
268
285
  )
269
286
 
270
287
  for property_dict in ast_dict["properties"]:
@@ -296,12 +313,14 @@ class MatlabHandler(BaseHandler):
296
313
  continue
297
314
 
298
315
  method = self.collect(f"{defining_class}.{name}", config)
316
+ (method.lineno, method.endlineno) = model.get_lineno_method(name)
299
317
  method.parent = model
300
318
  method._access = method_dict["access"]
301
319
  method._static = method_dict["static"]
302
320
  method._abstract = method_dict["abstract"]
303
321
  method._sealed = method_dict["sealed"]
304
322
  method._hidden = method_dict["hidden"]
323
+
305
324
  model.members[name] = method
306
325
  self.models[method.canonical_path] = method
307
326
 
@@ -340,6 +359,7 @@ class MatlabHandler(BaseHandler):
340
359
  )
341
360
  )
342
361
 
362
+ filepath = Path(ast_dict["path"])
343
363
  model = Function(
344
364
  ast_dict["name"],
345
365
  parameters=Parameters(*parameters),
@@ -350,8 +370,12 @@ class MatlabHandler(BaseHandler):
350
370
  )
351
371
  if ast_dict["docstring"]
352
372
  else None,
353
- parent=self.get_parent(Path(ast_dict["path"]).parent),
354
- filepath=Path(ast_dict["path"]),
373
+ parent=self.get_parent(filepath.parent),
374
+ filepath=filepath,
375
+ modules_collection=self.models,
376
+ lines_collection=self.lines,
377
+ lineno=1,
378
+ endlineno=len(self.lines[filepath]),
355
379
  )
356
380
 
357
381
  self.models[model.canonical_path] = model
@@ -9,4 +9,4 @@ function data = class(identifier)
9
9
  object = metaclass(identifier);
10
10
  data = docstring.metadata.class(object);
11
11
 
12
- end
12
+ end
@@ -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);
@@ -1,6 +1,6 @@
1
1
  function data = class(object)
2
2
  arguments
3
- object (1,1) matlab.metadata.Class
3
+ object (1,1) % meta.class matlab.metadata.Class
4
4
  end
5
5
  data.type = 'class';
6
6
 
@@ -45,4 +45,4 @@ function data = class(object)
45
45
  nameparts = split(object.Name, '.');
46
46
  data.constructor = any(strcmp(nameparts(end), [data.methods.name]));
47
47
 
48
- end
48
+ end
@@ -1,7 +1,7 @@
1
1
  function data = func(object)
2
2
 
3
3
  arguments
4
- object (1,1) matlab.metadata.MetaData
4
+ object (1,1) % meta.MetaData matlab.metadata.MetaData
5
5
  end
6
6
 
7
7
  data.type = 'function';
@@ -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 == ' ')
@@ -1,7 +1,7 @@
1
1
  function doc = parse_doc(object, combine)
2
2
 
3
3
  arguments
4
- object (1,1) matlab.metadata.MetaData
4
+ object (1,1) % meta.MetaData matlab.metadata.MetaData
5
5
  combine (1,1) logical = true
6
6
  end
7
7
 
@@ -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)