mkdocstrings-matlab 0.9.1__py3-none-any.whl → 0.9.3__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.
@@ -358,7 +358,15 @@ class MatlabHandler(BaseHandler):
358
358
  raise CollectionError("Empty identifier")
359
359
 
360
360
  final_config = ChainMap(config, self.default_config) # type: ignore[arg-type]
361
- model = self.paths.resolve(identifier, config=final_config)
361
+ try:
362
+ model = self.paths.resolve(identifier, config=final_config)
363
+ except SyntaxError as ex:
364
+ msg = str(ex)
365
+ if ex.text:
366
+ msg += ':\n' + ex.text
367
+ raise CollectionError(msg) from ex
368
+ except Exception as ex:
369
+ raise CollectionError(str(ex)) from ex
362
370
  if model is None:
363
371
  raise CollectionError(f"Identifier '{identifier}' not found")
364
372
  return model
@@ -198,6 +198,7 @@ class FileParser(object):
198
198
  self.encoding: str = result.encoding if result else "utf-8"
199
199
  with open(filepath, "rb") as f:
200
200
  self._content: bytes = f.read()
201
+ self._node: Node | None = None
201
202
 
202
203
  @property
203
204
  def content(self):
@@ -226,26 +227,38 @@ class FileParser(object):
226
227
  Raises:
227
228
  ValueError: If the file could not be parsed.
228
229
  """
229
- tree = PARSER.parse(self._content)
230
- cursor = tree.walk()
231
-
232
- if cursor.node is None:
233
- raise ValueError(f"The file {self.filepath} could not be parsed.")
234
- captures = FILE_QUERY.captures(cursor.node)
235
-
236
- if "function" in captures:
237
- model = self._parse_function(captures["function"][0], **kwargs)
238
- elif "class" in captures:
239
- model = self._parse_class(captures["class"][0], **kwargs)
240
- else:
241
- model = Script(self.filepath.stem, filepath=self.filepath, **kwargs)
230
+ try:
231
+ tree = PARSER.parse(self._content)
232
+ cursor = tree.walk()
233
+
234
+ if cursor.node is None:
235
+ raise ValueError(f"The file {self.filepath} could not be parsed.")
236
+ captures = FILE_QUERY.captures(cursor.node)
237
+ if "function" in captures:
238
+ model = self._parse_function(captures["function"][0], **kwargs)
239
+ elif "class" in captures:
240
+ model = self._parse_class(captures["class"][0], **kwargs)
241
+ else:
242
+ model = Script(self.filepath.stem, filepath=self.filepath, **kwargs)
242
243
 
243
- if not model.docstring:
244
- model.docstring = self._comment_docstring(
245
- captures.get("header", None), parent=model
246
- )
244
+ if not model.docstring:
245
+ model.docstring = self._comment_docstring(
246
+ captures.get("header", None), parent=model
247
+ )
247
248
 
248
- return model
249
+ return model
250
+ except Exception as ex:
251
+ syntax_error = SyntaxError(f"Error parsing Matlab file")
252
+ syntax_error.filename = str(self.filepath)
253
+ if self._node is not None:
254
+ if self._node.text is not None:
255
+ indentation = ' ' * self._node.start_point.column
256
+ syntax_error.text = indentation + self._node.text.decode(self.encoding)
257
+ syntax_error.lineno = self._node.start_point.row + 1
258
+ syntax_error.offset = self._node.start_point.column + 1
259
+ syntax_error.end_lineno = self._node.end_point.row + 1
260
+ syntax_error.end_offset = self._node.end_point.column + 1
261
+ raise syntax_error from ex
249
262
 
250
263
  def _parse_class(self, node: Node, **kwargs: Any) -> Class:
251
264
  """
@@ -262,6 +275,7 @@ class FileParser(object):
262
275
  Returns:
263
276
  Class: The parsed Class or Classfolder model.
264
277
  """
278
+ self._node = node
265
279
  saved_kwargs = {key: value for key, value in kwargs.items()}
266
280
  captures = CLASS_QUERY.captures(node)
267
281
 
@@ -401,6 +415,7 @@ class FileParser(object):
401
415
  The value is `True` if no value is specified,
402
416
  otherwise it is the parsed value which can be a boolean or a string.
403
417
  """
418
+ self._node = node
404
419
  captures = ATTRIBUTE_QUERY.captures(node)
405
420
 
406
421
  key = self._first_from_capture(captures, "name")
@@ -429,6 +444,7 @@ class FileParser(object):
429
444
  KeyError: If required captures are missing from the node.
