def _setup_environment(self, environments, home_dir, temp_dir):
        """Return map with desired environment variables for run."""
        # If keepEnv is set or sudo is used, start from a fresh environment,
        # otherwise with the current one.
        # Set HOME and TMPDIR to the temporary directories create above.
        # keepEnv specifies variables to copy from the current environment,
        # newEnv specifies variables to set to a new value,
        # additionalEnv specifies variables where some value should be appended, and
        # clearEnv specifies variables to delete.
        if self._user is not None or environments.get("keepEnv", None) is not None:
            run_environment = {}
        else :
            run_environment = os.environ.copy()
        run_environment["HOME"] = home_dir
        run_environment["TMPDIR"] = temp_dir
        run_environment["TMP"] = temp_dir
        run_environment["TEMPDIR"] = temp_dir
        run_environment["TEMP"] = temp_dir
        for key, value in environments.get("keepEnv", {}).items():
            if key in os.environ:
                run_environment[key] = os.environ[key]
        for key, value in environments.get("newEnv", {}).items():
            run_environment[key] = value
        for key, value in environments.get("additionalEnv", {}).items():
            run_environment[key] = os.environ.get(key, "") + value
        for key in environments.get("clearEnv", {}).items():
            run_environment.pop(key, None)

        logging.debug("Using additional environment %s.", environments)
        return run_environment
dataset/ETHPy150Open sosy-lab/benchexec/benchexec/runexecutor.py/RunExecutor._setup_environment/original