-
Notifications
You must be signed in to change notification settings - Fork 50
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
base: master
Are you sure you want to change the base?
Conversation
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.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #685 +/- ##
==========================================
+ Coverage 87.28% 87.30% +0.01%
==========================================
Files 68 68
Lines 3949 3953 +4
Branches 760 761 +1
==========================================
+ Hits 3447 3451 +4
Misses 396 396
Partials 106 106 ☔ View full report in Codecov by Sentry. |
if has_parameter: | ||
with_parameters[extension.PACKAGE_DISCOVERY_NAME] = extension | ||
return with_parameters | ||
if has_parameter is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This nested conditions are hard to read for a newbie in the code like me.
We could go explicit on has_parameter accepted values:
diff --git a/colcon_core/package_discovery/__init__.py b/colcon_core/package_discovery/__init__.py
index 165d7d3..44a897c 100644
--- a/colcon_core/package_discovery/__init__.py
+++ b/colcon_core/package_discovery/__init__.py
@@ -236,13 +236,20 @@ def _get_extensions_with_parameters(
'Exception in package discovery extension '
f"'{extension.PACKAGE_DISCOVERY_NAME}': {e}\n{exc}")
# skip failing extension, continue with next one
+ continue
+
+ if has_parameter is True:
+ explicitly_specified = True
+ if has_parameter is False:
+ continue
+ elif has_parameter is None:
+ pass
else:
- if has_parameter is not None:
- if has_parameter:
- explicitly_specified = True
- else:
- continue
- with_parameters[extension.PACKAGE_DISCOVERY_NAME] = extension
+ assert 'has_parameter returned a value different of True, '\
+ 'False or None'
+
+ with_parameters[extension.PACKAGE_DISCOVERY_NAME] = extension
+
return with_parameters if explicitly_specified else OrderedDict()
or in a more packed form:
--- a/colcon_core/package_discovery/__init__.py
+++ b/colcon_core/package_discovery/__init__.py
@@ -236,13 +236,15 @@ def _get_extensions_with_parameters(
'Exception in package discovery extension '
f"'{extension.PACKAGE_DISCOVERY_NAME}': {e}\n{exc}")
# skip failing extension, continue with next one
- else:
- if has_parameter is not None:
- if has_parameter:
- explicitly_specified = True
- else:
- continue
- with_parameters[extension.PACKAGE_DISCOVERY_NAME] = extension
+ continue
+
+ if has_parameter is False:
+ continue
+ elif has_parameter:
+ explicitly_specified = True
+
+ with_parameters[extension.PACKAGE_DISCOVERY_NAME] = extension
+
return with_parameters if explicitly_specified else OrderedDict()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes look good, a minor suggestion to improve readability
The current implementation of package discovery follows one of two paths:
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.