Pulled from Honcho code with minor updates, reads local default
    environment variables from a .env file located in the project root
    directory.
355296
def read(env_file=".env"):
    
    try:
        with open(env_file) as f:
            content = f.read()

    except IOError:
        content = ''

    for line in content.splitlines():

        m1 = re.match(r'\A([A-Za-z_0-9]+)=(.*)\Z', line)
        if m1:
            key, val = m1.group(1), m1.group(2)
            m2 = re.match(r"\A'(.*)'\Z", val)
            if m2:
                val = m2.group(1)
            m3 = re.match(r'\A"(.*)"\Z', val)
            if m3:
                val = re.sub(r'\\(.)', r'\1', m3.group(1))
            os.environ.setdefault(key, val)
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
1329615
def get_environment(name):
    """"""
    if name == "_default":
        return env_from_template(name)
    filename = os.path.join("environments", name + ".json")
    try:
        with open(filename) as f:
            try:
                return json.loads(f.read())
            except ValueError as e:
                msg = 'LittleChef found the following error in'
                msg += ' "{0}":\n                {1}'.format(filename, str(e))
                abort(msg)
    except IOError:
        raise FileNotFoundError('File {0} not found'.format(filename))
854715
private static function get_process_env_variables() {
		// Ensure we're using the expected `wp` binary
		$bin_dir        = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( dirname( dirname( __DIR__ ) ) . '/bin' );
		$vendor_dir     = self::get_vendor_dir();
		$path_separator = Utils\is_windows() ? ';' : ':';
		$env            = array(
			'PATH'      => $bin_dir . $path_separator . $vendor_dir . $path_separator . getenv( 'PATH' ),
			'BEHAT_RUN' => 1,
			'HOME'      => sys_get_temp_dir() . '/wp-cli-home',
		);

		$config_path = getenv( 'WP_CLI_CONFIG_PATH' );
		if ( false !== $config_path ) {
			$env['WP_CLI_CONFIG_PATH'] = $config_path;
		}

		$term = getenv( 'TERM' );
		if ( false !== $term ) {
			$env['TERM'] = $term;
		}

		$php_args = getenv( 'WP_CLI_PHP_ARGS' );
		if ( false !== $php_args ) {
			$env['WP_CLI_PHP_ARGS'] = $php_args;
		}

		$php_used = getenv( 'WP_CLI_PHP_USED' );
		if ( false !== $php_used ) {
			$env['WP_CLI_PHP_USED'] = $php_used;
		}

		$php = getenv( 'WP_CLI_PHP' );
		if ( false !== $php ) {
			$env['WP_CLI_PHP'] = $php;
		}

		$travis_build_dir = getenv( 'TRAVIS_BUILD_DIR' );
		if ( false !== $travis_build_dir ) {
			$env['TRAVIS_BUILD_DIR'] = $travis_build_dir;
		}

		$github_token = getenv( 'GITHUB_TOKEN' );
		if ( false !== $github_token ) {
			$env['GITHUB_TOKEN'] = $github_token;
		}
		return $env;
	}
385793
def find_dotenv(filename='.env', raise_error_if_not_found=False, usecwd=False):
    
    if usecwd or '__file__' not in globals():
        # should work without __file__, e.g. in REPL or IPython notebook
        path = os.getcwd()
    else:
        # will work for .py files
        frame_filename = sys._getframe().f_back.f_code.co_filename
        path = os.path.dirname(os.path.abspath(frame_filename))

    for dirname in _walk_to_root(path):
        check_path = os.path.join(dirname, filename)
        if os.path.exists(check_path):
            return check_path

    if raise_error_if_not_found:
        raise IOError('File not found')

    return ''
658590
def _include_environment_variables(self, program, executor_vars):
        """"""
        env_vars = {
            'RESOLWE_HOST_URL': self.settings_actual.get('RESOLWE_HOST_URL', 'localhost'),
        }

        set_env = self.settings_actual.get('FLOW_EXECUTOR', {}).get('SET_ENV', {})
        env_vars.update(executor_vars)
        env_vars.update(set_env)

        export_commands = ['export {}={}'.format(key, shlex.quote(value)) for key, value in env_vars.items()]
        return os.linesep.join(export_commands) + os.linesep + program
70219
def get_env():
    
    if not __ENV__:
        env = os.environ["env"] if "env" in os.environ else "Dev"
        set_env(env)
    return __ENV__
1014684
def read_envfile(path=None, **overrides):
        
        if path is None:
            frame = inspect.currentframe().f_back
            caller_dir = os.path.dirname(frame.f_code.co_filename)
            path = os.path.join(os.path.abspath(caller_dir), '.env')

        try:
            with open(path, 'r') as f:
                content = f.read()
        except getattr(__builtins__, 'FileNotFoundError', IOError):
            logger.debug('envfile not found at %s, looking in parent dir.',
                         path)
            filedir, filename = os.path.split(path)
            pardir = os.path.abspath(os.path.join(filedir, os.pardir))
            path = os.path.join(pardir, filename)
            if filedir != pardir:
                Env.read_envfile(path, **overrides)
            else:
                # Reached top level directory.
                warnings.warn('Could not any envfile.')
            return

        logger.debug('Reading environment variables from: %s', path)
        for line in content.splitlines():
            tokens = list(shlex.shlex(line, posix=True))
            # parses the assignment statement
            if len(tokens) < 3:
                continue
            name, op = tokens[:2]
            value = ''.join(tokens[2:])
            if op != '=':
                continue
            if not re.match(r'[A-Za-z_][A-Za-z_0-9]*', name):
                continue
            value = value.replace(r'\n', '\n').replace(r'\t', '\t')
            os.environ.setdefault(name, value)

        for name, value in overrides.items():
            os.environ.setdefault(name, value)
