From d159bec0fc67f67bd8a21c8e303c6afc3964d955 Mon Sep 17 00:00:00 2001 From: Abrar Rahman Protyasha Date: Wed, 11 Aug 2021 09:53:19 -0400 Subject: [PATCH] Give precedence to rosdoc2 settings when building Specifically for the `python_source` setting, which must be considered first to generate `package_src_directory`. Signed-off-by: Abrar Rahman Protyasha --- rosdoc2/verbs/build/builders/sphinx_builder.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/rosdoc2/verbs/build/builders/sphinx_builder.py b/rosdoc2/verbs/build/builders/sphinx_builder.py index b83e23d..3c4e2a1 100644 --- a/rosdoc2/verbs/build/builders/sphinx_builder.py +++ b/rosdoc2/verbs/build/builders/sphinx_builder.py @@ -393,15 +393,23 @@ def build(self, *, doc_build_folder, output_staging_directory): if (self.build_context.build_type == 'ament_python' or self.build_context.run_sphinx_apidoc): package_xml_directory = os.path.dirname(self.build_context.package.filename) - package_list = setuptools.find_packages(where=package_xml_directory) - if package_list: - package_src_directory = os.path.join(package_xml_directory, package_list[0]) - elif self.build_context.python_source is not None: + # If 'python_source' is specified, construct 'package_src_directory' from it + if self.build_context.python_source is not None: package_src_directory = \ os.path.join( package_xml_directory, self.build_context.python_source) + # If not provided, try to find the package source direcotry else: + package_list = setuptools.find_packages(where=package_xml_directory) + try: + package_src_directory = \ + os.path.join( + package_xml_directory, + package_list[package_list.index(self.build_context.package.name)] + except ValueError: + package_src_directory = '' + if not package_src_directory: msg = \ 'Could not locate source directory to invoke sphinx-apidoc in. ' \ 'If this is package does not have a standard Python package layout, '\