Skip to content

Commit

Permalink
Correctly insert package path to PATH
Browse files Browse the repository at this point in the history
If the package against which `rosdoc2` was invoked did not exist in
PATH, `autodoc` would throw errors about its inability to import said
modules.

This commit correctly adds the package path to PATH.

Note that this must occur within the `conf.py` being passed into
`sphinx`, rather than in the `SphinxBuilder` class. They're separate!

Signed-off-by: Abrar Rahman Protyasha <[email protected]>
  • Loading branch information
Abrar Rahman Protyasha committed Aug 14, 2021
1 parent cecccee commit eef02f1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions rosdoc2/verbs/build/builders/sphinx_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import setuptools
import shutil
import subprocess
import sys

from ..builder import Builder
from ..collect_inventory_files import collect_inventory_files
Expand Down Expand Up @@ -48,6 +49,7 @@ def generate_package_toc_entry(*, build_context) -> str:
## conf.py, extends the settings to support Breathe and Exhale and to set up
## intersphinx mappings correctly, among other things.
import os
import sys
## exec the user's conf.py to bring all of their settings into this file.
Expand All @@ -69,6 +71,8 @@ def ensure_global(name, default):
# 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}'))
if rosdoc2_settings.get('enable_intersphinx', True):
print('[rosdoc2] enabling intersphinx', file=sys.stderr)
Expand Down Expand Up @@ -388,12 +392,6 @@ def build(self, *, doc_build_folder, output_staging_directory):
if package_name != self.build_context.package.name
]

# Setup rosdoc2 Sphinx file which will include and extend the one in `sourcedir`.
self.generate_wrapping_rosdoc2_sphinx_project_into_directory(
doc_build_folder,
sourcedir,
intersphinx_mapping_extensions)

# If the package has build type `ament_python`, or if the user configured
# to run `sphinx-apidoc`, then invoke `sphinx-apidoc` before building
if (
Expand Down Expand Up @@ -425,7 +423,6 @@ def build(self, *, doc_build_folder, output_staging_directory):
'sphinx-apidoc',
'-o', os.path.relpath(sourcedir, start=doc_build_folder),
'-e', # Document each module in its own page.
'-a', # Append module path into `sys.path`.
os.path.abspath(package_src_directory),
]
logger.info(
Expand All @@ -438,6 +435,13 @@ def build(self, *, doc_build_folder, output_staging_directory):
else:
raise RuntimeError(msg)

# Setup rosdoc2 Sphinx file which will include and extend the one in `sourcedir`.
self.generate_wrapping_rosdoc2_sphinx_project_into_directory(
doc_build_folder,
sourcedir,
package_src_directory,
intersphinx_mapping_extensions)

# Invoke Sphinx-build.
working_directory = doc_build_folder
sphinx_output_dir = os.path.abspath(os.path.join(doc_build_folder, 'sphinx_output'))
Expand Down Expand Up @@ -531,6 +535,7 @@ def generate_wrapping_rosdoc2_sphinx_project_into_directory(
self,
directory,
user_sourcedir,
package_src_directory,
intersphinx_mapping_extensions,
):
os.makedirs(directory, exist_ok=True)
Expand All @@ -542,6 +547,7 @@ def generate_wrapping_rosdoc2_sphinx_project_into_directory(
f' "{package.name} Doxygen Project": "{self.doxygen_xml_directory}"')
template_variables = {
'package_name': package.name,
'package_src_directory': package_src_directory,
'exec_depends': [exec_depend.name for exec_depend in package.exec_depends],
'build_type': self.build_context.build_type,
'always_run_doxygen': self.build_context.always_run_doxygen,
Expand Down

0 comments on commit eef02f1

Please sign in to comment.