Skip to content

Commit dc050b2

Browse files
authored
Improving docs (#523)
* Fix DeclareLaunchArgument reference in architecture.rst Signed-off-by: Ivan Santiago Paunovic <[email protected]> * Fixes in sphinx conf.py Signed-off-by: Ivan Santiago Paunovic <[email protected]> * Add python and xml examples in DeclareLaunchArgument. Signed-off-by: Ivan Santiago Paunovic <[email protected]> * Make pytest run doctests Signed-off-by: Ivan Santiago Paunovic <[email protected]>
1 parent b06f115 commit dc050b2

File tree

6 files changed

+86
-2
lines changed

6 files changed

+86
-2
lines changed

launch/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2021 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def pytest_ignore_collect(path):
17+
# pytest doctest messes up when trying to import .launch.py packages, ignore them.
18+
# It also messes up when trying to import launch.logging.handlers due to conflicts with
19+
# logging.handlers, ignore that as well.
20+
return str(path).endswith((
21+
'.launch.py',
22+
'logging/handlers.py',
23+
))

launch/doc/source/architecture.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ This is a non-exhaustive list of actions that `launch` may provide:
4949
- This action will set a :class:`launch.LaunchConfiguration` to a specified value, creating it if it doesn't already exist.
5050
- These launch configurations can be accessed by any action via a substitution, but are scoped by default.
5151

52-
- :class:`launch.actions.DeclareLaunchDescriptionArgument`
52+
- :class:`launch.actions.DeclareLaunchArgument`
5353

5454
- This action will declare a launch description argument, which can have a name, default value, and documentation.
5555
- The argument will be exposed via a command line option for a root launch description, or as action configurations to the include launch description action for the included launch description.

launch/doc/source/conf.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@
6464
'sphinx.ext.githubpages',
6565
]
6666

67+
# autodoc settings
68+
autodoc_default_options = {
69+
'special-members': '__init__',
70+
'class-doc-from': 'class',
71+
}
72+
autodoc_class_signature = 'separated'
73+
6774
# Add any paths that contain templates here, relative to this directory.
6875
templates_path = ['_templates']
6976

@@ -108,7 +115,7 @@
108115
# Add any paths that contain custom static files (such as style sheets) here,
109116
# relative to this directory. They are copied after the builtin static files,
110117
# so a file named "default.css" will overwrite the builtin "default.css".
111-
html_static_path = ['_static']
118+
# html_static_path = ['_static']
112119

113120
# Custom sidebar templates, must be a dictionary that maps document names
114121
# to template names.

launch/launch/actions/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2021 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# imports needed for doctests
16+
import launch
17+
import launch.actions
18+
19+
import pytest
20+
21+
22+
@pytest.fixture(autouse=True)
23+
def add_imports_to_doctest_namespace(doctest_namespace):
24+
doctest_namespace['launch'] = launch
25+
doctest_namespace['LaunchDescription'] = launch.LaunchDescription
26+
for x in launch.actions.__all__:
27+
doctest_namespace[x] = getattr(launch.actions, x)

launch/launch/actions/declare_launch_argument.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,32 @@ class DeclareLaunchArgument(Action):
7474
exception is raised because none is set and there is no default value.
7575
However, the pre-condition does not guarantee that the argument was visible
7676
if behind condition or situational inclusions.
77+
78+
.. doctest::
79+
80+
>>> ld = LaunchDescription([
81+
... DeclareLaunchArgument('simple_argument'),
82+
... DeclareLaunchArgument('with_default_value', default_value='default'),
83+
... DeclareLaunchArgument(
84+
... 'with_default_and_description',
85+
... default_value='some_default',
86+
... description='this argument is used to configure ...'),
87+
... DeclareLaunchArgument(
88+
... 'mode',
89+
... default_value='A',
90+
... description='Choose between mode A and mode B',
91+
... choices=['A', 'B']),
92+
... # other actions here, ...
93+
... ])
94+
95+
.. code-block:: xml
96+
97+
<launch>
98+
<arg name="simple_argument"/>
99+
<arg name="with_default_value" default_value="default"/>
100+
<arg name="with_default_and_description" default_value="some_default"
101+
description="this argument is used to configure ..."/>
102+
</launch>
77103
"""
78104

79105
def __init__(

launch/pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[pytest]
22
junit_family=xunit2
3+
addopts = --doctest-modules

0 commit comments

Comments
 (0)