read_settings.py 626 B

12345678910111213141516171819202122232425
  1. import logging
  2. import sys
  3. from typing import NoReturn
  4. import tomli
  5. from app.schema import Settings
  6. logger = logging.getLogger(__name__)
  7. def read_settings(filepath: str) -> Settings | NoReturn:
  8. """Read settings.toml from the root of the project folder"""
  9. try:
  10. with open(filepath, mode="rb") as f:
  11. config = tomli.load(f)
  12. settings = Settings(**config)
  13. return settings
  14. except FileNotFoundError:
  15. logger.error(
  16. f"error => {filepath} has not been found\n",
  17. " please check the README for instructions",
  18. )
  19. sys.exit(1)