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

Extend package discovery to support passive mechanisms #685

Merged
merged 2 commits into from
Mar 12, 2025
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
16 changes: 11 additions & 5 deletions colcon_core/package_discovery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class PackageDiscoveryExtensionPoint:
"""

"""The version of the discovery extension interface."""
EXTENSION_POINT_VERSION = '1.0'
EXTENSION_POINT_VERSION = '1.1'

"""The default priority of discovery extensions."""
PRIORITY = 100

def has_default(self):
"""
Check if the extension has a default parameter is none are provided.
Check if the extension has a default parameter if none are provided.

The method is intended to be overridden in a subclass.

Expand Down Expand Up @@ -62,7 +62,9 @@ def has_parameters(self, *, args):
This method must be overridden in a subclass.

:param args: The parsed command line arguments
:returns: True if `discover()` should be called, False otherwise
:returns: True if `discover()` should be called, False if no
parameters were given, or None if this extension has no
parameters to be specified.
:rtype: bool
"""
raise NotImplementedError()
Expand Down Expand Up @@ -219,6 +221,7 @@ def expand_dir_wildcards(paths):
def _get_extensions_with_parameters(
args, discovery_extensions
):
explicitly_specified = False
with_parameters = OrderedDict()
for extension in discovery_extensions.values():
logger.log(
Expand All @@ -235,8 +238,11 @@ def _get_extensions_with_parameters(
# skip failing extension, continue with next one
else:
if has_parameter:
with_parameters[extension.PACKAGE_DISCOVERY_NAME] = extension
return with_parameters
explicitly_specified = True
elif has_parameter is not None:
continue
with_parameters[extension.PACKAGE_DISCOVERY_NAME] = extension
return with_parameters if explicitly_specified else OrderedDict()


def _discover_packages(
Expand Down
5 changes: 4 additions & 1 deletion test/test_package_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def test_discover_packages():
return_value={PackageDescriptor('/extension1/pkg1')})
extensions['extension2'].discover = Mock(
return_value={PackageDescriptor('/extension2/pkg1')})
extensions['extension2'].has_parameters = Mock(return_value=None)

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

descs = discover_packages(None, None, discovery_extensions=extensions)
assert len(descs) == 2
assert len(descs) == 3
expected_path = '/extension3/pkg1'.replace('/', os.sep)
assert expected_path in (str(d.path) for d in descs)
expected_path = '/extension3/pkg2'.replace('/', os.sep)
assert expected_path in (str(d.path) for d in descs)
expected_path = '/extension2/pkg1'.replace('/', os.sep)
assert expected_path in (str(d.path) for d in descs)


def test_expand_dir_wildcards():
Expand Down
Loading