python类load_dotenv()的实例源码

config.py 文件源码 项目:boss 作者: kabirbaidhya 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def resolve_dotenv_file(path, stage=None):
    '''
    Resolve dotenv file and load environment vars if it exists.
    If stage parameter is provided, then stage specific .env file is resolved,
    for instance .env.production if stage=production etc.
    If stage is None, just .env file is resolved.
    '''
    filename = '.env' + ('' if not stage else '.{}'.format(stage))
    dotenv_path = os.path.join(path, filename)
    fallback_path = os.path.join(path, '.env')

    if fs.exists(dotenv_path):
        info('Resolving env file: {}'.format(cyan(dotenv_path)))
        dotenv.load_dotenv(dotenv_path)

    elif fs.exists(fallback_path):
        info('Resolving env file: {}'.format(cyan(fallback_path)))
        dotenv.load_dotenv(fallback_path)
main.py 文件源码 项目:deploy 作者: datahq 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, configfile='.env'):
        '''Initialize.

        @param: configfile a .env style config file. See README for more.
        '''
        if os.path.exists(configfile):
            # we set ourselves as load_dotenv has system env variables to take
            # precedence which in our experience is confusing as a user changes a
            # var and re-runs and nothing happens
            # dotenv.load_dotenv('.env')
            out = dotenv.main.dotenv_values(configfile)
            # we need stuff in the environment for docker
            os.environ.update(out)
        self.config = os.environ
        rds_uri = self.config.get('RDS_URI')
        if not rds_uri:
            print('Warning: RDS_URI is not set. please set, or run `python main.py rds`')
settings.py 文件源码 项目:windflow 作者: hartym 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def load_settings_from_env(root_path):
    dotenv.load_dotenv(os.path.join(root_path, '.env'))
cli.py 文件源码 项目:pipenv 作者: pypa 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def load_dot_env():
    if not PIPENV_DONT_LOAD_ENV:
        # If the project doesn't exist yet, check current directory for a .env file
        project_directory = project.project_directory or '.'

        denv = dotenv.find_dotenv(PIPENV_DOTENV_LOCATION or os.sep.join([project_directory, '.env']))
        if os.path.isfile(denv):
            click.echo(crayons.normal('Loading .env environment variables…', bold=True), err=True)
        dotenv.load_dotenv(denv, override=True)
__init__.py 文件源码 项目:serverless-helpers-py 作者: serverless 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _maybe_load(env):
    if os.path.isfile(env):
        logger.debug("Loading .env file %s" % env)
        load_dotenv(env)
    else:
        logger.info(".env file %s does not exist, not loading." % env)


问题


面经


文章

微信
公众号

扫码关注公众号