-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathread_config.py
More file actions
26 lines (22 loc) · 836 Bytes
/
read_config.py
File metadata and controls
26 lines (22 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os.path
from typing import Optional
import toml
from coverage_threshold.model.config import Config
def read_config(config_file_name: Optional[str]) -> Config:
DEFAULT_FILENAME = "./pyproject.toml"
if config_file_name is not None:
if not os.path.isfile(config_file_name):
raise FileNotFoundError(f"Config file {config_file_name} not found")
else:
config_file_name = DEFAULT_FILENAME
if os.path.isfile(config_file_name):
toml_dict = toml.load(config_file_name)
try:
# PEP 518 compliant version
config_dict = toml_dict["tool"]["coverage-threshold"]
except KeyError:
# Legacy version
config_dict = toml_dict.get("coverage-threshold", {})
return Config.parse(config_dict)
else:
return Config()