4 """A default conf.py file for rosdoc_lite/sphinx documentation builder. 6 It provides some useful shortcuts and automatically links to ROS message definitions on docs.ros.org. 8 You can try e.g. :roswiki:`cras_py_common`, :rosdep:`rosdep2_api.html`, :tf2_msgs:`TFMessage`, :class:`genpy.Message` or 9 :class:`tf2_msgs.msg.TFMessage`. 11 To use this file in you project, create file `doc/conf.py` with the following content:: 14 os.environ['CRAS_DOCS_COMMON_SPHINX_PACKAGE_PATH'] = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 15 from cras_docs_common.sphinx_docs_conf import * 17 # Here you can customize all the variables, but leaving the rest empty is usually enough. 24 import catkin_pkg.package
26 from os.path
import abspath, dirname, join
28 from docutils
import nodes
29 from sphinx.ext
import intersphinx
32 catkin_dir = os.getenv(
'CRAS_DOCS_COMMON_SPHINX_PACKAGE_PATH', dirname(dirname(abspath(__file__))))
33 catkin_package = catkin_pkg.package.parse_package(join(catkin_dir, catkin_pkg.package.PACKAGE_MANIFEST_FILENAME))
35 project = catkin_package.name
36 copyright = time.strftime(
"%Y") +
', Czech Technical University in Prague' 37 author =
", ".join([a.name
for a
in catkin_package.authors])
38 version = catkin_package.version
39 release = catkin_package.version
45 'sphinx.ext.intersphinx',
46 'sphinx.ext.extlinks',
47 'catkin_sphinx.ShLexer',
48 'catkin_sphinx.cmake',
53 extensions.append(
'm2r')
58 autoclass_content =
'both' 61 this_dir = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
62 theme_path = os.path.join(this_dir,
'sphinx-themes')
64 html_theme_path = [theme_path, catkin_sphinx.get_theme_path()]
66 custom_theme_path = os.getenv(
'CRAS_DOCS_COMMON_SPHINX_THEME_PATH',
None)
67 if custom_theme_path
is not None:
68 html_theme_path.insert(0, custom_theme_path)
71 html_theme = os.getenv(
'CRAS_DOCS_COMMON_SPHINX_HTML_THEME',
'cras-theme')
73 ros_distro = os.getenv(
'ROS_DISTRO',
'latest')
74 ros_api_base =
'https://docs.ros.org/en/%s/api/' 75 ros_wiki_base =
'https://wiki.ros.org/' 79 .. |project| replace:: {} 80 .. |description| replace:: {} 81 .. role:: raw-html(raw) 84 .. |wiki| replace:: :raw-html:`<a href="{}{}?distro={}">ROS wiki entry</a>` 85 """.format(project, catkin_package.description, ros_wiki_base, project, ros_distro)
87 ros_api = ros_api_base % ros_distro
88 melodic_api = ros_api_base %
"melodic" 89 independent_api = ros_api_base %
"independent" 92 'ros': (ros_api +
'%s',
None),
93 'roswiki': (ros_wiki_base +
'%s?distro=' + ros_distro,
''),
94 'rospy:class': (melodic_api +
'rospy/html/rospy.%s-class.html',
"rospy."),
95 'rospy:fn': (melodic_api +
'rospy/html/rospy-module.html#%s',
"rospy."),
96 'catkin_pkg': (independent_api +
'catkin_pkg/html/%s',
None),
97 'rosdep': (independent_api +
'rosdep/html/%s',
None),
98 'rospkg': (independent_api +
'rospkg/html/%s',
None),
99 'dynamic_reconfigure': (ros_api +
'dynamic_reconfigure/html/msg/%s.html',
"dynamic_reconfigure/"),
101 for dep
in catkin_package.exec_depends:
102 if dep.name.endswith(
"_msgs"):
103 extlinks[dep.name] = (ros_api + dep.name +
'/html/msg/%s.html', dep.name +
"/")
104 elif dep.name.endswith(
"_srvs"):
105 extlinks[dep.name] = (ros_api + dep.name +
'/html/srv/%s.html', dep.name +
"/")
106 elif dep.name
not in extlinks:
107 extlinks[dep.name] = (ros_api + dep.name +
'/html/%s.html', dep.name +
"/")
109 intersphinx_mapping = {
110 "numpy": (
"https://numpy.org/doc/stable/",
None),
111 "genpy": (ros_api +
"genpy/html",
None),
113 if sys.version_info.major == 2:
114 intersphinx_mapping[
'python'] = (
'https://docs.python.org/2.7/',
None)
116 python_version =
'{}.{}'.format(sys.version_info.major, sys.version_info.minor)
117 intersphinx_mapping[
'python'] = (
'https://docs.python.org/{}/'.format(python_version),
None)
121 text_node = next(iter(contnode.traverse(
lambda n: n.tagname ==
'#text')))
122 parts = text_node.astext().split(
'.')
124 return intersphinx.missing_reference(app, env, node, contnode)
125 pkg, obj_type, obj = parts
126 if obj_type
not in (
"msg",
"srv"):
127 return intersphinx.missing_reference(app, env, node, contnode)
128 target = ros_api +
'{}/html/{}/{}.html'.format(pkg, obj_type, obj)
129 ref_node = nodes.reference()
130 ref_node[
'refuri'] = target
131 title =
'{}/{}'.format(pkg, obj)
132 text_node = nodes.literal(title, title)
133 text_node[
'classes'] = [
'xref',
'ros',
'ros-' + obj_type]
134 ref_node += text_node
138 from sphinx.domains.python
import PyObject
139 PyObject.doc_field_types[list(map(
lambda f: f.name ==
'variable', PyObject.doc_field_types)).index(
True)].rolename =
None 142 app.connect(
"missing-reference", ros_msg_reference)
def ros_msg_reference(app, env, node, contnode)