Skip to content

Commit 6d42f16

Browse files
dweindlclaude
andcommitted
Add petablint --fail-on-warnings
Allows restoring the previous behavior of failing on warnings for PEtab v2 problems. Currently has no effect for PEtab v1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent cacd2c1 commit 6d42f16

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@
6060
Previously, their order was undefined
6161
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/562)
6262
* `petablint` no longer fails for PEtab v2 problems with only warnings,
63-
consistent with PEtab v1. Warnings are still reported
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)
6466
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/569)
6567

6668
**Features**

‎petab/petablint.py‎

Lines changed: 21 additions & 2 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)
201217
# Handle petab.v2.lint.ValidationTask issues
202218
validation_issues.log(logger=logger)
203-
if validation_issues.has_errors():
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,19 @@ def test_petablint_v2(tmpdir):
10601060
assert result.returncode == 0
10611061
assert "CheckUnusedConditions" in result.stdout + result.stderr
10621062

1063+
# ... unless requested
1064+
result = subprocess.run( # noqa S607
1065+
[ # noqa: S607
1066+
"petablint",
1067+
"--fail-on-warnings",
1068+
str(Path(tmpdir, "problem.yaml")),
1069+
],
1070+
capture_output=True,
1071+
text=True,
1072+
)
1073+
assert result.returncode == 1
1074+
assert "CheckUnusedConditions" in result.stdout + result.stderr
1075+
10631076
# errors make petablint fail
10641077
problem.add_measurement(
10651078
"obs_undefined", time=10, measurement=2.5, experiment_id=""

0 commit comments

Comments
 (0)