|
14 | 14 | from sphinx.util.docutils import new_document
|
15 | 15 | from sphinx.util.nodes import nested_parse_with_titles
|
16 | 16 | from sphinx.ext.autodoc import mock
|
17 |
| -from sphinx.util.docutils import SphinxDirective |
18 | 17 |
|
19 | 18 | from sphinxarg import __version__
|
20 | 19 | from sphinxarg.parser import parse_parser, parser_navigate
|
@@ -280,7 +279,7 @@ def ensure_unique_ids(items):
|
280 | 279 | n['ids'] = ids
|
281 | 280 |
|
282 | 281 |
|
283 |
| -class ArgParseDirective(SphinxDirective): |
| 282 | +class ArgParseDirective(Directive): |
284 | 283 | has_content = True
|
285 | 284 | option_spec = {
|
286 | 285 | 'module': unchanged,
|
@@ -505,26 +504,24 @@ def run(self):
|
505 | 504 | msg = ':module: and :func: should be specified, or :ref:, or :filename: and :func:'
|
506 | 505 | raise self.error(msg)
|
507 | 506 |
|
508 |
| - mock_imports = getattr(self.config,'autodoc_mock_imports',[]) |
509 |
| - |
510 | 507 | # Skip this if we're dealing with a local file, since it obviously can't be imported
|
511 | 508 | if 'filename' not in self.options:
|
512 |
| - with mock(mock_imports): |
| 509 | + with mock(self.config.autodoc_mock_imports): |
513 | 510 | try:
|
514 | 511 | mod = importlib.import_module(module_name)
|
515 |
| - except ImportErroras exc: |
| 512 | + except ImportError as exc: |
516 | 513 | msg = (
|
517 |
| - f'Failed to import "{attr_name}" from "{module_name}".\n' |
518 |
| - f'{sys.exc_info()[1]}' |
519 |
| - ) |
520 |
| - raise self.error(msg) from exc |
| 514 | + f'Failed to import "{attr_name}" from "{module_name}".\n' |
| 515 | + f'{sys.exc_info()[1]}' |
| 516 | + ) |
| 517 | + raise self.error(msg) from exc |
521 | 518 |
|
522 | 519 | if not hasattr(mod, attr_name):
|
523 | 520 | msg = (
|
524 |
| - f'Module "{module_name}" has no attribute "{attr_name}"\n' |
525 |
| - f'Incorrect argparse :module: or :func: values?' |
526 |
| - ) |
527 |
| - raise self.error(msg) |
| 521 | + f'Module "{module_name}" has no attribute "{attr_name}"\n' |
| 522 | + f'Incorrect argparse :module: or :func: values?' |
| 523 | + ) |
| 524 | + raise self.error(msg) |
528 | 525 | func = getattr(mod, attr_name)
|
529 | 526 |
|
530 | 527 | if isinstance(func, ArgumentParser):
|
@@ -600,6 +597,7 @@ def run(self):
|
600 | 597 |
|
601 | 598 |
|
602 | 599 | def setup(app):
|
| 600 | + app.setup_extension('sphinx.ext.autodoc') |
603 | 601 | app.add_directive('argparse', ArgParseDirective)
|
604 | 602 | return {
|
605 | 603 | 'version': __version__,
|
|
0 commit comments