Skip to content

Commit da76fb4

Browse files
authored
Extend package discovery to support passive mechanisms (#685)
The current implementation of package discovery follows one of two paths: 1. None of the extensions were specifically enabled via a command line argument, in which case all of the extensions are engaged. 2. Some subset of the extensions were given arguments, in which case the others are ignored and their discover() methods are not called. This change adds support for discovery extensions which do not expose command line arguments and cannot therefore be specifically enabled, and ensures that those extensions are always engaged. This is a non-breaking enhancement of the PackageDiscoveryExtensionPoint interface.
1 parent 7a3bf42 commit da76fb4

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

colcon_core/package_discovery/__init__.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class PackageDiscoveryExtensionPoint:
2525
"""
2626

2727
"""The version of the discovery extension interface."""
28-
EXTENSION_POINT_VERSION = '1.0'
28+
EXTENSION_POINT_VERSION = '1.1'
2929

3030
"""The default priority of discovery extensions."""
3131
PRIORITY = 100
3232

3333
def has_default(self):
3434
"""
35-
Check if the extension has a default parameter is none are provided.
35+
Check if the extension has a default parameter if none are provided.
3636
3737
The method is intended to be overridden in a subclass.
3838
@@ -62,7 +62,9 @@ def has_parameters(self, *, args):
6262
This method must be overridden in a subclass.
6363
6464
:param args: The parsed command line arguments
65-
:returns: True if `discover()` should be called, False otherwise
65+
:returns: True if `discover()` should be called, False if no
66+
parameters were given, or None if this extension has no
67+
parameters to be specified.
6668
:rtype: bool
6769
"""
6870
raise NotImplementedError()
@@ -219,6 +221,7 @@ def expand_dir_wildcards(paths):
219221
def _get_extensions_with_parameters(
220222
args, discovery_extensions
221223
):
224+
explicitly_specified = False
222225
with_parameters = OrderedDict()
223226
for extension in discovery_extensions.values():
224227
logger.log(
@@ -235,8 +238,11 @@ def _get_extensions_with_parameters(
235238
# skip failing extension, continue with next one
236239
else:
237240
if has_parameter:
238-
with_parameters[extension.PACKAGE_DISCOVERY_NAME] = extension
239-
return with_parameters
241+
explicitly_specified = True
242+
elif has_parameter is not None:
243+
continue
244+
with_parameters[extension.PACKAGE_DISCOVERY_NAME] = extension
245+
return with_parameters if explicitly_specified else OrderedDict()
240246

241247

242248
def _discover_packages(

test/test_package_discovery.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def test_discover_packages():
110110
return_value={PackageDescriptor('/extension1/pkg1')})
111111
extensions['extension2'].discover = Mock(
112112
return_value={PackageDescriptor('/extension2/pkg1')})
113+
extensions['extension2'].has_parameters = Mock(return_value=None)
113114

114115
descs = discover_packages(None, None, discovery_extensions=extensions)
115116
assert len(descs) == 2
@@ -126,11 +127,13 @@ def test_discover_packages():
126127
PackageDescriptor('/extension3/pkg2')})
127128

128129
descs = discover_packages(None, None, discovery_extensions=extensions)
129-
assert len(descs) == 2
130+
assert len(descs) == 3
130131
expected_path = '/extension3/pkg1'.replace('/', os.sep)
131132
assert expected_path in (str(d.path) for d in descs)
132133
expected_path = '/extension3/pkg2'.replace('/', os.sep)
133134
assert expected_path in (str(d.path) for d in descs)
135+
expected_path = '/extension2/pkg1'.replace('/', os.sep)
136+
assert expected_path in (str(d.path) for d in descs)
134137

135138

136139
def test_expand_dir_wildcards():

0 commit comments

Comments
 (0)