Skip to content

Commit 0e7aa40

Browse files
authored
Use PEP518 compliant pyproject format
Parameters should be under the [tool.coverage-threshold] key. If not found, fall back to [coverage-threshold].
1 parent 440c0cc commit 0e7aa40

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

coverage_threshold/cli/read_config.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
def read_config(config_file_name: Optional[str]) -> Config:
1010
DEFAULT_FILENAME = "./pyproject.toml"
1111
if config_file_name is not None:
12-
return Config.parse(toml.load(config_file_name)["coverage-threshold"])
12+
if not os.path.isfile(config_file_name):
13+
raise FileNotFoundError(f"Config file {config_file_name} not found")
1314
else:
14-
if os.path.isfile(DEFAULT_FILENAME):
15-
return Config.parse(
16-
toml.load(DEFAULT_FILENAME).get("coverage-threshold", {})
17-
)
18-
else:
19-
return Config()
15+
config_file_name = DEFAULT_FILENAME
16+
if os.path.isfile(config_file_name):
17+
try:
18+
# PEP 518 compliant version
19+
return Config.parse(toml.load(config_file_name)["tool"]["coverage-threshold"])
20+
except KeyError:
21+
# Legacy version
22+
return Config.parse(toml.load(config_file_name).get("coverage-threshold", {}))
23+
else:
24+
return Config()

0 commit comments

Comments
 (0)