430
445
 
431
446
  """
447
+ self._node = node
432
448
  captures: dict = FUNCTION_QUERY.matches(node)[0][1]
433
449
 
434
450
  input_names = self._decode_from_capture(captures, "input")
@@ -529,6 +545,7 @@ class FileParser(object):
529
545
  Returns:
530
546
  str: The decoded text of the node. If the node or its text is None, returns an empty string.
531
547
  """
548
+ self._node = node
532
549
  return (
533
550
  node.text.decode(self.encoding)
534
551
  if node is not None and node.text is not None
@@ -621,6 +638,18 @@ class FileParser(object):
621
638
  except StopIteration:
622
639
  break
623
640
 
641
+ # Exclude all pragma's
642
+ if line in [
643
+ '%#codegen',
644
+ '%#eml',
645
+ '%#external',
646
+ '%#exclude',
647
+ '%#function',
648
+ '%#ok',
649
+ '%#mex',
650
+ ]:
651
+ continue
652
+
624
653
  if "--8<--" in line:
625
654
  continue
626
655
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocstrings-matlab
3
- Version: 0.9.1
3
+ Version: 0.9.3
4
4
  Summary: A MATLAB handler for mkdocstrings
5
5
  Author-email: Mark Hu <watermarkhu@gmail.com>
6
6
  License: MIT
@@ -25,7 +25,7 @@ Requires-Dist: charset-normalizer==3.4.1
25
25
  Requires-Dist: mkdocstrings-python==1.13.0
26
26
  Requires-Dist: mkdocstrings==0.27.0
27
27
  Requires-Dist: tree-sitter-matlab==1.0.3
28
- Requires-Dist: tree-sitter==0.23.2
28
+ Requires-Dist: tree-sitter==0.24.0
29
29
  Description-Content-Type: text/markdown
30
30
 
31
31
  <!-- --8<-- [start:header] -->
@@ -1,10 +1,10 @@
1
1
  mkdocstrings_handlers/matlab/__init__.py,sha256=w5R9cGtqeJF0GUP_Jc_ad8FnS4FpbutnmHvzVRlohPM,1124
2
2
  mkdocstrings_handlers/matlab/collect.py,sha256=6GkAwKor11Hm9QvKr6cKSHuylpoMF4Y3c8_myKiYOdE,29677
3
3
  mkdocstrings_handlers/matlab/enums.py,sha256=Lzc8MLar-uMoKplT5LxF1lXNBfjHc9MCTe2b0mJMc10,1540
4
- mkdocstrings_handlers/matlab/handler.py,sha256=5EK559dDElhNI9owKmia72Nl02MBULUaa1Dd-zCCeSE,19718
4
+ mkdocstrings_handlers/matlab/handler.py,sha256=TK3a19O-m668qtnf7r1bRRI9TVWm3vZf1LnOj1e8uQw,19988
5
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=mpYNAoIU_nxvyisYLYzXllKjWKUKu0pkk8_e3RqVNaE,22284
7
+ mkdocstrings_handlers/matlab/treesitter.py,sha256=lnpnwNOb22FvS7mykG3qs5rd5aPwvRJplHqOqC1vDbE,23526
8
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
@@ -16,7 +16,7 @@ mkdocstrings_handlers/matlab/templates/material/docstring/namespaces.html.jinja,
16
16
  mkdocstrings_handlers/matlab/templates/material/docstring/properties.html.jinja,sha256=9ckdYymLlB5sflwYEaEPAQLJuVWF8nezMCV5JnanXVA,4165
17
17
  mkdocstrings_handlers/matlab/templates/material/summary/namespaces.html.jinja,sha256=0vVlUB6oh-A7cpXbuDLOQLxTubyb_DisdOKm062WNMs,650
18
18
  mkdocstrings_handlers/matlab/templates/material/summary/properties.html.jinja,sha256=nyPaELf9qPCxJQFxK1MWYK4fPwsk5VESh9xKHLtd-XE,643
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,,
19
+ mkdocstrings_matlab-0.9.3.dist-info/METADATA,sha256=KfUWqpFqCqh-CTpXMS01ZYkM3SNHEU0vHmsVqw_lLrM,4736
20
+ mkdocstrings_matlab-0.9.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
21
+ mkdocstrings_matlab-0.9.3.dist-info/licenses/LICENSE,sha256=TZQpwBuA3KLH56--XDAY2Qwo9gGdxeTITYhMOylmYhg,743
22
+ mkdocstrings_matlab-0.9.3.dist-info/RECORD,,