Reads an .env file and assigns their values to environment variables
480456
function assign(name) {
  const envFileName = _getFileName(name);
  const envPath = path.resolve(config.get('env.rootDirectory'), envFileName);
  const result = dotenv.config({path: envPath});

  if (typeof name !== 'undefined' && result.error) {
    throw result.error;
  }

  _setEnvName(name);
}
1353448
def export_env_string(name, value):
    # type: (AEnvName, AEnvValue) -> ADefine
    """"""
    os.environ[name] = value
    return Define(name, value)
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;
}
353106
def env(var_name, default=False):
    
    try:
        value = os.environ[var_name]
        if str(value).strip().lower() in ['false', 'f', 'no', 'off' '0', 'none', 'null', '', ]:
            return None
        return value
    except:
        from traceback import format_exc
        msg = "Unable to find the %s environment variable.\nUsing the value %s (the default) instead.\n" % (var_name, default)
        sys.stderr.write(format_exc())
        sys.stderr.write(msg)
        return default
1117828
def _setup_environment(self, environments):
        """"""
        # If keepEnv is set or sudo is used, start from a fresh environment,
        # otherwise with the current one.
        # 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()
        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
1341059
def parse_env(content):
    
    values = {}
    for line in content.splitlines():
        lexer = shlex.shlex(line, posix=True)
        tokens = list(lexer)

        # parses the assignment statement
        if len(tokens) < 3:
            continue

        name, op = tokens[:2]
        value = ''.join(tokens[2:])

        if op != '=':
            continue
        if not _ITEM_RE.match(name):
            continue

        value = value.replace(r'\n', '\n')
        value = value.replace(r'\t', '\t')
        values[name] = value
    return values
414925
def parse_env(self, env=None, namespace=None):
        """"""
        env = env or os.environ
        results = {}
        if not namespace:
            namespace = self.prog
        namespace = namespace.upper()  # pylint: disable=no-member
        for option in self._options:
            env_var = option.kwargs.get('env')
            default_env = "%s_%s" % (namespace, option.name.upper())
            if env_var and env_var in env:
                value = env[env_var]
                results[option.dest] = option.type(value)
            elif default_env in env:
                value = env[default_env]
                results[option.dest] = option.type(value)

        return results
1266448
function readFromEnvFile() {
  try {
    // .env file should be in root directory
    const data = require('fs').readFileSync(require('path').join(__dirname, '../../.env'), 'utf8')

    const env = {}
    data.split('\n').filter((v) => {
      return v !== ''
    }).filter((v) => {
      return v.indexOf('#') === -1
    }).forEach((v) => {
      const splitPosition = v.indexOf('=')
      if (splitPosition === -1) {
        return
      }
      // only first '=' will be splitted
      const key = v.slice(0, splitPosition).trim()
      const value = v.slice(splitPosition + 1).trim()
      env[key] = value
    })
    return env
  } catch (err) {
    throw err
  }
}
1270061
function setEnv(env) {
  home.initHomeDir();
  const envFile = path.join(home.getHomePath(), FILE_ENV);
  const envData = {
    env,
  };
  debug('set fie env data : %o', envData);
  debug('set fie to : %s', envFile);
  cacheEnv = null;
  fs.outputJsonSync(envFile, envData);
}
10774
def getenv(option, default=undefined, cast=undefined):
    

    # We can't avoid __contains__ because value may be empty.
    if option in os.environ:
        value = os.environ[option]
    else:
        if isinstance(default, Undefined):
            raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))

        value = default

    if isinstance(cast, Undefined):
        return value

    if cast is bool:
        value = _cast_boolean(value)
    elif cast is list:
        value = [x for x in value.split(',') if x]
    else:
        value = cast(value)

    return value
331914
def Update(self, env, args=None):
        

        values = {}

        # first set the defaults:
        for option in self.options:
            if not option.default is None:
                values[option.key] = option.default

        # next set the value specified in the options file
        for filename in self.files:
            if os.path.exists(filename):
                dir = os.path.split(os.path.abspath(filename))[0]
                if dir:
                    sys.path.insert(0, dir)
                try:
                    values['__name__'] = filename
                    with open(filename, 'r') as f:
                        contents = f.read()
                    exec(contents, {}, values)
                finally:
                    if dir:
                        del sys.path[0]
                    del values['__name__']

        # set the values specified on the command line
        if args is None:
            args = self.args

        for arg, value in args.items():
            added = False
            for option in self.options:
                if arg in list(option.aliases) + [ option.key ]:
                    values[option.key] = value
                    added = True
            if not added:
                self.unknown[arg] = value

        # put the variables in the environment:
        # (don't copy over variables that are not declared as options)
        for option in self.options:
            try:
                env[option.key] = values[option.key]
            except KeyError:
                pass

        # Call the convert functions:
        for option in self.options:
            if option.converter and option.key in values:
                value = env.subst('${%s}'%option.key)
                try:
                    try:
                        env[option.key] = option.converter(value)
                    except TypeError:
                        env[option.key] = option.converter(value, env)
                except ValueError as x:
                    raise SCons.Errors.UserError('Error converting option: %s\n%s'%(option.key, x))


        # Finally validate the values:
        for option in self.options:
            if option.validator and option.key in values:
                option.validator(option.key, env.subst('${%s}'%option.key), env)
988925
def setup_environment_from_config_file():
    

    from os.path import exists

    config_file = get_config_file()

    if not exists(config_file):
        return

    try:
        config = _ConfigParser.SafeConfigParser()
        config.read(config_file)

        __section = "Environment"

        if config.has_section(__section):
            items = config.items(__section)

            for k, v in items:
                try:
                    os.environ[k.upper()] = v
                except Exception as e:
                    print(("WARNING: Error setting environment variable "
                           "'%s = %s' from config file '%s': %s.")
                          % (k, str(v), config_file, str(e)) )
    except Exception as e:
        print("WARNING: Error reading config file '%s': %s." % (config_file, str(e)))
195556
def load_env(self):
        
        for key, value in self.spec.items():
            if value['type'] in (dict, list):
                envar = (self.env_prefix + "_" + key).upper()
                try:
                    envvar = env.json(envar,
                                      default=getattr(self, key.upper(), value.get('default')))
                except ConfigurationError as _err:  #pragma: no cover
                    print(_err)
                    self.log.critical(f"Error parsing json from env var. {os.environ.get(envar)}")
                    print(envar)
                    raise
            else:
                envvar = env((self.env_prefix + "_" + key).upper(),
                             default=getattr(self, key.upper(), value.get('default')),
                             cast=value['type'])
            setattr(self, key.upper(), envvar)
102856
def make_value_from_env(self, param, value_type, function):
        
        value = os.getenv(param)
        if value is None:
            self.notify_user("Environment variable `%s` undefined" % param)
        return self.value_convert(value, value_type)
1255811
function resolveEnvSources(env) {
  let paths = [];

  if (process.env[env]) {
    paths = process.env[env].includes(path.delimiter) ? process.env[env].split(path.delimiter) : [process.env[env]];
  }

  return paths;
}
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]
881305
def from_env(key: str, default: T = None) -> Union[str, Optional[T]]:
    
    return os.getenv(key, default)