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)
评论列表
文章目录