Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repository url if missing #161

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rosdoc2/verbs/build/builders/sphinx_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ..create_format_map_from_package import create_format_map_from_package
from ..generate_interface_docs import generate_interface_docs
from ..include_user_docs import include_user_docs
from ..package_repo_url import package_repo_url
from ..standard_documents import generate_standard_document_files, locate_standard_documents

logger = logging.getLogger('rosdoc2')
Expand Down Expand Up @@ -561,6 +562,9 @@ def build(self, *, doc_build_folder, output_staging_directory):
or build_context.ament_cmake_python) \
and not build_context.never_run_sphinx_apidoc

# Try to locate package repo url if missing
package_repo_url(self.build_context.package)

self.template_variables.update({
'has_python': has_python,
'has_cpp': has_cpp,
Expand Down
50 changes: 50 additions & 0 deletions rosdoc2/verbs/build/package_repo_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2024 R. Kent James <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os

from catkin_pkg.package import Url
import rosdistro

logger = logging.getLogger('rosdoc2')


def package_repo_url(package):
"""Add a package url from rosdistro if missing."""
for url in package.urls:
if url.type == 'repository':
return

# Only include repo url if ROS_DISTRO is known
distro = os.environ.get('ROS_DISTRO')
package_url = None
if not distro:
logger.info('Not searching for package repository url because ROS_DISTRO is not set')
return
try:
index = rosdistro.get_index(rosdistro.get_index_url())
dist_file = rosdistro.get_distribution_file(index, distro)
rosdistro_package = dist_file.release_packages[package.name]
repo_name = rosdistro_package.repository_name
repo = dist_file.repositories[repo_name]
if repo.source_repository and repo.source_repository.url:
package_url = repo.source_repository.url
logger.info(f'Adding package repository url from rosdisto: {package_url}')
package.urls.append(Url(package_url, 'repository'))
except (KeyError, RuntimeError):
pass
finally:
if not package_url:
logger.info('No package repo url found from rosdistro')
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ install_requires =
Jinja2
osrf_pycommon
pyyaml
rosdistro
setuptools>=40.6.0
sphinx
sphinx-rtd-theme
Expand Down
2 changes: 1 addition & 1 deletion stdeb.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[rosdoc2]
No-Python2:
Depends3: python3-breathe, python3-catkin-pkg-modules, python3-exhale, python3-jinja2, python3-myst-parser, python3-osrf-pycommon, python3-setuptools, python3-sphinx, python3-sphinx-rtd-theme, python3-yaml, doxygen, graphviz
Depends3: python3-breathe, python3-catkin-pkg-modules, python3-exhale, python3-jinja2, python3-myst-parser, python3-osrf-pycommon, python3-rosdistro-modules, python3-setuptools, python3-sphinx, python3-sphinx-rtd-theme, python3-yaml, doxygen, graphviz
Suite: jammy noble bookworm trixie
X-Python3-Version: >= 3.6
9 changes: 9 additions & 0 deletions test/packages/rclcpp/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rclcpp</name>
<version>0.1.2</version>
<description>Dummy rcpcpp to test repo lookup</description>
<maintainer email="[email protected]">Some One</maintainer>
<license>Apache License 2.0</license>
</package>
18 changes: 18 additions & 0 deletions test/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import argparse
import logging
import os
import pathlib

import pytest
Expand Down Expand Up @@ -214,6 +215,8 @@ def test_only_messages(module_dir):
"""Test a package only containing messages."""
PKG_NAME = 'only_messages'

# This tests that run succeeds even if rosdistro entry is missing.
os.environ['ROS_DISTRO'] = 'rolling'
do_build_package(DATAPATH / PKG_NAME, module_dir)

includes = [
Expand Down Expand Up @@ -310,3 +313,18 @@ def test_ignore_doc(module_dir):
excludes = ['do not show']

do_test_package(PKG_NAME, module_dir, excludes=excludes)


def test_rclcpp(module_dir):
"""Tests of repo url lookup from a known standard package."""
PKG_NAME = 'rclcpp'
os.environ['ROS_DISTRO'] = 'rolling'
do_build_package(DATAPATH / PKG_NAME, module_dir)

includes = [
PKG_NAME,
]

links_exist = ['https://github.com/ros2/rclcpp.git'] # Found repo url from rosdistro.
do_test_package(PKG_NAME, module_dir,
includes=includes, links_exist=links_exist)