From 3b78367d16bee854efb1cacf7365dc04612a3605 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Wed, 2 Jul 2025 14:57:46 +0200 Subject: [PATCH 1/2] Prettify linter output Prettify linter output in case of schema violations in the problem yaml file. Previously, the messages were rather confusing. --- petab/petablint.py | 14 +++++++++++++- petab/v1/yaml.py | 6 ++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/petab/petablint.py b/petab/petablint.py index 244b7536..bd1843f3 100755 --- a/petab/petablint.py +++ b/petab/petablint.py @@ -160,10 +160,22 @@ def main(): try: validate(args.yaml_file_name) except SchemaValidationError as e: + if e.absolute_path: + # construct a path to the error location inside the YAML file + path = list(e.absolute_path) + path = ( + path[0] + "".join(f"[{str(p)}]" for p in path[1:]) + ": " + ) + else: + path = "" logger.error( - f"Provided YAML file does not adhere to PEtab schema: {e}" + "Provided YAML file does not adhere to PEtab schema: " + f"{path}{e.args[0]}" ) sys.exit(1) + except ValueError as e: + logger.error(e) + sys.exit(1) if petab.is_composite_problem(args.yaml_file_name): # TODO: further checking: diff --git a/petab/v1/yaml.py b/petab/v1/yaml.py index b8330028..0c092049 100644 --- a/petab/v1/yaml.py +++ b/petab/v1/yaml.py @@ -77,16 +77,14 @@ def validate_yaml_syntax( # but let's still use the latest PEtab schema for full validation version = yaml_config.get(FORMAT_VERSION, None) version = ( - parse_version(version)[:2] - if version - else list(SCHEMAS.values())[-1] + parse_version(version)[:2] if version else list(SCHEMAS.keys())[-1] ) try: schema = SCHEMAS[version] except KeyError as e: raise ValueError( - "Unknown PEtab version given in problem " + "No or unknown PEtab version given in problem " f"specification: {version}" ) from e schema = load_yaml(schema) From 8cc793d651a88a529c82804d606fe0252bfb302e Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Thu, 3 Jul 2025 13:42:17 +0200 Subject: [PATCH 2/2] .. --- petab/petablint.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/petab/petablint.py b/petab/petablint.py index bd1843f3..413f67db 100755 --- a/petab/petablint.py +++ b/petab/petablint.py @@ -160,17 +160,18 @@ def main(): try: validate(args.yaml_file_name) except SchemaValidationError as e: + path = "" if e.absolute_path: # construct a path to the error location inside the YAML file path = list(e.absolute_path) path = ( - path[0] + "".join(f"[{str(p)}]" for p in path[1:]) + ": " + f" at {path[0]}" + + "".join(f"[{str(p)}]" for p in path[1:]) + + ": " ) - else: - path = "" logger.error( - "Provided YAML file does not adhere to PEtab schema: " - f"{path}{e.args[0]}" + "Provided YAML file does not adhere to the PEtab schema" + f"{path}: {e.args[0]}" ) sys.exit(1) except ValueError as e: