Sometime you want to emulate the action of "source" in bash,
    settings some environment variables. Here is a way to do it.

def shell_source(script):
    """Sometime you want to emulate the action of "source" in bash,
    settings some environment variables. Here is a way to do it."""
    pipe = subprocess.Popen(
        ". %s; env" % script, stdout=subprocess.PIPE, shell=True)
    output = pipe.communicate()[0].decode()
    env = {}
    for line in output.splitlines():
        try:
            keyval = line.split("=", 1)
            env[keyval[0]] = keyval[1]
        except:
            pass

    os.environ.update(env)