def parse_version(version_str):
    """
    Parse the bazel version string, returning a tuple.

    Derived from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/version_check.bzl

    Args:
        version_str: The version string to parse.

    Returns:
        The tuple of version elements.

    """

    # Extract just the semver part
    semver_str = version_str.partition(" ")[0].partition("-")[0]

    # Return version tuple
    return tuple([n for n in semver_str.split(".")])