| 1234567891011121314151617181920212223242526272829303132333435 |
- import logging
- import sys
- from pathlib import Path
- from typing import NoReturn
- import tomli
- from app.git import is_git_repo
- from app.schema import Settings
- logger = logging.getLogger(__name__)
- def read_settings(filepath: str, check_valid_repo: bool = True) -> Settings | NoReturn:
- """Read settings.toml from the root of the project folder"""
- try:
- with open(filepath, mode="rb") as f:
- config = tomli.load(f)
- if check_valid_repo:
- git_repo = str(Path(config["git_repo"]).expanduser())
- if not is_git_repo(str(git_repo)):
- raise FileNotFoundError("git-repo has not been found")
- config["git_repo"] = git_repo
- settings = Settings(**config)
- return settings
- except FileNotFoundError:
- logger.error(
- f"error => {filepath} has not been found\n",
- " please check the README for instructions",
- )
- sys.exit(1)
|