Skip to content

Commit

Permalink
Fix petablint v2 warning (#342)
Browse files Browse the repository at this point in the history
Don't show `Support for PEtab2.0 and all of petab.v2 is experimental` warning when validating PEtab v1 problems.
  • Loading branch information
dweindl authored Dec 16, 2024
1 parent 6fffafb commit 6d70b20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
5 changes: 3 additions & 2 deletions petab/petablint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

import petab.v1 as petab
from petab.v1.C import FORMAT_VERSION
from petab.v2.lint import lint_problem
from petab.v1.yaml import validate
from petab.versions import get_major_version
from petab.yaml import validate

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -178,6 +177,8 @@ def main():
ret = petab.lint.lint_problem(problem)
sys.exit(ret)
case 2:
from petab.v2.lint import lint_problem

validation_issues = lint_problem(args.yaml_file_name)
if validation_issues:
validation_issues.log(logger=logger)
Expand Down
27 changes: 16 additions & 11 deletions petab/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,38 @@

from pathlib import Path

import petab
from petab.v1 import Problem as V1Problem
from petab.v1.C import FORMAT_VERSION
from petab.v1.yaml import load_yaml
from petab.v2 import Problem as V2Problem

__all__ = [
"get_major_version",
]


def get_major_version(
problem: str | dict | Path | V1Problem | V2Problem,
problem: str | dict | Path | V1Problem | petab.v2.Problem,
) -> int:
"""Get the major version number of the given problem."""
if isinstance(problem, V1Problem):
return 1

if isinstance(problem, V2Problem):
return 2
version = None

if isinstance(problem, str | Path):
yaml_config = load_yaml(problem)
version = yaml_config.get(FORMAT_VERSION)
elif isinstance(problem, dict):
version = problem.get(FORMAT_VERSION)
else:
raise ValueError(f"Unsupported argument type: {type(problem)}")

version = str(version)
return int(version.split(".")[0])
if version is not None:
version = str(version)
return int(version.split(".")[0])

if isinstance(problem, V1Problem):
return 1

from . import v2

if isinstance(problem, v2.Problem):
return 2

raise ValueError(f"Unsupported argument type: {type(problem)}")

0 comments on commit 6d70b20

Please sign in to comment.