def get_pipe_parent(job):
    """Check if the job has a pipe_from parent and if so return that. If
    the does does not have any pipe targets, the job itself is returned.

    :param job: the job
    :type job: :class:`jip.db.Job`
    :returns: pipe source job or the job itself if no pipe parent is found
    """
    if len(job.pipe_from) > 0:
        ## walk up and add this jobs dependencies
        j = job
        while len(j.pipe_from) > 0:
            j = j.pipe_from[0]
        return get_pipe_parent(j)
    return job