[Notes] [Git][BuildStream/buildstream][phil/848-plugin-deprecation-warnings] plugin.py: Add API to allow plugins to raise deprecation warnings



Title: GitLab

Phil Dawson pushed to branch phil/848-plugin-deprecation-warnings at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • buildstream/_project.py
    ... ... @@ -232,7 +232,8 @@ class Project():
    232 232
                 'artifacts', 'options',
    
    233 233
                 'fail-on-overlap', 'shell', 'fatal-warnings',
    
    234 234
                 'ref-storage', 'sandbox', 'mirrors', 'remote-execution',
    
    235
    -            'sources', '(@)'
    
    235
    +            'sources', '(@)',
    
    236
    +            'supress-deprecation-warnings'
    
    236 237
             ])
    
    237 238
     
    
    238 239
         # create_element()
    
    ... ... @@ -428,6 +429,10 @@ class Project():
    428 429
     
    
    429 430
             self._validate_node(pre_config_node)
    
    430 431
     
    
    432
    +        # Load plugin deprecation warning supression config
    
    433
    +        self.supressed_deprecation_warnings = _yaml.node_get(
    
    434
    +            pre_config_node, list, 'supress-deprecation-warnings', default_value=[])
    
    435
    +
    
    431 436
             # FIXME:
    
    432 437
             #
    
    433 438
             #   Performing this check manually in the absense
    

  • buildstream/plugin.py
    ... ... @@ -164,6 +164,25 @@ class Plugin():
    164 164
            core format version :ref:`core format version <project_format_version>`.
    
    165 165
         """
    
    166 166
     
    
    167
    +    BST_PLUGIN_DEPRECATED = False
    
    168
    +    """True if this element plugin has been deprecated.
    
    169
    +
    
    170
    +    If this is set to true, the plugin will call self.eimit_deprecation_warning()
    
    171
    +    on instantiation. Plugin authors may override this method to provide
    
    172
    +    custom deprecation warnings
    
    173
    +
    
    174
    +    *Since 1.4*
    
    175
    +    """
    
    176
    +
    
    177
    +    BST_PLUGIN_DEPRECATION_MESSAGE = ""
    
    178
    +    """ The message printed when this element shows a deprecation warning.
    
    179
    +
    
    180
    +    This should be set if BST_PLUGIN_DEPRECATED is True and should direct the user
    
    181
    +    to the deprecated plug-in's replacement.
    
    182
    +
    
    183
    +    *Since 1.4*
    
    184
    +    """
    
    185
    +
    
    167 186
         def __init__(self, name, context, project, provenance, type_tag):
    
    168 187
     
    
    169 188
             self.name = name
    
    ... ... @@ -188,6 +207,14 @@ class Plugin():
    188 207
             self.__kind = modulename.split('.')[-1]
    
    189 208
             self.debug("Created: {}".format(self))
    
    190 209
     
    
    210
    +        # If this plugin has been deprecated, emit a warning.
    
    211
    +        silenced_warnings = self.__project.supressed_deprecation_warnings
    
    212
    +        if self.BST_PLUGIN_DEPRECATED and self.__kind not in silenced_warnings:
    
    213
    +            self.__context.message(
    
    214
    +                Message(message_type=MessageType.WARN,
    
    215
    +                        detail="Using deprecated plugin {}: {}".format(
    
    216
    +                            self.__kind, BST_PLUGIN_DEPRECATION_MESSAGE)))
    
    217
    +
    
    191 218
         def __del__(self):
    
    192 219
             # Dont send anything through the Message() pipeline at destruction time,
    
    193 220
             # any subsequent lookup of plugin by unique id would raise KeyError.
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]