Validates the doc string in a snippet of documentation `text` from file `name` Parameters ---------- text : str Docstring text name : str File name for which the doc string is to be validated dots : bool Whether to print a dot symbol for each chec
(text, name, dots=True)
| 386 | |
| 387 | |
| 388 | def validate_rst_syntax(text, name, dots=True): |
| 389 | """ |
| 390 | Validates the doc string in a snippet of documentation |
| 391 | `text` from file `name` |
| 392 | Parameters |
| 393 | ---------- |
| 394 | text : str |
| 395 | Docstring text |
| 396 | name : str |
| 397 | File name for which the doc string is to be validated |
| 398 | dots : bool |
| 399 | Whether to print a dot symbol for each check |
| 400 | Returns |
| 401 | ------- |
| 402 | (bool, str) |
| 403 | """ |
| 404 | if text is None: |
| 405 | if dots: |
| 406 | output_dot('E') |
| 407 | return False, f"ERROR: {name}: no documentation" |
| 408 | |
| 409 | ok_unknown_items = { |
| 410 | 'mod', 'doc', 'currentmodule', 'autosummary', 'data', 'attr', |
| 411 | 'obj', 'versionadded', 'versionchanged', 'module', 'class', |
| 412 | 'ref', 'func', 'toctree', 'moduleauthor', 'term', 'c:member', |
| 413 | 'sectionauthor', 'codeauthor', 'eq', 'doi', 'DOI', 'arXiv', 'arxiv' |
| 414 | } |
| 415 | |
| 416 | # Run through docutils |
| 417 | error_stream = io.StringIO() |
| 418 | |
| 419 | def resolve(name, is_label=False): |
| 420 | return ("http://foo", name) |
| 421 | |
| 422 | token = '<RST-VALIDATE-SYNTAX-CHECK>' |
| 423 | |
| 424 | docutils.core.publish_doctree( |
| 425 | text, token, |
| 426 | settings_overrides={'halt_level': 5, |
| 427 | 'traceback': True, |
| 428 | 'default_reference_context': 'title-reference', |
| 429 | 'default_role': 'emphasis', |
| 430 | 'link_base': '', |
| 431 | 'resolve_name': resolve, |
| 432 | 'stylesheet_path': '', |
| 433 | 'raw_enabled': 0, |
| 434 | 'file_insertion_enabled': 0, |
| 435 | 'warning_stream': error_stream}) |
| 436 | |
| 437 | # Print errors, disregarding unimportant ones |
| 438 | error_msg = error_stream.getvalue() |
| 439 | errors = error_msg.split(token) |
| 440 | success = True |
| 441 | output = "" |
| 442 | |
| 443 | for error in errors: |
| 444 | lines = error.splitlines() |
| 445 | if not lines: |
no test coverage detected
searching dependent graphs…