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

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.51%. Comparing base (a74fa97) to head (e14eb19).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #685      +/-   ##
==========================================
+ Coverage   87.28%   87.51%   +0.23%     
==========================================
  Files          68       70       +2     
  Lines        3949     4054     +105     
  Branches      760      784      +24     
==========================================
+ Hits         3447     3548     +101     
  Misses        396      396              
- Partials      106      110       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does e14eb19 look better? I'm trying to keep the boolean semantics from the original implementation without actually checking that the type is bool (i.e. comparing directly with True/False)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better yes, thanks!

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

@cottsay cottsay requested a review from j-rivero March 12, 2025 14:19
@cottsay cottsay merged commit da76fb4 into master Mar 12, 2025
36 checks passed
@cottsay cottsay deleted the cottsay/passive-package-discovery branch March 12, 2025 22:58
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