Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions coverage_threshold/cli/read_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
def read_config(config_file_name: Optional[str]) -> Config:
DEFAULT_FILENAME = "./pyproject.toml"
if config_file_name is not None:
return Config.parse(toml.load(config_file_name)["coverage-threshold"])
if not os.path.isfile(config_file_name):
raise FileNotFoundError(f"Config file {config_file_name} not found")
else:
if os.path.isfile(DEFAULT_FILENAME):
return Config.parse(
toml.load(DEFAULT_FILENAME).get("coverage-threshold", {})
)
else:
return Config()
config_file_name = DEFAULT_FILENAME
if os.path.isfile(config_file_name):
try:
# PEP 518 compliant version
return Config.parse(toml.load(config_file_name)["tool"]["coverage-threshold"])
except KeyError:
# Legacy version
return Config.parse(toml.load(config_file_name).get("coverage-threshold", {}))
else:
return Config()