From 0e7aa406f71568cfbf9fc6a5c8e26e8ac647f1f9 Mon Sep 17 00:00:00 2001 From: colasriev <156931839+colasriev@users.noreply.github.com> Date: Thu, 22 May 2025 13:44:36 +0200 Subject: [PATCH] Use PEP518 compliant pyproject format Parameters should be under the [tool.coverage-threshold] key. If not found, fall back to [coverage-threshold]. --- coverage_threshold/cli/read_config.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/coverage_threshold/cli/read_config.py b/coverage_threshold/cli/read_config.py index 24c9a53..7c06ceb 100644 --- a/coverage_threshold/cli/read_config.py +++ b/coverage_threshold/cli/read_config.py @@ -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()