Coverage for databooks/config.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-09 13:11 +0000

1"""Configuration functions, and settings objects.""" 

2from pathlib import Path 

3from typing import Any, Dict, List, Optional 

4 

5from databooks.common import find_common_parent, find_obj 

6from databooks.git_utils import get_repo 

7from databooks.logging import get_logger 

8 

9TOML_CONFIG_FILE = "pyproject.toml" 

10 

11ConfigFields = Dict[str, Any] 

12 

13logger = get_logger(__file__) 

14 

15 

16def get_config(target_paths: List[Path], config_filename: str) -> Optional[Path]: 

17 """Find configuration file from CLI target paths.""" 

18 common_path = find_common_parent(paths=target_paths) 

19 repo = get_repo(common_path) 

20 repo_dir = getattr(repo, "working_dir", None) 

21 

22 return find_obj( 

23 obj_name=config_filename, 

24 start=Path(repo_dir) if repo_dir is not None else Path(common_path.anchor), 

25 finish=common_path, 

26 )