545590
def env_vars(self):
        """"""
        if not self.no_libfaketime:
            faketime_filename = self.service_group.hitch_dir.faketime()

            env_vars = dict(os.environ)
            env_vars.update(self._env_vars)
            env_vars.update(faketime.get_environment_vars(faketime_filename))
        else:
            env_vars = dict(os.environ)
            env_vars.update(self._env_vars)
        return env_vars
1230345
def initialize_env(env_file=None, fail_silently=True, load_globally=True):
    
    data = {}
    data.update(os.environ)
    if env_file:
        data.update(read_file_values(env_file, fail_silently))
    
    if load_globally:
        os.environ.update(data)
    
    return Environment(env_dict=data)
580319
function env(environment) {
  environment = environment || {};

  if ('object' === typeof process && 'object' === typeof process.env) {
    env.merge(environment, process.env);
  }

  if ('undefined' !== typeof window) {
    if ('string' === window.name && window.name.length) {
      env.merge(environment, env.parse(window.name));
    }

    if (window.localStorage) {
      try { env.merge(environment, env.parse(window.localStorage.env || window.localStorage.debug)); }
      catch (e) {}
    }

    if (
         'object' === typeof window.location
      && 'string' === typeof window.location.hash
      && window.location.hash.length
    ) {
      env.merge(environment, env.parse(window.location.hash.charAt(0) === '#'
        ? window.location.hash.slice(1)
        : window.location.hash
      ));
    }
  }

  //
  // Also add lower case variants to the object for easy access.
  //
  var key, lower;
  for (key in environment) {
    lower = key.toLowerCase();

    if (!(lower in environment)) {
      environment[lower] = environment[key];
    }
  }

  return environment;
}
51328
private static function get_process_env_variables() {
		// Ensure we're using the expected `wp` binary
		$bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( __DIR__ . '/../../bin' );
		$vendor_dir = realpath( __DIR__ . '/../../vendor/bin' );
		$path_separator = Utils\is_windows() ? ';' : ':';
		$env = array(
			'PATH' =>  $bin_dir . $path_separator . $vendor_dir . $path_separator . getenv( 'PATH' ),
			'BEHAT_RUN' => 1,
			'HOME' => sys_get_temp_dir() . '/wp-cli-home',
		);
		if ( $config_path = getenv( 'WP_CLI_CONFIG_PATH' ) ) {
			$env['WP_CLI_CONFIG_PATH'] = $config_path;
		}
		if ( $term = getenv( 'TERM' ) ) {
			$env['TERM'] = $term;
		}
		if ( $php_args = getenv( 'WP_CLI_PHP_ARGS' ) ) {
			$env['WP_CLI_PHP_ARGS'] = $php_args;
		}
		if ( $php_used = getenv( 'WP_CLI_PHP_USED' ) ) {
			$env['WP_CLI_PHP_USED'] = $php_used;
		}
		if ( $php = getenv( 'WP_CLI_PHP' ) ) {
			$env['WP_CLI_PHP'] = $php;
		}
		if ( $travis_build_dir = getenv( 'TRAVIS_BUILD_DIR' ) ) {
			$env['TRAVIS_BUILD_DIR'] = $travis_build_dir;
		}
		if ( $github_token = getenv( 'GITHUB_TOKEN' ) ) {
			$env['GITHUB_TOKEN'] = $github_token;
		}
		return $env;
	}
845024
def get_env(name, default=None):
    """"""
    if name in os.environ:
        return os.environ[name]

    if default is not None:
        return default

    error_msg = "Set the {} env variable".format(name)
    raise ImproperlyConfigured(error_msg)
717751
public static String readEnvironment(String environmentName, String defaultValue) {
		String property = System.getenv(environmentName);
		if (isNullOrEmpty(property)) {
			return defaultValue;
		}
		return property;
	}
386539
def init_environment():
        """"""
        base_path = os.path.abspath(os.path.dirname(__file__))
        env_path = '{0}/.env'.format(base_path)
        if os.path.exists(env_path):
            with open(env_path) as f:
                lines = f.readlines()
                for line in lines:
                    var = line.strip().split('=')
                    if len(var) == 2:
                        os.environ[var[0]] = var[1]
55622
private Properties getEnvVars()
    {
        Process p = null;
        Properties envVars = new Properties();

        try
        {
            Runtime r = Runtime.getRuntime();
            String OS = System.getProperty("os.name").toLowerCase();

            if (OS.indexOf("windows 9") > -1)
            {
                p = r.exec("command.com /c set");
            }
            else if ((OS.indexOf("nt") > -1) ||
                     (OS.indexOf("windows 2000") > -1) ||
                     (OS.indexOf("windows xp") > -1))
            {
                p = r.exec("cmd.exe /c set");
            }
            else
            {
                // our last hope, we assume Unix (thanks to H. Ware for the fix)
                p = r.exec("env");
            }
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while((line = br.readLine()) != null)
            {
                int idx = line.indexOf('=');
                String key = line.substring(0, idx);
                String value = line.substring(idx + 1);
                envVars.setProperty(key, value);
            }
        }
        catch (Exception ExIgnore)
        {
        }
        return envVars;
    }
300891
def file_envs(self, load=None):
        '''
        
        '''
        if load is None:
            load = {}
        load.pop('cmd', None)
        return self.envs(**load)