Skip to content

Commit 6d70b20

Browse files
authored
Fix petablint v2 warning (#342)
Don't show `Support for PEtab2.0 and all of petab.v2 is experimental` warning when validating PEtab v1 problems.
1 parent 6fffafb commit 6d70b20

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

petab/petablint.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212

1313
import petab.v1 as petab
1414
from petab.v1.C import FORMAT_VERSION
15-
from petab.v2.lint import lint_problem
15+
from petab.v1.yaml import validate
1616
from petab.versions import get_major_version
17-
from petab.yaml import validate
1817

1918
logger = logging.getLogger(__name__)
2019

@@ -178,6 +177,8 @@ def main():
178177
ret = petab.lint.lint_problem(problem)
179178
sys.exit(ret)
180179
case 2:
180+
from petab.v2.lint import lint_problem
181+
181182
validation_issues = lint_problem(args.yaml_file_name)
182183
if validation_issues:
183184
validation_issues.log(logger=logger)

petab/versions.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,38 @@
33

44
from pathlib import Path
55

6+
import petab
67
from petab.v1 import Problem as V1Problem
78
from petab.v1.C import FORMAT_VERSION
89
from petab.v1.yaml import load_yaml
9-
from petab.v2 import Problem as V2Problem
1010

1111
__all__ = [
1212
"get_major_version",
1313
]
1414

1515

1616
def get_major_version(
17-
problem: str | dict | Path | V1Problem | V2Problem,
17+
problem: str | dict | Path | V1Problem | petab.v2.Problem,
1818
) -> int:
1919
"""Get the major version number of the given problem."""
20-
if isinstance(problem, V1Problem):
21-
return 1
22-
23-
if isinstance(problem, V2Problem):
24-
return 2
20+
version = None
2521

2622
if isinstance(problem, str | Path):
2723
yaml_config = load_yaml(problem)
2824
version = yaml_config.get(FORMAT_VERSION)
2925
elif isinstance(problem, dict):
3026
version = problem.get(FORMAT_VERSION)
31-
else:
32-
raise ValueError(f"Unsupported argument type: {type(problem)}")
3327

34-
version = str(version)
35-
return int(version.split(".")[0])
28+
if version is not None:
29+
version = str(version)
30+
return int(version.split(".")[0])
31+
32+
if isinstance(problem, V1Problem):
33+
return 1
34+
35+
from . import v2
36+
37+
if isinstance(problem, v2.Problem):
38+
return 2
39+
40+
raise ValueError(f"Unsupported argument type: {type(problem)}")

0 commit comments

Comments
 (0)