Skip to content

Commit a285cad

Browse files
dweindlclaude
andauthored
Don't fail petablint for PEtab v2 problems with only warnings (#569)
For PEtab v2 problems, `petablint` exited with 1 for any validation issue, including warnings such as unused conditions. Now it reports all issues but only fails if there are errors, consistent with PEtab v1. Use `petablint --fail-on-warnings` to get the previous behavior. This option currently only affects PEtab v2 problems. Closes #567. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 19df050 commit a285cad

3 files changed

Lines changed: 70 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
that PEtab condition changes are applied before its assignments.
6060
Previously, their order was undefined
6161
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/562)
62+
* `petablint` no longer fails for PEtab v2 problems with only warnings,
63+
consistent with PEtab v1. Warnings are still reported.
64+
The previous behavior can be restored via `--fail-on-warnings`
65+
(currently only effective for PEtab v2)
66+
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/569)
6267
* Several fixes to `assignments_to_experiments`: keep a switch at the start
6368
of a later period, keep the condition changes of symbols that the model
6469
still uses elsewhere, evaluate a condition change once at the start of its

‎petab/petablint.py‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ def parse_cli_args():
5353
action="store_true",
5454
help="More verbose output",
5555
)
56+
parser.add_argument(
57+
"--fail-on-warnings",
58+
dest="fail_on_warnings",
59+
action="store_true",
60+
help="Exit with a non-zero status also if there are only warnings. "
61+
"Currently only supported for PEtab v2 problems; "
62+
"has no effect for PEtab v1.",
63+
)
5664

5765
# Call with set of files
5866
group = parser.add_argument_group(
@@ -194,13 +202,24 @@ def main():
194202
ret = petab.lint.lint_problem(problem)
195203
sys.exit(ret)
196204
case 2:
197-
from petab.v2.lint import lint_problem
205+
from petab.v2.lint import (
206+
ValidationIssueSeverity,
207+
lint_problem,
208+
)
198209

210+
fail_level = (
211+
ValidationIssueSeverity.WARNING
212+
if args.fail_on_warnings
213+
else ValidationIssueSeverity.ERROR
214+
)
199215
try:
200216
validation_issues = lint_problem(args.yaml_file_name)
201-
if validation_issues:
202-
# Handle petab.v2.lint.ValidationTask issues
203-
validation_issues.log(logger=logger)
217+
# Handle petab.v2.lint.ValidationTask issues
218+
validation_issues.log(logger=logger)
219+
if any(
220+
issue.level >= fail_level
221+
for issue in validation_issues
222+
):
204223
sys.exit(1)
205224
logger.info("PEtab format check completed successfully.")
206225
sys.exit(0)

‎tests/v2/test_core.py‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,48 @@ def test_petablint_v2(tmpdir):
10521052
check=True,
10531053
)
10541054

1055+
# warnings are reported, but don't make petablint fail
1056+
problem.add_condition("unused_condition", B=1)
1057+
problem.condition_tables[0].rel_path = "conditions.tsv"
1058+
problem.config.condition_files = ["conditions.tsv"]
1059+
issues = problem.validate()
1060+
assert issues
1061+
assert not issues.has_errors()
1062+
problem.to_files(Path(tmpdir))
1063+
result = subprocess.run( # noqa S607
1064+
["petablint", str(Path(tmpdir, "problem.yaml"))], # noqa S607
1065+
capture_output=True,
1066+
text=True,
1067+
)
1068+
assert result.returncode == 0
1069+
assert "CheckUnusedConditions" in result.stdout + result.stderr
1070+
1071+
# ... unless requested
1072+
result = subprocess.run( # noqa S607
1073+
[ # noqa: S607
1074+
"petablint",
1075+
"--fail-on-warnings",
1076+
str(Path(tmpdir, "problem.yaml")),
1077+
],
1078+
capture_output=True,
1079+
text=True,
1080+
)
1081+
assert result.returncode == 1
1082+
assert "CheckUnusedConditions" in result.stdout + result.stderr
1083+
1084+
# errors make petablint fail
1085+
problem.add_measurement(
1086+
"obs_undefined", time=10, measurement=2.5, experiment_id=""
1087+
)
1088+
assert problem.validate().has_errors()
1089+
problem.to_files(Path(tmpdir))
1090+
result = subprocess.run( # noqa S607
1091+
["petablint", str(Path(tmpdir, "problem.yaml"))], # noqa S607
1092+
capture_output=True,
1093+
text=True,
1094+
)
1095+
assert result.returncode == 1
1096+
10551097

10561098
def test_problem_id(tmpdir):
10571099
"""Test that the problem ID works as expected."""

0 commit comments

Comments
 (0)