def prereleaser_middle(data):
    """
    zest.releaser prerelease middle hook for gevent.

    The prerelease step:

        asks you for a version number
        updates the setup.py or version.txt and the
        CHANGES/HISTORY/CHANGELOG file (with either
        this new version
        number and offers to commit those changes to git

    The middle hook:

        All data dictionary items are available and some questions
        (like new version number) have been asked.
        No filesystem changes have been made yet.

    It is our job to finish up the filesystem changes needed, including:

    - Calling towncrier to handle CHANGES.rst
    - Add the version number to ``versionadded``, ``versionchanged`` and
      ``deprecated`` directives in Python source.
    """
    if data['name'] != 'gevent':
        return
    import re
    import os
    import subprocess
    from gevent.testing import modules
    new_version = data['new_version']
    subprocess.check_call(['towncrier', 'build', '--version', data[
        'new_version'], '--yes'])
    data['update_history'] = False
    subprocess.check_call(['git', 'restore', '--staged', 'CHANGES.rst'])
    regex = re.compile(b'.. (versionchanged|versionadded|deprecated):: NEXT')
    if not isinstance(new_version, bytes):
        new_version_bytes = new_version.encode('ascii')
    else:
        new_version_bytes = new_version
    new_version_bytes = new_version.encode('ascii')
    replacement = b'.. \\1:: %s' % (new_version_bytes,)
    for path, _ in modules.walk_modules(basedir=os.path.join(data[
        'reporoot'], 'src', 'gevent'), recursive=True, include_tests=True,
        excluded_modules=(), include_so=False, check_optional=False):
        with open(path, 'rb') as f:
            contents = f.read()
        new_contents, count = regex.subn(replacement, contents)
        if count:
            print('Replaced version NEXT in', path)
            with open(path, 'wb') as f:
                f.write(new_contents)
