Calls a block of code with a modified set of environment variables,
 restoring them once the code has executed.

 @param env [Hash] environment variables to set
352276
def with_environment(env)
      old_env = {}
      env.each do |var, value|
        old_env[var] = ENV[var.to_s]
        ENV[var.to_s] = value
      end

      yield
    ensure
      old_env.each { |var, value| ENV[var.to_s] = value }
    end
502753
public void setNewenvironment(final boolean newenv) {
    this.compilerDef.setNewenvironment(newenv);
    for (int i = 0; i < this._compilers.size(); i++) {
      final CompilerDef currentCompilerDef = this._compilers.elementAt(i);
      currentCompilerDef.setNewenvironment(newenv);
    }
    this.linkerDef.setNewenvironment(newenv);
  }
74604
def set_environment_variable(self, key, val):
        
        if self.get_environment_variable(key) in [None, val]:
            self.__dict__['environment_variables'][key] = val
        else:
            raise Contradiction("Could not set environment variable %s" % (key))
1192542
private void setEnvironmentVariable(String line) {
        Matcher matcher = ENV_VAR_PATTERN.matcher(line);
        if (matcher.matches()) {
            String key = matcher.group("key");
            String value = matcher.group("value");
            log.debug("Env: %s=%s",key,value);
            env.put(key, value);
        }
    }
542766
public void addEnv(final Environment.Variable var) {
    if (this.env == null) {
      this.env = new Environment();
      this.newEnvironment = true;
      if (this.processor != null) {
        // Change the environment in the processor
        setProcessor(this.processor);
      }
    }
    this.env.addVariable(var);
  }
597489
def environment_variables
      global_variables = @config.environment_variables
      process_vars = @config.process_options[@name] ? @config.process_options[@name]['env'] || {} : {}
      process_local_vars = @config.local_process_options[@name] ? @config.local_process_options[@name]['env'] || {} : {}
      global_variables.merge(process_vars.merge(process_local_vars)).each_with_object({}) do |(key, value), hash|
        hash[key.to_s] = value.to_s
      end
    end
186346
def init(envVarName, enableColorOutput=False):
    
    global _initialized

    if _initialized:
        return

    global _ENV_VAR_NAME
    _ENV_VAR_NAME = envVarName

    if enableColorOutput:
        _preformatLevels(envVarName + "_NO_COLOR")
    else:
        _preformatLevels(None)

    if envVarName in os.environ:
        # install a log handler that uses the value of the environment var
        setDebug(os.environ[envVarName])
    addLimitedLogHandler(stderrHandler)

    _initialized = True
1333923
public static function setEnvVariables()
    {
        $env_variables = [];

        if (file_exists(static::projectRoot() . '/.env')) {
            $env_variables = (new Dotenv(static::projectRoot()))
                ->load();
        }

        self::$projectEnv = $env_variables;
    }
142650
public static function setEnvironmentVariable($name, $value = null)
        {
            list($name, $value) = static::normaliseEnvironmentVariable($name, $value);

            // Don't overwrite existing environment variables if we're immutable
            // Ruby's dotenv does this with `ENV[key] ||= value`.
            if (true === static::$immutable && false === is_null(static::findEnvironmentVariable($name))) {
                return;
            }

            putenv("$name=$value");

            $_ENV[$name] = $value;
            $_SERVER[$name] = $value;
        }
774663
def call_env_updated(cls, kb_app,
                         sphinx_app: Sphinx,
                         sphinx_env: BuildEnvironment):

        
        for callback in EventAction.get_callbacks(kb_app, SphinxEvent.EU):
            callback(kb_app, sphinx_app, sphinx_env)
1180625
def add(key, value)
    if @env.has_key?(key)
      @env[key] += value
    else
      set(key,value)
    end
  end
1244179
public function setEnvironmentVariable($name, $value = null)
    {
        list($name, $value) = $this->normaliseEnvironmentVariable($name, $value);

        // Don't overwrite existing environment variables if we're immutable
        // Ruby's dotenv does this with `ENV[key] ||= value`.
        if ($this->immutable === true && !is_null($this->getEnvironmentVariable($name))) {
            return;
        }

        $_ENV[$name] = $value;
        $_SERVER[$name] = $value;
        putenv("$name=$value");
    }
430615
def update_from_env(yaml_dict, prefix=None):
    '''
    
    '''
    prefix = prefix or ""

    def _set_env_var(path, node):
        env_path = "{0}{1}{2}".format(
            prefix.upper(),
            '_' if prefix else '',
            '_'.join([str(key).upper() for key in path])
        )
        env_val = os.environ.get(env_path, None)
        if env_val is not None:
            # convert the value to a YAML-defined type
            env_dict = yamldict.load('val: {0}'.format(env_val))
            return env_dict.val
        else:
            return None

    # traverse yaml_dict with the callback function
    yaml_dict.traverse(_set_env_var)
1165172
def apply_environment!(hook_context, env)
      skipped_hooks = "#{env['SKIP']} #{env['SKIP_CHECKS']} #{env['SKIP_HOOKS']}".split(/[:, ]/)
      only_hooks = env.fetch('ONLY') { '' }.split(/[:, ]/)
      hook_type = hook_context.hook_class_name

      if only_hooks.any? || skipped_hooks.include?('all') || skipped_hooks.include?('ALL')
        @hash[hook_type]['ALL']['skip'] = true
      end

      only_hooks.select { |hook_name| hook_exists?(hook_context, hook_name) }.
                 map { |hook_name| Overcommit::Utils.camel_case(hook_name) }.
                 each do |hook_name|
        @hash[hook_type][hook_name] ||= {}
        @hash[hook_type][hook_name]['skip'] = false
      end

      skipped_hooks.select { |hook_name| hook_exists?(hook_context, hook_name) }.
                    map { |hook_name| Overcommit::Utils.camel_case(hook_name) }.
                    each do |hook_name|
        @hash[hook_type][hook_name] ||= {}
        @hash[hook_type][hook_name]['skip'] = true
      end
    end
223701
function applyEnv(env, secrets = {}, required = {}) {
  if (Array.isArray(env)) {
    env.forEach(key => {
      // if the key already exists don't overwrite it
      if (!process.env[key]) {
        const value = getValue(key, {}, secrets, required)
        process.env[key] = value
      }
    })
  } else {
    Object.entries(env).forEach(([key, value]) => {
      // if the key already exists don't overwrite it
      if (!process.env[key]) {
        const value = getValue(key, env, secrets, required)
        process.env[key] = value
      }
    })
  }
}
513400
def run(command_line)
      require 'open3'
      env = Hash[environment_vars.map { |k, v| [k.to_s, v.to_s] }]
      Open3.capture2e(env, command_line.to_s)
    end
1215067
def call(env)
      @app.call(env).on_complete do |response_env|
        datetime = sunset_header(response_env.response_headers)
        report_deprecated_usage(env, datetime) unless datetime.nil?
      end
    end