From 56a79083ab4163b705872c76e08b7ddfa76687c6 Mon Sep 17 00:00:00 2001 From: Abrar Rahman Protyasha Date: Mon, 4 Apr 2022 18:50:06 -0400 Subject: [PATCH] Only mock dependencies that cannot be imported Signed-off-by: Abrar Rahman Protyasha --- rosdoc2/verbs/build/builders/sphinx_builder.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/rosdoc2/verbs/build/builders/sphinx_builder.py b/rosdoc2/verbs/build/builders/sphinx_builder.py index c5ea381..163c6e9 100644 --- a/rosdoc2/verbs/build/builders/sphinx_builder.py +++ b/rosdoc2/verbs/build/builders/sphinx_builder.py @@ -71,11 +71,15 @@ def ensure_global(name, default): if rosdoc2_settings.get('enable_autodoc', True): print('[rosdoc2] enabling autodoc', file=sys.stderr) extensions.append('sphinx.ext.autodoc') - # Provide all runtime dependencies to be mocked up - # Note: `autodoc` only mocks up those modules that it actually cannot locate in PATH - autodoc_mock_imports = {exec_depends} - # Add the package directory to PATH, so that `sphinx-autodoc` can import it - sys.path.insert(0, os.path.dirname('{package_src_directory}/')) + + pkgs_to_mock = [] + import importlib + for exec_depend in {exec_depends}: + try: + importlib.import_module(exec_depend) + except: + pkgs_to_mock.append(exec_depend) + autodoc_mock_imports = pkgs_to_mock if rosdoc2_settings.get('enable_intersphinx', True): print('[rosdoc2] enabling intersphinx', file=sys.stderr)