def align_bone_y_axis(obj, bone, vec):
    """ Matches the bone y-axis to
        the given vector.
        Must be in edit mode.
    """
    bone_e = obj.data.edit_bones[bone]
    vec.normalize()
    vec = vec * bone_e.length
    bone_e.tail = bone_e.head + vec
