def finalize_env(env):
    """
    Produce a platform specific env for passing into subprocess.Popen
    family of external process calling methods, and the supplied env
    will be updated on top of it.  Returns a new env.
    """

    keys = _PLATFORM_ENV_KEYS.get(sys.platform, [])
    if 'PATH' not in keys:
        # this MUST be available due to Node.js (and others really)
        # needing something to look for binary locations when it shells
        # out to other binaries.
        keys.append('PATH')
    results = {
        key: os.environ.get(key, '') for key in keys
    }
    results.update(env)
    return results
Produce a platform specific env for passing into subprocess.Popen
    family of external process calling methods, and the supplied env
    will be updated on top of it.  Returns a new env.