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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cottsay
Copy link
Member

@cottsay cottsay commented Feb 26, 2025

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.

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.
@cottsay cottsay added the enhancement New feature or request label Feb 26, 2025
@cottsay cottsay self-assigned this Feb 26, 2025
Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.30%. Comparing base (a74fa97) to head (37bb393).

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.
📢 Have feedback on the report? Share it here.

if has_parameter:
with_parameters[extension.PACKAGE_DISCOVERY_NAME] = extension
return with_parameters
if has_parameter is not None:
Copy link
Contributor

@j-rivero j-rivero Mar 6, 2025

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()   

Copy link
Contributor

@j-rivero j-rivero left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

2 participants