Skip to content

Commit 80e9325

Browse files
committed
Updates
1 parent ed486d3 commit 80e9325

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

sphinxarg/ext.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from sphinx.util.docutils import new_document
1515
from sphinx.util.nodes import nested_parse_with_titles
1616
from sphinx.ext.autodoc import mock
17-
from sphinx.util.docutils import SphinxDirective
1817

1918
from sphinxarg import __version__
2019
from sphinxarg.parser import parse_parser, parser_navigate
@@ -280,7 +279,7 @@ def ensure_unique_ids(items):
280279
n['ids'] = ids
281280

282281

283-
class ArgParseDirective(SphinxDirective):
282+
class ArgParseDirective(Directive):
284283
has_content = True
285284
option_spec = {
286285
'module': unchanged,
@@ -505,26 +504,24 @@ def run(self):
505504
msg = ':module: and :func: should be specified, or :ref:, or :filename: and :func:'
506505
raise self.error(msg)
507506

508-
mock_imports = getattr(self.config,'autodoc_mock_imports',[])
509-
510507
# Skip this if we're dealing with a local file, since it obviously can't be imported
511508
if 'filename' not in self.options:
512-
with mock(mock_imports):
509+
with mock(self.config.autodoc_mock_imports):
513510
try:
514511
mod = importlib.import_module(module_name)
515-
except ImportErroras exc:
512+
except ImportError as exc:
516513
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
521518

522519
if not hasattr(mod, attr_name):
523520
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)
528525
func = getattr(mod, attr_name)
529526

530527
if isinstance(func, ArgumentParser):
@@ -600,6 +597,7 @@ def run(self):
600597

601598

602599
def setup(app):
600+
app.setup_extension('sphinx.ext.autodoc')
603601
app.add_directive('argparse', ArgParseDirective)
604602
return {
605603
'version': __version__,

0 commit comments

Comments
 (0)