__init__.py 650 B

1234567891011121314151617181920212223
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # vim:fenc=utf-8
  4. import json
  5. import os
  6. import yaml
  7. _config_cache = None
  8. def get():
  9. global _config_cache
  10. if _config_cache is None:
  11. dir_name = os.path.dirname(os.path.abspath(__file__))
  12. env = os.environ.get('RAG_ENV', 'dev')
  13. if env not in ('dev', 'pre', 'prod'):
  14. raise ValueError(f"Invalid environment: {env}. Expected one of ('dev', 'pre', 'prod').")
  15. with open(f'{dir_name}/{env}.yaml', 'r') as f:
  16. _config_cache = yaml.safe_load(f.read())
  17. return _config_cache
  18. def get_env():
  19. env = os.environ.get('RAG_ENV', 'dev')
  20. return env