Skip to content

Commit c6d4cab

Browse files
authored
Prettify linter output (#401)
Prettify linter output in case of schema violations in the problem yaml file. Previously, the messages were rather confusing. Also fix an error message and a bug in the default schema choice. Related to #369.
1 parent 3f49363 commit c6d4cab

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

petab/petablint.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,23 @@ def main():
161161
try:
162162
validate(args.yaml_file_name)
163163
except SchemaValidationError as e:
164+
path = ""
165+
if e.absolute_path:
166+
# construct a path to the error location inside the YAML file
167+
path = list(e.absolute_path)
168+
path = (
169+
f" at {path[0]}"
170+
+ "".join(f"[{str(p)}]" for p in path[1:])
171+
+ ": "
172+
)
164173
logger.error(
165-
f"Provided YAML file does not adhere to PEtab schema: {e}"
174+
"Provided YAML file does not adhere to the PEtab schema"
175+
f"{path}: {e.args[0]}"
166176
)
167177
sys.exit(1)
178+
except ValueError as e:
179+
logger.error(e)
180+
sys.exit(1)
168181

169182
if petab.is_composite_problem(args.yaml_file_name):
170183
# TODO: further checking:

petab/v1/yaml.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,14 @@ def validate_yaml_syntax(
7777
# but let's still use the latest PEtab schema for full validation
7878
version = yaml_config.get(FORMAT_VERSION, None)
7979
version = (
80-
parse_version(version)[:2]
81-
if version
82-
else list(SCHEMAS.values())[-1]
80+
parse_version(version)[:2] if version else list(SCHEMAS.keys())[-1]
8381
)
8482

8583
try:
8684
schema = SCHEMAS[version]
8785
except KeyError as e:
8886
raise ValueError(
89-
"Unknown PEtab version given in problem "
87+
"No or unknown PEtab version given in problem "
9088
f"specification: {version}"
9189
) from e
9290
schema = load_yaml(schema)

0 commit comments

Comments
 (0)