[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:

7 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,13 @@ 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
    +            detail = "Using deprecated plugin {}: {}".format(self.__kind,
    
    214
    +                                                             self.BST_PLUGIN_DEPRECATION_MESSAGE)
    
    215
    +            self.__message(MessageType.WARN, detail)
    
    216
    +
    
    191 217
         def __del__(self):
    
    192 218
             # Dont send anything through the Message() pipeline at destruction time,
    
    193 219
             # any subsequent lookup of plugin by unique id would raise KeyError.
    

  • tests/plugins/basics/deprecationwarnings/deprecationwarnings.py
    1
    +import pytest
    
    2
    +import tempfile
    
    3
    +import os
    
    4
    +from tests.testutils import cli
    
    5
    +import buildstream.plugins.elements.manual
    
    6
    +
    
    7
    +
    
    8
    +DATA_DIR = os.path.join(
    
    9
    +    os.path.dirname(os.path.realpath(__file__)),
    
    10
    +    "project"
    
    11
    +)
    
    12
    +
    
    13
    +_DEPRECATION_MESSAGE = "Here is some detail."
    
    14
    +_DEPRECATION_WARNING = "Using deprecated plugin deprecated_plugin: {}".format(_DEPRECATION_MESSAGE)
    
    15
    +
    
    16
    +
    
    17
    +@pytest.mark.datafiles(DATA_DIR)
    
    18
    +def test_deprecation_warning_present(cli, datafiles):
    
    19
    +    project = os.path.join(datafiles.dirname, datafiles.basename)
    
    20
    +    result = cli.run(project=project, args=['show', 'deprecated.bst'])
    
    21
    +    result.assert_success()
    
    22
    +    assert _DEPRECATION_WARNING in result.stderr
    
    23
    +
    
    24
    +
    
    25
    +@pytest.mark.datafiles(DATA_DIR)
    
    26
    +def test_supress_deprecation_warning(cli, datafiles):
    
    27
    +    project = os.path.join(datafiles.dirname, datafiles.basename)
    
    28
    +    result = cli.run(project=project, args=['show', 'manual.bst'])
    
    29
    +
    
    30
    +    project_conf = os.path.join(project, 'project.conf')
    
    31
    +    with open(project_conf, 'a') as f:
    
    32
    +        f.write('\nsupress-deprecation-warnings: [deprecated_plugin]')
    
    33
    +
    
    34
    +    result = cli.run(project=project, args=['show', 'deprecated.bst'])
    
    35
    +
    
    36
    +    result.assert_success()
    
    37
    +    assert _DEPRECATION_WARNING not in result.stderr

  • tests/plugins/basics/deprecationwarnings/project/elements/deprecated.bst
    1
    +kind: deprecated_plugin
    \ No newline at end of file

  • tests/plugins/basics/deprecationwarnings/project/plugins/elements/deprecated_plugin.py
    1
    +from buildstream import BuildElement, SandboxFlags
    
    2
    +
    
    3
    +
    
    4
    +class DeprecatedPlugin(BuildElement):
    
    5
    +    BST_PLUGIN_DEPRECATED = True
    
    6
    +    BST_PLUGIN_DEPRECATION_MESSAGE = "Here is some detail."
    
    7
    +
    
    8
    +
    
    9
    +# Plugin entry point
    
    10
    +def setup():
    
    11
    +    return DeprecatedPlugin

  • tests/plugins/basics/deprecationwarnings/project/plugins/elements/deprecated_plugin.yaml
    1
    +# Deprecated-plugin build element does not provide any default
    
    2
    +# build commands
    
    3
    +config:
    
    4
    +
    
    5
    +  # Commands for configuring the software
    
    6
    +  #
    
    7
    +  configure-commands: []
    
    8
    +
    
    9
    +  # Commands for building the software
    
    10
    +  #
    
    11
    +  build-commands: []
    
    12
    +
    
    13
    +  # Commands for installing the software into a
    
    14
    +  # destination folder
    
    15
    +  #
    
    16
    +  install-commands: []
    
    17
    +
    
    18
    +  # Commands for stripping installed binaries
    
    19
    +  #
    
    20
    +  strip-commands:
    
    21
    +  - |
    
    22
    +    %{strip-binaries}
    \ No newline at end of file

  • tests/plugins/basics/deprecationwarnings/project/project.conf
    1
    +# Unique project name
    
    2
    +name: deprecation-warnings
    
    3
    +
    
    4
    +# Required BuildStream format version
    
    5
    +format-version: 20
    
    6
    +
    
    7
    +# Subdirectory where elements are stored
    
    8
    +element-path: elements
    
    9
    +
    
    10
    +plugins:
    
    11
    +
    
    12
    +- origin: local
    
    13
    +  path: plugins/elements
    
    14
    +  elements:
    
    15
    +    deprecated_plugin: 0



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