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

A deprecated option past its removal version should fail eagerly #7335

Open
stuhood opened this issue Mar 7, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@stuhood
Copy link
Member

commented Mar 7, 2019

Currently (as demonstrated in #7332 and #7325), the removal_version in options registration is not triggering an eager failure once the version has been bumped.

I believe that the register(..) call itself used to fail immediately when given a version in the past. Assuming that we want that behaviour, we should restore it.

@cosmicexplorer

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2019

This would be a really useful fix and probably turn up some bugs we haven't noticed yet.

@cosmicexplorer

This comment has been minimized.

Copy link
Contributor

commented Apr 23, 2019

To give a little closer view of how this might be solved:

  1. Start by reading the pants task developer's guide to understand how options are registered.
  2. Continue by reading options.py and parser.py -- take note of the _check_deprecated() method, which validates that the pants version is less than the declared deprecation version for the option:
    def _check_deprecated(self, dest, kwargs):
    """Checks option for deprecation and issues a warning/error if necessary."""
    removal_version = kwargs.get('removal_version', None)
    if removal_version is not None:
    warn_or_error(
    removal_version=removal_version,
    deprecated_entity_description="option '{}' in {}".format(dest, self._scope_str()),
    deprecation_start_version=kwargs.get('deprecation_start_version', None),
    hint=kwargs.get('removal_hint', None),
    stacklevel=9999) # Out of range stacklevel to suppress printing src line.

    Note that deprecation checking methods come from deprecated.py.
  3. In parser.py, ensure the _check_deprecated() method is called "eagerly" -- meaning, within the register() method invocation, not when the option is accessed. Note that there's a lot of indirection that goes into a register() call -- you'll have to think about which level of abstraction to edit. This is the fun part!
  4. Add a unit test in test_options.py, likely by adding an option with a deprecated version, kind of like here:
    # Test deprecated options with a scope

    However, we'd want to make sure that register() call (wrapped with a self.assertRaisesWithMessage(...) contextmanager) is done in its own test method, instead of that global register method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.