ansible / proposals

Repository for sharing and tracking progress on enhancement proposals for Ansible.
Creative Commons Zero v1.0 Universal
93 stars 19 forks source link

Add more flexible 'deprecation' support. #32

Closed alikins closed 3 years ago

alikins commented 7 years ago

Proposal: Add more flexible 'deprecation' support.

Author: Adrian Likins alikins@redhat.com Date: 2016-10-10

During the preparation of major releases, the process of updating deprecations is a significant amount of work and can be trouble prone. Deprecations need to be found and documented, and code needs to be updated to remove deprecated code and warn/error on it's use.

Problems

What problems exist that this proposal will solve?

In the future, could also support:

Example deprecation definitions:


class SudoUsage(Deprecation):
    label = SUDO_USAGE
    version = None
    removed = None
    message = "Instead of sudo/sudo_user, use become/become_user and set become_method to 'sudo' (default is sudo)")

class MergeMultipleCliSkipTags(Deprecation):
    label = MERGE_MULTIPLE_CLI_SKIP_TAGS
    version = 2.5
    removed = False
    message = 'Specifying --skip-tags multiple times on the command line currently uses the last specified value. In 2.4, values will be merged instead.  Set merge_multiple_cli_tags=True in ansible.cfg to get this behavior now.'

    def mitigated(self):
        '''If user has explicitly enable MERGE_MULTIPLE_CLI_TAGS, dont warn.'''
        return C.MERGE_MULTIPLE_CLI_TAGS

class ToBytes(Deprecation):
    label = TO_BYTES
    version = 2.4
    removed = None
    message = u'ansible.utils.unicode.to_bytes is deprecated.  Use ansible.module_utils._text.to_bytes instead'

API deprecation:

from ansible import deprecated

def to_bytes(*args, **kwargs):
    deprecated.check(deprecated.TO_BYTES)
     if 'errors' not in kwargs:
         kwargs['errors'] = 'replace'
     return _to_bytes(*args, **kwargs)

Feature deprecation:

from ansible import deprecated
<...>
def _preprocess_data_become(self, ds):
    <...>
    deprecated.check(deprecated.SUDO_USAGE)

Dependencies (optional)

Depends on final implementation, but there is no external deps required currently.

Testing (optional)

Some similar tools (mostly focused on API deprecation)

jctanner commented 7 years ago

related https://github.com/ansible/ansible/pull/18470

jctanner commented 7 years ago

related https://github.com/ansible/ansible/issues/18559

abadger commented 7 years ago

-1. Adding registration is something that static language practitioners naturally reach for but isn't natural for dynamic languages. It gets in the way of both reading and writing code by forcing you to break out of the flow of the problem you are working on and into defining the type for an unrelated system. Reading through the reasons for this proposal, most of them can be solved without centralized registration. The only thing that is helped by registration is being able to list all of the deprecations in the code base. And that's justified for the purposes of building release notes, not an end user need (the end user needs to know what deprecations affect them, not all the potential deprecations exist). Listing all deprecations also doesn't work as it only registers code that has been reached at the time it has been called. Code that hasn't been reached at that point will not be included.

bcoca commented 7 years ago

-1 also, mostly I agree with @abadger there are much simpler solutions to deal with listing the deprecations for the changelog (i.e. grep) which, unlike the code, will deal with ALL of them, not just the ones in the branches of code hit.

bcoca commented 3 years ago

Closing as most of the problems stated have been addressed in alternative ways, we now have facilities to list deprecations and a process to handle removal on every new release cycle.