Skip to content

Commit

Permalink
Correctly generate toctree entries per build type
Browse files Browse the repository at this point in the history
This commit ensures toctree entries are correctly generated according to
both the build type of the package and additional options set by the
user (to run `doxygen`/`sphinx-apidoc` regardless of package build type).

Signed-off-by: Abrar Rahman Protyasha <[email protected]>
  • Loading branch information
Abrar Rahman Protyasha committed Aug 7, 2021
1 parent 2977f35 commit e43f3ab
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions rosdoc2/verbs/build/builders/sphinx_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@

logger = logging.getLogger('rosdoc2')

def generate_package_toc_entry(*, build_type: str) -> str:
toc_entry_py = 'modules'
toc_entry_cpp = 'api/library_root\n Full API <api/unabridged_api>\n File structure <api/unabridged_orphan>'
def generate_package_toc_entry(*, build_context) -> str:
build_type = build_context.build_type
run_doxygen = build_context.run_doxygen
run_sphinx_apidoc = build_context.run_sphinx_apidoc
toc_entry_py = f'\n {build_context.package.name} Python API <modules>'
toc_entry_cpp = '\n api/library_root\n Full C/C++ API <api/unabridged_api>\n File structure <api/unabridged_orphan>'
toc_entry = ''

if build_type == 'ament_python':
return toc_entry_py
elif build_type in ['ament_cmake', 'cmake']:
return toc_entry_cpp
else: # build_type == 'mixed'
return f'{toc_entry_cpp}\n {toc_entry_py}'
if build_type == 'ament_python' or run_sphinx_apidoc:
toc_entry += toc_entry_py
if build_type in ['ament_cmake', 'cmake'] or run_doxygen:
toc_entry += toc_entry_cpp

return toc_entry

rosdoc2_wrapping_conf_py_template = """\
## Generated by rosdoc2.verbs.build.builders.SphinxBuilder.
Expand Down Expand Up @@ -93,7 +97,7 @@ def ensure_global(name, default):
# These arguments are required.
"containmentFolder": "{user_sourcedir}/api",
"rootFileName": "library_root.rst",
"rootFileTitle": "{package_name} API",
"rootFileTitle": "{package_name} C/C++ API",
"doxygenStripFromPath": "..",
# Suggested optional arguments.
"createTreeView": True,
Expand Down Expand Up @@ -266,7 +270,6 @@ def ensure_global(name, default):
.. toctree::
:maxdepth: 2
{package_toc_entry}
Indices and Search
Expand Down Expand Up @@ -501,8 +504,7 @@ def generate_default_project_into_directory(self, directory):
[a.name for a in package.authors] + [m.name for m in package.maintainers]
)),
'package_underline': '=' * len(package.name),
'package_toc_entry': generate_package_toc_entry(
build_type = self.build_context.build_type)
'package_toc_entry': generate_package_toc_entry(build_context=self.build_context)
}

with open(os.path.join(directory, 'conf.py'), 'w+') as f:
Expand Down

0 comments on commit e43f3ab

Please sign in to comment.